|
1 | | -import { vi, it, expect, describe, beforeEach } from 'vitest'; |
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
2 | 2 |
|
3 | 3 | // ------------------------------------- |
4 | 4 | // Mocks and mocking |
@@ -66,8 +66,8 @@ vi.mock('stylis', () => { |
66 | 66 | }); |
67 | 67 |
|
68 | 68 | import { compile, serialize } from 'stylis'; |
69 | | -import { decodeEntities, encodeEntities } from './utils.js'; |
70 | 69 | import { Diagram } from './Diagram.js'; |
| 70 | +import { decodeEntities, encodeEntities } from './utils.js'; |
71 | 71 | import { toBase64 } from './utils/base64.js'; |
72 | 72 |
|
73 | 73 | /** |
@@ -693,18 +693,79 @@ describe('mermaidAPI', () => { |
693 | 693 | await expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).resolves |
694 | 694 | .toMatchInlineSnapshot(` |
695 | 695 | { |
| 696 | + "config": {}, |
696 | 697 | "diagramType": "flowchart-v2", |
697 | 698 | } |
698 | 699 | `); |
699 | 700 | }); |
| 701 | + it('returns config when defined in frontmatter', async () => { |
| 702 | + await expect( |
| 703 | + mermaidAPI.parse(`--- |
| 704 | +config: |
| 705 | + theme: base |
| 706 | + flowchart: |
| 707 | + htmlLabels: true |
| 708 | +--- |
| 709 | +graph TD;A--x|text including URL space|B;`) |
| 710 | + ).resolves.toMatchInlineSnapshot(` |
| 711 | + { |
| 712 | + "config": { |
| 713 | + "flowchart": { |
| 714 | + "htmlLabels": true, |
| 715 | + }, |
| 716 | + "theme": "base", |
| 717 | + }, |
| 718 | + "diagramType": "flowchart-v2", |
| 719 | + } |
| 720 | +`); |
| 721 | + }); |
| 722 | + |
| 723 | + it('returns config when defined in directive', async () => { |
| 724 | + await expect( |
| 725 | + mermaidAPI.parse(`%%{init: { 'theme': 'base' } }%% |
| 726 | +graph TD;A--x|text including URL space|B;`) |
| 727 | + ).resolves.toMatchInlineSnapshot(` |
| 728 | + { |
| 729 | + "config": { |
| 730 | + "theme": "base", |
| 731 | + }, |
| 732 | + "diagramType": "flowchart-v2", |
| 733 | + } |
| 734 | +`); |
| 735 | + }); |
| 736 | + |
| 737 | + it('returns merged config when defined in frontmatter and directive', async () => { |
| 738 | + await expect( |
| 739 | + mermaidAPI.parse(`--- |
| 740 | +config: |
| 741 | + theme: forest |
| 742 | + flowchart: |
| 743 | + htmlLabels: true |
| 744 | +--- |
| 745 | +%%{init: { 'theme': 'base' } }%% |
| 746 | +graph TD;A--x|text including URL space|B;`) |
| 747 | + ).resolves.toMatchInlineSnapshot(` |
| 748 | + { |
| 749 | + "config": { |
| 750 | + "flowchart": { |
| 751 | + "htmlLabels": true, |
| 752 | + }, |
| 753 | + "theme": "base", |
| 754 | + }, |
| 755 | + "diagramType": "flowchart-v2", |
| 756 | + } |
| 757 | +`); |
| 758 | + }); |
| 759 | + |
700 | 760 | it('returns true for valid definition with silent option', async () => { |
701 | 761 | await expect( |
702 | 762 | mermaidAPI.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true }) |
703 | 763 | ).resolves.toMatchInlineSnapshot(` |
704 | | - { |
705 | | - "diagramType": "flowchart-v2", |
706 | | - } |
707 | | - `); |
| 764 | + { |
| 765 | + "config": {}, |
| 766 | + "diagramType": "flowchart-v2", |
| 767 | + } |
| 768 | + `); |
708 | 769 | }); |
709 | 770 | }); |
710 | 771 |
|
|
0 commit comments