Skip to content

Commit

Permalink
Add tests to cover long title case
Browse files Browse the repository at this point in the history
  • Loading branch information
yari-dewalt committed Jul 5, 2024
1 parent 010a93a commit 27410f1
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions cypress/integration/rendering/pie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,60 @@ describe('pie chart', () => {
);
});

it('should render a simple pie diagram with long title', () => {
renderGraph(
`pie title Sports in Sweden that are my favorite to watch
"Bandy": 40
"Ice-Hockey": 80
"Football": 90
`
);
cy.get('svg').should((svg) => {
expect(svg).to.have.attr('width', '100%');
const style = svg.attr('style');
expect(style).to.match(/^max-width: [\d.]+px;$/);
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
expect(maxWidthValue).to.be.within(730, 750); // depends on installed fonts
});
});

it('should render a simple pie diagram with long title and long labels', () => {
renderGraph(
`pie title Time usage on NETFLIX the last few movie nights
"Time spent looking for movie": 90
"Time spent watching it": 10
`
);
cy.get('svg').should((svg) => {
expect(svg).to.have.attr('width', '100%');
const style = svg.attr('style');
expect(style).to.match(/^max-width: [\d.]+px;$/);
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
expect(maxWidthValue).to.be.within(900, 920); // depends on installed fonts
});
});

it('should render a simple pie diagram that is centered with long title', () => {
renderGraph(
`pie title Sports in Sweden that are my favorite to watch
"Bandy": 40
"Ice-Hockey": 80
"Football": 90
`
);
cy.get('g')
.eq(1)
.should((g) => {
const transform = g.attr('transform');
expect(transform).to.match(/translate\(\d+(\.\d+)?,\d+(\.\d+)?\)/);

const translateValues = transform.match(/translate\((\d+(\.\d+)?),(\d+(\.\d+)?)\)/);
const translateX = parseFloat(translateValues[1]);

expect(translateX).to.be.within(280, 300);
});
});

it('should render a simple pie diagram with capital letters for labels', () => {
imgSnapshotTest(
`pie title What Voldemort doesn't have?
Expand All @@ -44,7 +98,7 @@ describe('pie chart', () => {
const style = svg.attr('style');
expect(style).to.match(/^max-width: [\d.]+px;$/);
const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join(''));
expect(maxWidthValue).to.be.within(590, 600); // depends on installed fonts: 596.2 on my PC, 597.5 on CI
expect(maxWidthValue).to.be.within(590, 610); // depends on installed fonts: 596.2 on my PC, 597.5 on CI
});
});

Expand All @@ -59,7 +113,7 @@ describe('pie chart', () => {
);
cy.get('svg').should((svg) => {
const width = parseFloat(svg.attr('width'));
expect(width).to.be.within(590, 600); // depends on installed fonts: 596.2 on my PC, 597.5 on CI
expect(width).to.be.within(590, 610); // depends on installed fonts: 596.2 on my PC, 597.5 on CI
expect(svg).to.not.have.attr('style');
});
});
Expand Down

0 comments on commit 27410f1

Please sign in to comment.