2023-03-11 14:54:21 +01:00
|
|
|
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';
|
2023-03-11 14:54:21 +01:00
|
|
|
import { getDiagramFromText } from '../Diagram.js';
|
2023-02-28 12:18:54 +01:00
|
|
|
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', () => {
|
2023-02-24 07:45:55 +01:00
|
|
|
expect(() => getDiagram('loki')).toThrowErrorMatchingInlineSnapshot(
|
|
|
|
'"Diagram loki not found."'
|
|
|
|
);
|
2022-09-05 11:22:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle diagram registrations', () => {
|
2023-02-24 07:45:55 +01:00
|
|
|
expect(() => getDiagram('loki')).toThrowErrorMatchingInlineSnapshot(
|
|
|
|
'"Diagram loki not found."'
|
|
|
|
);
|
|
|
|
expect(() => detectType('loki diagram')).toThrowErrorMatchingInlineSnapshot(
|
2023-02-24 12:57:24 +01:00
|
|
|
'"No diagram type detected matching given configuration for text: loki diagram"'
|
2022-10-06 13:14:25 +02:00
|
|
|
);
|
2022-09-26 08:02:12 +02:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|