mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
Updated test cases
This commit is contained in:
parent
8dc016e7f9
commit
6836e9c7a8
@ -25,10 +25,11 @@ import type {
|
||||
FlowVertexTypeParam,
|
||||
} from './types.js';
|
||||
import type { NodeMetaData } from '../../types.js';
|
||||
import type { DiagramDB } from '../../diagram-api/types.js';
|
||||
|
||||
const MERMAID_DOM_ID_PREFIX = 'flowchart-';
|
||||
|
||||
export class FlowDb {
|
||||
export class FlowDb implements DiagramDB {
|
||||
private vertexCounter = 0;
|
||||
private config = getConfig();
|
||||
private vertices = new Map<string, FlowVertex>();
|
||||
|
@ -69,6 +69,7 @@ import { compile, serialize } from 'stylis';
|
||||
import { Diagram } from './Diagram.js';
|
||||
import { decodeEntities, encodeEntities } from './utils.js';
|
||||
import { toBase64 } from './utils/base64.js';
|
||||
import { FlowDb } from './diagrams/flowchart/flowDb.js';
|
||||
|
||||
/**
|
||||
* @see https://vitest.dev/guide/mocking.html Mock part of a module
|
||||
@ -836,16 +837,17 @@ graph TD;A--x|text including URL space|B;`)
|
||||
it('should not modify db when rendering different diagrams', async () => {
|
||||
const flowDiagram1 = await mermaidAPI.getDiagramFromText(
|
||||
`flowchart LR
|
||||
%% This is a comment A -- text --> B{node}
|
||||
A -- text --> B -- text2 --> C`
|
||||
);
|
||||
const flwoDiagram2 = await mermaidAPI.getDiagramFromText(
|
||||
`flowchart LR
|
||||
%% This is a comment A -- text --> B{node}
|
||||
`flowchart TD
|
||||
A -- text --> B -- text2 --> C`
|
||||
);
|
||||
// Since flowDiagram will return new Db object each time, we can compare the db to be different.
|
||||
expect(flwoDiagram1.db).not.toBe(flwoDiagram2.db);
|
||||
expect(flowDiagram1.db).not.toBe(flwoDiagram2.db);
|
||||
assert(flowDiagram1.db instanceof FlowDb);
|
||||
assert(flwoDiagram2.db instanceof FlowDb);
|
||||
expect(flowDiagram1.db.getDirection()).not.toEqual(flwoDiagram2.db.getDirection());
|
||||
|
||||
const classDiagram1 = await mermaidAPI.getDiagramFromText(
|
||||
`stateDiagram
|
||||
@ -869,4 +871,19 @@ graph TD;A--x|text including URL space|B;`)
|
||||
expect(classDiagram1.db).toBe(classDiagram2.db);
|
||||
});
|
||||
});
|
||||
|
||||
// Sequence Diagram currently uses a singleton DB, so this test will fail
|
||||
it.fails('should not modify db when rendering different sequence diagrams', async () => {
|
||||
const sequenceDiagram1 = await mermaidAPI.getDiagramFromText(
|
||||
`sequenceDiagram
|
||||
Alice->>Bob: Hello Bob, how are you?
|
||||
Bob-->>John: How about you John?`
|
||||
);
|
||||
const sequenceDiagram2 = await mermaidAPI.getDiagramFromText(
|
||||
`sequenceDiagram
|
||||
Alice->>Bob: Hello Bob, how are you?
|
||||
Bob-->>John: How about you John?`
|
||||
);
|
||||
expect(sequenceDiagram1.db).not.toBe(sequenceDiagram2.db);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user