Skip to content

Commit 537a627

Browse files
committed
test(e2e): test for mindmap before snapshot
Sometimes, the mindmap e2e tests take a snapshot when the mindmap SVG has been created, but hasn't yet been fully rendered. This adds a quick check for a mindmap section root, so that the snapshot is only taken after the mindmap diagram has started rendering. I was also running into JSDoc ESLint warnings, so I moved the file into a TypeScript file to fix those warnings.
1 parent 57edcfe commit 537a627

File tree

2 files changed

+71
-15
lines changed

2 files changed

+71
-15
lines changed

cypress/integration/rendering/mindmap.spec.js cypress/integration/rendering/mindmap.spec.ts

+63-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';
22

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+
321
describe('Mindmaps', () => {
422
it('Only a root', () => {
523
imgSnapshotTest(
624
`mindmap
725
root
826
`,
9-
{}
27+
{},
28+
undefined,
29+
shouldHaveRoot
1030
);
1131
});
1232

@@ -15,7 +35,9 @@ root
1535
`mindmap
1636
root[root]
1737
`,
18-
{}
38+
{},
39+
undefined,
40+
shouldHaveRoot
1941
);
2042
});
2143

@@ -24,7 +46,9 @@ root[root]
2446
`mindmap
2547
root[A root with a long text that wraps to keep the node size in check]
2648
`,
27-
{}
49+
{},
50+
undefined,
51+
shouldHaveRoot
2852
);
2953
});
3054

@@ -34,7 +58,9 @@ root[A root with a long text that wraps to keep the node size in check]
3458
root[root]
3559
::icon(mdi mdi-fire)
3660
`,
37-
{}
61+
{},
62+
undefined,
63+
shouldHaveRoot
3864
);
3965
});
4066

@@ -48,7 +74,9 @@ root))bang((
4874
a)A cloud(
4975
::icon(mdi mdi-fire)
5076
`,
51-
{}
77+
{},
78+
undefined,
79+
shouldHaveRoot
5280
);
5381
});
5482

@@ -60,7 +88,9 @@ root))bang((
6088
a))Another bang((
6189
a)A cloud(
6290
`,
63-
{}
91+
{},
92+
undefined,
93+
shouldHaveRoot
6494
);
6595
});
6696

@@ -78,7 +108,9 @@ root
78108
grandchild 5
79109
grandchild 6
80110
`,
81-
{}
111+
{},
112+
undefined,
113+
shouldHaveRoot
82114
);
83115
});
84116

@@ -98,7 +130,9 @@ root
98130
gc6((grand<br/>child 6))
99131
::icon(mdi mdi-fire)
100132
`,
101-
{}
133+
{},
134+
undefined,
135+
shouldHaveRoot
102136
);
103137
});
104138
it('text shouhld wrap with icon', () => {
@@ -107,7 +141,9 @@ root
107141
root
108142
Child3(A node with an icon and with a long text that wraps to keep the node size in check)
109143
`,
110-
{}
144+
{},
145+
undefined,
146+
shouldHaveRoot
111147
);
112148
});
113149
it('square shape', () => {
@@ -118,7 +154,9 @@ mindmap
118154
The root
119155
]
120156
`,
121-
{}
157+
{},
158+
undefined,
159+
shouldHaveRoot
122160
);
123161
cy.get('svg');
124162
});
@@ -130,7 +168,9 @@ mindmap
130168
The root
131169
))
132170
`,
133-
{}
171+
{},
172+
undefined,
173+
shouldHaveRoot
134174
);
135175
cy.get('svg');
136176
});
@@ -142,7 +182,9 @@ mindmap
142182
The root
143183
)
144184
`,
145-
{}
185+
{},
186+
undefined,
187+
shouldHaveRoot
146188
);
147189
cy.get('svg');
148190
});
@@ -152,7 +194,9 @@ mindmap
152194
mindmap
153195
The root
154196
`,
155-
{}
197+
{},
198+
undefined,
199+
shouldHaveRoot
156200
);
157201
cy.get('svg');
158202
});
@@ -164,7 +208,9 @@ mindmap
164208
child1
165209
child2
166210
`,
167-
{}
211+
{},
212+
undefined,
213+
shouldHaveRoot
168214
);
169215
cy.get('svg');
170216
});
@@ -177,7 +223,9 @@ mindmap
177223
child2
178224
child3
179225
`,
180-
{}
226+
{},
227+
undefined,
228+
shouldHaveRoot
181229
);
182230
cy.get('svg');
183231
});

cypress/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"lib": ["es2020", "dom"],
5+
"types": ["cypress", "node"]
6+
},
7+
"include": ["**/*.ts"]
8+
}

0 commit comments

Comments
 (0)