Skip to content

Commit

Permalink
Add cypress test to check width and number of contribution bars
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTXK committed Apr 2, 2023
1 parent 0d89c64 commit 1141240
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions frontend/cypress/tests/chartView/chartView_mergeGroup.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,45 @@ describe('merge group', () => {
.should('be.visible')
.should('be.disabled');
});

it('merge group contribution bars have correct number and width after reload', () => {
cy.get('#summary label.merge-group > input:visible')
.should('be.visible')
.check()
.should('be.checked');

// get the three chart bars and assert they have the correct initial widths
cy.get('.summary-chart__contrib--bar')
.should('have.length', 3)
.then(($bars) => {
// calculate the percentage of the width relative to the parent container
const parentWidth = $bars.eq(0).parent().width();
const width1 = (parseFloat(window.getComputedStyle($bars[0]).width) / parentWidth) * 100;
const width2 = (parseFloat(window.getComputedStyle($bars[1]).width) / parentWidth) * 100;
const width3 = (parseFloat(window.getComputedStyle($bars[2]).width) / parentWidth) * 100;

// assert that the widths are close enough to 100% and 50%
expect(width1).to.be.closeTo(100, 1);
expect(width2).to.be.closeTo(100, 1);
expect(width3).to.be.closeTo(50, 1);
});

cy.reload();

// assert that the chart bars still have the correct widths
cy.get('.summary-chart__contrib--bar')
.should('have.length', 3)
.then(($bars) => {
// calculate the percentage of the width relative to the parent container
const parentWidth = $bars.eq(0).parent().width();
const width1 = (parseFloat(window.getComputedStyle($bars[0]).width) / parentWidth) * 100;
const width2 = (parseFloat(window.getComputedStyle($bars[1]).width) / parentWidth) * 100;
const width3 = (parseFloat(window.getComputedStyle($bars[2]).width) / parentWidth) * 100;

// assert that the widths are close enough to 100% and 50%
expect(width1).to.be.closeTo(100, 1);
expect(width2).to.be.closeTo(100, 1);
expect(width3).to.be.closeTo(50, 1);
});
});
});

0 comments on commit 1141240

Please sign in to comment.