Skip to content

Commit

Permalink
test(e2e): test for mindmap before snapshot
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aloisklink committed Nov 18, 2022
1 parent 57edcfe commit 537a627
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';

/**
* Check whether the SVG Element has a Mindmap root
*
* Sometimes, Cypress takes a snapshot before the mermaid mindmap has finished
* generating the SVG.
*
* @param $p - The element to check.
*/
function shouldHaveRoot($p: JQuery<SVGSVGElement>) {
// get HTML Element from jquery element
const svgElement = $p[0];
expect(svgElement.nodeName).equal('svg');

const sectionRoots = svgElement.getElementsByClassName('mindmap-node section-root');
// mindmap should have at least one root section
expect(sectionRoots).to.have.lengthOf.at.least(1);
}

describe('Mindmaps', () => {
it('Only a root', () => {
imgSnapshotTest(
`mindmap
root
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -15,7 +35,9 @@ root
`mindmap
root[root]
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -24,7 +46,9 @@ root[root]
`mindmap
root[A root with a long text that wraps to keep the node size in check]
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -34,7 +58,9 @@ root[A root with a long text that wraps to keep the node size in check]
root[root]
::icon(mdi mdi-fire)
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -48,7 +74,9 @@ root))bang((
a)A cloud(
::icon(mdi mdi-fire)
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -60,7 +88,9 @@ root))bang((
a))Another bang((
a)A cloud(
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -78,7 +108,9 @@ root
grandchild 5
grandchild 6
`,
{}
{},
undefined,
shouldHaveRoot
);
});

Expand All @@ -98,7 +130,9 @@ root
gc6((grand<br/>child 6))
::icon(mdi mdi-fire)
`,
{}
{},
undefined,
shouldHaveRoot
);
});
it('text shouhld wrap with icon', () => {
Expand All @@ -107,7 +141,9 @@ root
root
Child3(A node with an icon and with a long text that wraps to keep the node size in check)
`,
{}
{},
undefined,
shouldHaveRoot
);
});
it('square shape', () => {
Expand All @@ -118,7 +154,9 @@ mindmap
The root
]
`,
{}
{},
undefined,
shouldHaveRoot
);
cy.get('svg');
});
Expand All @@ -130,7 +168,9 @@ mindmap
The root
))
`,
{}
{},
undefined,
shouldHaveRoot
);
cy.get('svg');
});
Expand All @@ -142,7 +182,9 @@ mindmap
The root
)
`,
{}
{},
undefined,
shouldHaveRoot
);
cy.get('svg');
});
Expand All @@ -152,7 +194,9 @@ mindmap
mindmap
The root
`,
{}
{},
undefined,
shouldHaveRoot
);
cy.get('svg');
});
Expand All @@ -164,7 +208,9 @@ mindmap
child1
child2
`,
{}
{},
undefined,
shouldHaveRoot
);
cy.get('svg');
});
Expand All @@ -177,7 +223,9 @@ mindmap
child2
child3
`,
{}
{},
undefined,
shouldHaveRoot
);
cy.get('svg');
});
Expand Down
8 changes: 8 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2020", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}

0 comments on commit 537a627

Please sign in to comment.