mermaid/packages/mermaid/src/diagram-api/diagramAPI.spec.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

import { detectType } from './detectType.js';
import { getDiagram, registerDiagram } from './diagramAPI.js';
import { addDiagrams } from './diagram-orchestration.js';
2023-08-22 10:14:11 +02:00
import type { DiagramDetector } from './types.js';
import { getDiagramFromText } from '../Diagram.js';
import { it, describe, expect, beforeAll } from 'vitest';
2022-09-12 07:41:56 +02:00
addDiagrams();
2023-02-19 19:44:39 +01:00
beforeAll(async () => {
await getDiagramFromText('sequenceDiagram');
});
2022-09-05 11:22:17 +02:00
describe('DiagramAPI', () => {
it('should return default diagrams', () => {
expect(getDiagram('sequence')).not.toBeNull();
});
it('should throw error if diagram is not defined', () => {
expect(() => getDiagram('loki')).toThrowErrorMatchingInlineSnapshot(
'"Diagram loki not found."'
);
2022-09-05 11:22:17 +02:00
});
it('should handle diagram registrations', () => {
expect(() => getDiagram('loki')).toThrowErrorMatchingInlineSnapshot(
'"Diagram loki not found."'
);
expect(() => detectType('loki diagram')).toThrowErrorMatchingInlineSnapshot(
'"No diagram type detected matching given configuration for text: loki diagram"'
);
const detector: DiagramDetector = (str: string) => {
return str.match('loki') !== null;
};
2022-10-08 07:14:16 +02:00
registerDiagram(
'loki',
{
db: {},
2023-08-10 21:26:04 +02:00
parser: {
parse: (_text) => {
return;
},
},
2022-10-08 07:14:16 +02:00
renderer: {},
styles: {},
},
detector
);
2022-09-05 11:22:17 +02:00
expect(getDiagram('loki')).not.toBeNull();
expect(detectType('loki diagram')).toBe('loki');
});
});