1
1
import { imgSnapshotTest , renderGraph } from '../../helpers/util.js' ;
2
2
3
+ /**
4
+ * Check whether the SVG Element has a Mindmap root
5
+ *
6
+ * Sometimes, Cypress takes a snapshot before the mermaid mindmap has finished
7
+ * generating the SVG.
8
+ *
9
+ * @param $p - The element to check.
10
+ */
11
+ function shouldHaveRoot ( $p : JQuery < SVGSVGElement > ) {
12
+ // get HTML Element from jquery element
13
+ const svgElement = $p [ 0 ] ;
14
+ expect ( svgElement . nodeName ) . equal ( 'svg' ) ;
15
+
16
+ const sectionRoots = svgElement . getElementsByClassName ( 'mindmap-node section-root' ) ;
17
+ // mindmap should have at least one root section
18
+ expect ( sectionRoots ) . to . have . lengthOf . at . least ( 1 ) ;
19
+ }
20
+
3
21
describe ( 'Mindmaps' , ( ) => {
4
22
it ( 'Only a root' , ( ) => {
5
23
imgSnapshotTest (
6
24
`mindmap
7
25
root
8
26
` ,
9
- { }
27
+ { } ,
28
+ undefined ,
29
+ shouldHaveRoot
10
30
) ;
11
31
} ) ;
12
32
15
35
`mindmap
16
36
root[root]
17
37
` ,
18
- { }
38
+ { } ,
39
+ undefined ,
40
+ shouldHaveRoot
19
41
) ;
20
42
} ) ;
21
43
@@ -24,7 +46,9 @@ root[root]
24
46
`mindmap
25
47
root[A root with a long text that wraps to keep the node size in check]
26
48
` ,
27
- { }
49
+ { } ,
50
+ undefined ,
51
+ shouldHaveRoot
28
52
) ;
29
53
} ) ;
30
54
@@ -34,7 +58,9 @@ root[A root with a long text that wraps to keep the node size in check]
34
58
root[root]
35
59
::icon(mdi mdi-fire)
36
60
` ,
37
- { }
61
+ { } ,
62
+ undefined ,
63
+ shouldHaveRoot
38
64
) ;
39
65
} ) ;
40
66
@@ -48,7 +74,9 @@ root))bang((
48
74
a)A cloud(
49
75
::icon(mdi mdi-fire)
50
76
` ,
51
- { }
77
+ { } ,
78
+ undefined ,
79
+ shouldHaveRoot
52
80
) ;
53
81
} ) ;
54
82
@@ -60,7 +88,9 @@ root))bang((
60
88
a))Another bang((
61
89
a)A cloud(
62
90
` ,
63
- { }
91
+ { } ,
92
+ undefined ,
93
+ shouldHaveRoot
64
94
) ;
65
95
} ) ;
66
96
78
108
grandchild 5
79
109
grandchild 6
80
110
` ,
81
- { }
111
+ { } ,
112
+ undefined ,
113
+ shouldHaveRoot
82
114
) ;
83
115
} ) ;
84
116
98
130
gc6((grand<br/>child 6))
99
131
::icon(mdi mdi-fire)
100
132
` ,
101
- { }
133
+ { } ,
134
+ undefined ,
135
+ shouldHaveRoot
102
136
) ;
103
137
} ) ;
104
138
it ( 'text shouhld wrap with icon' , ( ) => {
107
141
root
108
142
Child3(A node with an icon and with a long text that wraps to keep the node size in check)
109
143
` ,
110
- { }
144
+ { } ,
145
+ undefined ,
146
+ shouldHaveRoot
111
147
) ;
112
148
} ) ;
113
149
it ( 'square shape' , ( ) => {
@@ -118,7 +154,9 @@ mindmap
118
154
The root
119
155
]
120
156
` ,
121
- { }
157
+ { } ,
158
+ undefined ,
159
+ shouldHaveRoot
122
160
) ;
123
161
cy . get ( 'svg' ) ;
124
162
} ) ;
@@ -130,7 +168,9 @@ mindmap
130
168
The root
131
169
))
132
170
` ,
133
- { }
171
+ { } ,
172
+ undefined ,
173
+ shouldHaveRoot
134
174
) ;
135
175
cy . get ( 'svg' ) ;
136
176
} ) ;
@@ -142,7 +182,9 @@ mindmap
142
182
The root
143
183
)
144
184
` ,
145
- { }
185
+ { } ,
186
+ undefined ,
187
+ shouldHaveRoot
146
188
) ;
147
189
cy . get ( 'svg' ) ;
148
190
} ) ;
@@ -152,7 +194,9 @@ mindmap
152
194
mindmap
153
195
The root
154
196
` ,
155
- { }
197
+ { } ,
198
+ undefined ,
199
+ shouldHaveRoot
156
200
) ;
157
201
cy . get ( 'svg' ) ;
158
202
} ) ;
@@ -164,7 +208,9 @@ mindmap
164
208
child1
165
209
child2
166
210
` ,
167
- { }
211
+ { } ,
212
+ undefined ,
213
+ shouldHaveRoot
168
214
) ;
169
215
cy . get ( 'svg' ) ;
170
216
} ) ;
@@ -177,7 +223,9 @@ mindmap
177
223
child2
178
224
child3
179
225
` ,
180
- { }
226
+ { } ,
227
+ undefined ,
228
+ shouldHaveRoot
181
229
) ;
182
230
cy . get ( 'svg' ) ;
183
231
} ) ;
0 commit comments