mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 09:49:46 +02:00
65 lines
2.1 KiB
JavaScript
65 lines
2.1 KiB
JavaScript
import { FlowDB } from '../flowDb.js';
|
|
import flow from './flowParserAdapter.js';
|
|
import { setConfig } from '../../../config.js';
|
|
|
|
setConfig({
|
|
securityLevel: 'strict',
|
|
});
|
|
|
|
describe('[Chevrotain] parsing a flow chart with markdown strings', function () {
|
|
beforeEach(function () {
|
|
flow.yy = new FlowDB();
|
|
flow.yy.clear();
|
|
});
|
|
|
|
it('markdown formatting in nodes and labels', function () {
|
|
const res = flow.parse(`flowchart
|
|
A["\`The cat in **the** hat\`"]-- "\`The *bat* in the chat\`" -->B["The dog in the hog"] -- "The rat in the mat" -->C;`);
|
|
|
|
const vert = flow.yy.getVertices();
|
|
const edges = flow.yy.getEdges();
|
|
|
|
expect(vert.get('A').id).toBe('A');
|
|
expect(vert.get('A').text).toBe('The cat in **the** hat');
|
|
expect(vert.get('A').labelType).toBe('markdown');
|
|
expect(vert.get('B').id).toBe('B');
|
|
expect(vert.get('B').text).toBe('The dog in the hog');
|
|
expect(vert.get('B').labelType).toBe('string');
|
|
expect(edges.length).toBe(2);
|
|
expect(edges[0].start).toBe('A');
|
|
expect(edges[0].end).toBe('B');
|
|
expect(edges[0].type).toBe('arrow_point');
|
|
expect(edges[0].text).toBe('The *bat* in the chat');
|
|
expect(edges[0].labelType).toBe('markdown');
|
|
expect(edges[1].start).toBe('B');
|
|
expect(edges[1].end).toBe('C');
|
|
expect(edges[1].type).toBe('arrow_point');
|
|
expect(edges[1].text).toBe('The rat in the mat');
|
|
expect(edges[1].labelType).toBe('string');
|
|
});
|
|
it('markdown formatting in subgraphs', function () {
|
|
const res = flow.parse(`flowchart LR
|
|
subgraph "One"
|
|
a("\`The **cat**
|
|
in the hat\`") -- "1o" --> b{{"\`The **dog** in the hog\`"}}
|
|
end
|
|
subgraph "\`**Two**\`"
|
|
c("\`The **cat**
|
|
in the hat\`") -- "\`1o **ipa**\`" --> d("The dog in the hog")
|
|
end`);
|
|
|
|
const subgraphs = flow.yy.getSubGraphs();
|
|
expect(subgraphs.length).toBe(2);
|
|
const subgraph = subgraphs[0];
|
|
|
|
expect(subgraph.nodes.length).toBe(2);
|
|
expect(subgraph.title).toBe('One');
|
|
expect(subgraph.labelType).toBe('text');
|
|
|
|
const subgraph2 = subgraphs[1];
|
|
expect(subgraph2.nodes.length).toBe(2);
|
|
expect(subgraph2.title).toBe('**Two**');
|
|
expect(subgraph2.labelType).toBe('markdown');
|
|
});
|
|
});
|