mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +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 { Diagram } from '../../Diagram.js';
|
||||
import { addDiagrams } from '../../diagram-api/diagram-orchestration.js';
|
||||
import { SequenceDB } from './sequenceDb.js';
|
||||
|
||||
beforeAll(async () => {
|
||||
// Is required to load the sequence diagram
|
||||
@@ -97,8 +98,8 @@ let diagram;
|
||||
describe('more than one sequence diagram', () => {
|
||||
it('should not have duplicated messages', async () => {
|
||||
const diagram1 = await Diagram.fromText(`
|
||||
sequenceDiagram
|
||||
Alice->Bob:Hello Bob, how are you?
|
||||
sequenceDiagram
|
||||
Alice->Bob:Hello Bob, how are you?
|
||||
Bob-->Alice: I am good thanks!`);
|
||||
expect(diagram1.db.getMessages()).toMatchInlineSnapshot(`
|
||||
[
|
||||
@@ -2071,3 +2072,27 @@ ${prop}-->>A: Hello, how are you?`)
|
||||
).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';
|
||||
// @ts-ignore: JISON doesn't support types
|
||||
import parser from './parser/sequenceDiagram.jison';
|
||||
import db from './sequenceDb.js';
|
||||
import { SequenceDB } from './sequenceDb.js';
|
||||
import styles from './styles.js';
|
||||
import renderer from './sequenceRenderer.js';
|
||||
|
||||
let db: SequenceDB;
|
||||
|
||||
export const diagram: DiagramDefinition = {
|
||||
parser,
|
||||
db,
|
||||
get db() {
|
||||
if (!db) {
|
||||
db = new SequenceDB();
|
||||
}
|
||||
return db;
|
||||
},
|
||||
renderer,
|
||||
styles,
|
||||
init: ({ wrap }) => {
|
||||
|
Reference in New Issue
Block a user