test: Fix parse tests

This commit is contained in:
Sidharth Vinod
2024-09-10 17:08:15 +05:30
parent 900c8a4209
commit d0caa2b3e0

View File

@@ -35,7 +35,7 @@ vi.mock('./diagrams/sequence/sequenceRenderer.js');
import assignWithDepth from './assignWithDepth.js';
import type { MermaidConfig } from './config.type.js';
import mermaid from './mermaid.js';
import mermaid, { type ParseResult } from './mermaid.js';
import mermaidAPI, {
appendDivSvgG,
cleanUpSvgCode,
@@ -695,23 +695,29 @@ describe('mermaidAPI', () => {
).resolves.toBe(false);
});
it('resolves for valid definition', async () => {
await expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).resolves
.toMatchInlineSnapshot(`
await expect(
mermaidAPI
.parse('graph TD;A--x|text including URL space|B;')
.then((p) => ({ config: p.config }))
).resolves.toMatchInlineSnapshot(`
{
"config": {},
"diagramType": "flowchart-v2",
}
`);
});
it('returns config when defined in frontmatter', async () => {
await expect(
mermaidAPI.parse(`---
mermaidAPI
.parse(
`---
config:
theme: base
flowchart:
htmlLabels: true
---
graph TD;A--x|text including URL space|B;`)
graph TD;A--x|text including URL space|B;`
)
.then((p) => ({ config: p.config }))
).resolves.toMatchInlineSnapshot(`
{
"config": {
@@ -720,35 +726,41 @@ graph TD;A--x|text including URL space|B;`)
},
"theme": "base",
},
"diagramType": "flowchart-v2",
}
`);
`);
});
it('returns config when defined in directive', async () => {
await expect(
mermaidAPI.parse(`%%{init: { 'theme': 'base' } }%%
graph TD;A--x|text including URL space|B;`)
mermaidAPI
.parse(
`%%{init: { 'theme': 'base' } }%%
graph TD;A--x|text including URL space|B;`
)
.then((p) => ({ config: p.config }))
).resolves.toMatchInlineSnapshot(`
{
"config": {
"theme": "base",
},
"diagramType": "flowchart-v2",
}
`);
`);
});
it('returns merged config when defined in frontmatter and directive', async () => {
await expect(
mermaidAPI.parse(`---
mermaidAPI
.parse(
`---
config:
theme: forest
flowchart:
htmlLabels: true
---
%%{init: { 'theme': 'base' } }%%
graph TD;A--x|text including URL space|B;`)
graph TD;A--x|text including URL space|B;`
)
.then((p) => ({ config: p.config }))
).resolves.toMatchInlineSnapshot(`
{
"config": {
@@ -757,17 +769,17 @@ graph TD;A--x|text including URL space|B;`)
},
"theme": "base",
},
"diagramType": "flowchart-v2",
}
`);
`);
});
it('returns true for valid definition with silent option', async () => {
await expect(
mermaidAPI.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
mermaidAPI
.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
.then((p) => ({ config: (p as ParseResult).config }))
).resolves.toMatchInlineSnapshot(`
{
"config": {},
"diagramType": "flowchart-v2",
}
`);
});