2.4 KB95 lines
Blame
1import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';
2
3describe('pie chart', () => {
4 it('should render a simple pie diagram', () => {
5 imgSnapshotTest(
6 `pie title Sports in Sweden
7 "Bandy": 40
8 "Ice-Hockey": 80
9 "Football": 90
10 `
11 );
12 });
13
14 it('should render a simple pie diagram with long labels', () => {
15 imgSnapshotTest(
16 `pie title NETFLIX
17 "Time spent looking for movie": 90
18 "Time spent watching it": 10
19 `
20 );
21 });
22
23 it('should render a simple pie diagram with capital letters for labels', () => {
24 imgSnapshotTest(
25 `pie title What Voldemort doesn't have?
26 "FRIENDS": 2
27 "FAMILY": 3
28 "NOSE": 45
29 `
30 );
31 });
32
33 it('should render a pie diagram when useMaxWidth is true (default)', () => {
34 renderGraph(
35 `pie title Sports in Sweden
36 "Bandy": 40
37 "Ice-Hockey": 80
38 "Football": 90
39 `,
40 { pie: { useMaxWidth: true } }
41 );
42 cy.get('svg').should((svg) => {
43 expect(svg).to.have.attr('width', '100%');
44 const style = svg.attr('style');
45 expect(style).to.match(/^max-width: [\d.]+px;$/);
46 const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
47 expect(maxWidthValue).to.be.within(590, 600); // depends on installed fonts: 596.2 on my PC, 597.5 on CI
48 });
49 });
50
51 it('should render a pie diagram when useMaxWidth is false', () => {
52 renderGraph(
53 `pie title Sports in Sweden
54 "Bandy": 40
55 "Ice-Hockey": 80
56 "Football": 90
57 `,
58 { pie: { useMaxWidth: false } }
59 );
60 cy.get('svg').should((svg) => {
61 const width = parseFloat(svg.attr('width'));
62 expect(width).to.be.within(590, 600); // depends on installed fonts: 596.2 on my PC, 597.5 on CI
63 expect(svg).to.not.have.attr('style');
64 });
65 });
66
67 it('should render a pie diagram when textPosition is set', () => {
68 imgSnapshotTest(
69 `pie
70 "Dogs": 50
71 "Cats": 25
72 `,
73 { logLevel: 1, pie: { textPosition: 0.9 } }
74 );
75 });
76
77 it('should render a pie diagram with showData', () => {
78 imgSnapshotTest(
79 `pie showData
80 "Dogs": 50
81 "Cats": 25
82 `
83 );
84 });
85 it('should render pie slices only for non-zero values but shows all legends', () => {
86 imgSnapshotTest(
87 ` pie title Pets adopted by volunteers
88 "Dogs" : 386
89 "Cats" : 85
90 "Rats" : 1
91 `
92 );
93 });
94});
95