mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-30 13:46:43 +02:00
convert sequenceDb to class.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ import { setSiteConfig } from '../../diagram-api/diagramAPI.js';
|
|||||||
import mermaidAPI from '../../mermaidAPI.js';
|
import mermaidAPI from '../../mermaidAPI.js';
|
||||||
import { Diagram } from '../../Diagram.js';
|
import { Diagram } from '../../Diagram.js';
|
||||||
import { addDiagrams } from '../../diagram-api/diagram-orchestration.js';
|
import { addDiagrams } from '../../diagram-api/diagram-orchestration.js';
|
||||||
|
import { SequenceDB } from './sequenceDb.js';
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Is required to load the sequence diagram
|
// Is required to load the sequence diagram
|
||||||
@@ -97,8 +98,8 @@ let diagram;
|
|||||||
describe('more than one sequence diagram', () => {
|
describe('more than one sequence diagram', () => {
|
||||||
it('should not have duplicated messages', async () => {
|
it('should not have duplicated messages', async () => {
|
||||||
const diagram1 = await Diagram.fromText(`
|
const diagram1 = await Diagram.fromText(`
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
Alice->Bob:Hello Bob, how are you?
|
Alice->Bob:Hello Bob, how are you?
|
||||||
Bob-->Alice: I am good thanks!`);
|
Bob-->Alice: I am good thanks!`);
|
||||||
expect(diagram1.db.getMessages()).toMatchInlineSnapshot(`
|
expect(diagram1.db.getMessages()).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
@@ -2071,3 +2072,27 @@ ${prop}-->>A: Hello, how are you?`)
|
|||||||
).resolves.toBeDefined();
|
).resolves.toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('sequence db class', () => {
|
||||||
|
let sequenceDb;
|
||||||
|
beforeEach(() => {
|
||||||
|
sequenceDb = new SequenceDB();
|
||||||
|
});
|
||||||
|
// This is to ensure that functions used in sequence JISON are exposed as function from SequenceDB
|
||||||
|
it('should have functions used in sequence JISON as own property', () => {
|
||||||
|
const functionsUsedInParser = [
|
||||||
|
'apply',
|
||||||
|
'parseBoxData',
|
||||||
|
'LINETYPE',
|
||||||
|
'setDiagramTitle',
|
||||||
|
'setAccTitle',
|
||||||
|
'setAccDescription',
|
||||||
|
'parseMessage',
|
||||||
|
'PLACEMENT',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const fun of functionsUsedInParser) {
|
||||||
|
expect(Object.hasOwn(sequenceDb, fun)).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@@ -1,13 +1,20 @@
|
|||||||
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
||||||
// @ts-ignore: JISON doesn't support types
|
// @ts-ignore: JISON doesn't support types
|
||||||
import parser from './parser/sequenceDiagram.jison';
|
import parser from './parser/sequenceDiagram.jison';
|
||||||
import db from './sequenceDb.js';
|
import { SequenceDB } from './sequenceDb.js';
|
||||||
import styles from './styles.js';
|
import styles from './styles.js';
|
||||||
import renderer from './sequenceRenderer.js';
|
import renderer from './sequenceRenderer.js';
|
||||||
|
|
||||||
|
let db: SequenceDB;
|
||||||
|
|
||||||
export const diagram: DiagramDefinition = {
|
export const diagram: DiagramDefinition = {
|
||||||
parser,
|
parser,
|
||||||
db,
|
get db() {
|
||||||
|
if (!db) {
|
||||||
|
db = new SequenceDB();
|
||||||
|
}
|
||||||
|
return db;
|
||||||
|
},
|
||||||
renderer,
|
renderer,
|
||||||
styles,
|
styles,
|
||||||
init: ({ wrap }) => {
|
init: ({ wrap }) => {
|
||||||
|
Reference in New Issue
Block a user