2023-07-07 17:21:18 +05:30
|
|
|
import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';
|
2019-09-11 21:20:28 +02:00
|
|
|
|
|
|
|
describe('Pie Chart', () => {
|
|
|
|
it('should render a simple pie diagram', () => {
|
2019-09-18 18:25:06 +02:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
2019-09-11 21:20:28 +02:00
|
|
|
pie title Sports in Sweden
|
|
|
|
"Bandy" : 40
|
|
|
|
"Ice-Hockey" : 80
|
|
|
|
"Football" : 90
|
|
|
|
`,
|
2019-09-18 18:25:06 +02:00
|
|
|
{}
|
|
|
|
);
|
2019-10-30 18:29:26 +01:00
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
it('should render a simple pie diagram with long labels', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
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', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
pie title What Voldemort doesn't have?
|
|
|
|
"FRIENDS" : 2
|
|
|
|
"FAMILY" : 3
|
|
|
|
"NOSE" : 45
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
2019-09-18 18:25:06 +02:00
|
|
|
});
|
2020-08-25 17:05:01 +02:00
|
|
|
it('should render a pie diagram when useMaxWidth is true (default)', () => {
|
|
|
|
renderGraph(
|
|
|
|
`
|
|
|
|
pie title Sports in Sweden
|
|
|
|
"Bandy" : 40
|
|
|
|
"Ice-Hockey" : 80
|
|
|
|
"Football" : 90
|
|
|
|
`,
|
|
|
|
{ pie: { useMaxWidth: true } }
|
|
|
|
);
|
2021-11-18 19:17:00 +01:00
|
|
|
cy.get('svg').should((svg) => {
|
|
|
|
expect(svg).to.have.attr('width', '100%');
|
2022-08-28 11:25:09 +02:00
|
|
|
// expect(svg).to.have.attr('height');
|
|
|
|
// const height = parseFloat(svg.attr('height'));
|
|
|
|
// expect(height).to.eq(450);
|
2021-11-18 19:17:00 +01:00
|
|
|
const style = svg.attr('style');
|
|
|
|
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
|
|
|
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
|
|
|
|
expect(maxWidthValue).to.eq(984);
|
|
|
|
});
|
2020-08-25 17:05:01 +02:00
|
|
|
});
|
|
|
|
it('should render a pie diagram when useMaxWidth is false', () => {
|
|
|
|
renderGraph(
|
|
|
|
`
|
|
|
|
pie title Sports in Sweden
|
|
|
|
"Bandy" : 40
|
|
|
|
"Ice-Hockey" : 80
|
|
|
|
"Football" : 90
|
|
|
|
`,
|
|
|
|
{ pie: { useMaxWidth: false } }
|
|
|
|
);
|
2021-11-18 19:17:00 +01:00
|
|
|
cy.get('svg').should((svg) => {
|
2022-08-28 11:39:22 +02:00
|
|
|
// const height = parseFloat(svg.attr('height'));
|
2021-11-18 19:17:00 +01:00
|
|
|
const width = parseFloat(svg.attr('width'));
|
2022-08-28 11:39:22 +02:00
|
|
|
// expect(height).to.eq(450);
|
2021-11-18 19:17:00 +01:00
|
|
|
expect(width).to.eq(984);
|
|
|
|
expect(svg).to.not.have.attr('style');
|
|
|
|
});
|
2020-08-25 17:05:01 +02:00
|
|
|
});
|
2023-02-25 15:47:38 -06:00
|
|
|
it('should render a pie diagram when textPosition is set', () => {
|
2023-02-25 15:42:18 -06:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
pie
|
|
|
|
"Dogs": 50
|
|
|
|
"Cats": 25
|
|
|
|
`,
|
|
|
|
{ logLevel: 1, pie: { textPosition: 0.9 } }
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2019-09-18 18:25:06 +02:00
|
|
|
});
|