mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-14 21:09:50 +02:00
convert pie.spec.js to ts, remove cy.get and useless comment, add showData unit test case
This commit is contained in:
@@ -1,89 +1,85 @@
|
|||||||
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';
|
import { imgSnapshotTest, renderGraph } from '../../helpers/util.js';
|
||||||
|
|
||||||
describe('Pie Chart', () => {
|
describe('pie chart', () => {
|
||||||
it('should render a simple pie diagram', () => {
|
it('should render a simple pie diagram', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
|
`pie title Sports in Sweden
|
||||||
|
"Bandy": 40
|
||||||
|
"Ice-Hockey": 80
|
||||||
|
"Football": 90
|
||||||
`
|
`
|
||||||
pie title Sports in Sweden
|
|
||||||
"Bandy" : 40
|
|
||||||
"Ice-Hockey" : 80
|
|
||||||
"Football" : 90
|
|
||||||
`,
|
|
||||||
{}
|
|
||||||
);
|
);
|
||||||
cy.get('svg');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a simple pie diagram with long labels', () => {
|
it('should render a simple pie diagram with long labels', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
|
`pie title NETFLIX
|
||||||
|
"Time spent looking for movie": 90
|
||||||
|
"Time spent watching it": 10
|
||||||
`
|
`
|
||||||
pie title NETFLIX
|
|
||||||
"Time spent looking for movie" : 90
|
|
||||||
"Time spent watching it" : 10
|
|
||||||
`,
|
|
||||||
{}
|
|
||||||
);
|
);
|
||||||
cy.get('svg');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a simple pie diagram with capital letters for labels', () => {
|
it('should render a simple pie diagram with capital letters for labels', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
|
`pie title What Voldemort doesn't have?
|
||||||
|
"FRIENDS": 2
|
||||||
|
"FAMILY": 3
|
||||||
|
"NOSE": 45
|
||||||
`
|
`
|
||||||
pie title What Voldemort doesn't have?
|
|
||||||
"FRIENDS" : 2
|
|
||||||
"FAMILY" : 3
|
|
||||||
"NOSE" : 45
|
|
||||||
`,
|
|
||||||
{}
|
|
||||||
);
|
);
|
||||||
cy.get('svg');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a pie diagram when useMaxWidth is true (default)', () => {
|
it('should render a pie diagram when useMaxWidth is true (default)', () => {
|
||||||
renderGraph(
|
renderGraph(
|
||||||
`
|
`pie title Sports in Sweden
|
||||||
pie title Sports in Sweden
|
"Bandy": 40
|
||||||
"Bandy" : 40
|
"Ice-Hockey": 80
|
||||||
"Ice-Hockey" : 80
|
"Football": 90
|
||||||
"Football" : 90
|
|
||||||
`,
|
`,
|
||||||
{ pie: { useMaxWidth: true } }
|
{ pie: { useMaxWidth: true } }
|
||||||
);
|
);
|
||||||
cy.get('svg').should((svg) => {
|
cy.get('svg').should((svg) => {
|
||||||
expect(svg).to.have.attr('width', '100%');
|
expect(svg).to.have.attr('width', '100%');
|
||||||
// expect(svg).to.have.attr('height');
|
|
||||||
// const height = parseFloat(svg.attr('height'));
|
|
||||||
// expect(height).to.eq(450);
|
|
||||||
const style = svg.attr('style');
|
const style = svg.attr('style');
|
||||||
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
||||||
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
||||||
expect(maxWidthValue).to.eq(984);
|
expect(maxWidthValue).to.eq(984);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render a pie diagram when useMaxWidth is false', () => {
|
it('should render a pie diagram when useMaxWidth is false', () => {
|
||||||
renderGraph(
|
renderGraph(
|
||||||
`
|
`pie title Sports in Sweden
|
||||||
pie title Sports in Sweden
|
"Bandy": 40
|
||||||
"Bandy" : 40
|
"Ice-Hockey": 80
|
||||||
"Ice-Hockey" : 80
|
"Football": 90
|
||||||
"Football" : 90
|
|
||||||
`,
|
`,
|
||||||
{ pie: { useMaxWidth: false } }
|
{ pie: { useMaxWidth: false } }
|
||||||
);
|
);
|
||||||
cy.get('svg').should((svg) => {
|
cy.get('svg').should((svg) => {
|
||||||
// const height = parseFloat(svg.attr('height'));
|
|
||||||
const width = parseFloat(svg.attr('width'));
|
const width = parseFloat(svg.attr('width'));
|
||||||
// expect(height).to.eq(450);
|
|
||||||
expect(width).to.eq(984);
|
expect(width).to.eq(984);
|
||||||
expect(svg).to.not.have.attr('style');
|
expect(svg).to.not.have.attr('style');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should render a pie diagram when textPosition is set', () => {
|
|
||||||
|
it('should render a pie diagram when textPosition is setted', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`pie
|
||||||
pie
|
"Dogs": 50
|
||||||
"Dogs": 50
|
"Cats": 25
|
||||||
"Cats": 25
|
`,
|
||||||
`,
|
|
||||||
{ logLevel: 1, pie: { textPosition: 0.9 } }
|
{ logLevel: 1, pie: { textPosition: 0.9 } }
|
||||||
);
|
);
|
||||||
cy.get('svg');
|
});
|
||||||
|
|
||||||
|
it('should render a pie diagram with showData', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`pie showData
|
||||||
|
"Dogs": 50
|
||||||
|
"Cats": 25
|
||||||
|
`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
Reference in New Issue
Block a user