-
Notifications
You must be signed in to change notification settings - Fork 20
/
hooks.test.ts
151 lines (103 loc) · 3.72 KB
/
hooks.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import mermaid from "mermaid";
import { isMermaidCode } from "./hooks";
describe("isMermaidCode", () => {
beforeAll(() => {
mermaid.initialize({});
})
describe("returns true when", () => {
it("mermaid code exists", () => {
const mermaidCode = "sequenceDiagram foo foo2 foo-->foo2";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("C4Context mermaid code exists", () => {
const mermaidCode = "C4Context foo foo2 foo-->foo2";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("Mindmap mermaid code exists", () => {
const mermaidCode = "mindmap root((foo bar)) Baz";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("Quadrant chart mermaid code exists", () => {
const mermaidCode = "quadrantChart x-axis Low Reach --> High Reach";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("xychart-beta chart mermaid code exists", () => {
const mermaidCode = "xychart-beta x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("Block-beta chart mermaid code exists", () => {
const mermaidCode = "block-beta columns 1 db((\"DB\"))";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("C4Container mermaid code exists", () => {
const mermaidCode = "C4Container foo foo2 foo-->foo2";
expect(isMermaidCode(mermaidCode)).toBe(true);
})
it("C4Component mermaid code exists", () => {
const mermaidCode = "C4Component foo foo2 foo-->foo2";
expect(isMermaidCode(mermaidCode)).toBe(true);
})
it("C4Dynamic mermaid code exists", () => {
const mermaidCode = "C4Dynamic foo foo2 foo-->foo2";
expect(isMermaidCode(mermaidCode)).toBe(true);
})
it("C4Deployment mermaid code exists", () => {
const mermaidCode = "C4Deployment foo foo2 foo-->foo2";
expect(isMermaidCode(mermaidCode)).toBe(true);
})
it("mermaid code exists with directive", () => {
const mermaidCode = `%%{init: { 'logLevel': 'debug', 'theme': 'dark' } }%%
graph LR
A-->B`;
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("mermade code exists with timeline", () => {
const mermaidCode = "timeline April 2023 : Phase 1: Clearwater";
expect(isMermaidCode(mermaidCode)).toBe(true);
})
it("mermaid code exists with frontmatter", () => {
const mermaidCode = `---
title: class diagram with frontmatter
---
classDiagram
direction LR`;
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
it("mermaid code exists with comment", () => {
const mermaidCode = `%% mermaid code with comment
graph LR
A-->B`;
const result = isMermaidCode(mermaidCode);
expect(result).toBe(true);
});
});
describe("returns false when", () => {
it("contains no mermaid code", () => {
const mermaidCode = "this isnt mermaid code";
const result = isMermaidCode(mermaidCode);
expect(result).toBe(false);
});
it("mermaid directive but not mermaid start keyword", () => {
const mermaidCode = `%%{init: { 'logLevel': 'debug', 'theme': 'dark' } }%%
invalid LR
A-->B`;
const result = isMermaidCode(mermaidCode);
expect(result).toBe(false);
});
it("improper directive", () => {
const mermaidCode = `%%{init: { 'logLevel': 'debug', 'theme': 'dark' }
invalid LR
A-->B`;
const result = isMermaidCode(mermaidCode);
expect(result).toBe(false);
});
});
});