Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1966] Add cypress test for merged groups contribution bars #1970

Merged
merged 7 commits into from
Apr 10, 2023
53 changes: 53 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,57 @@ describe('merge group', () => {
.should('be.visible')
.should('be.disabled');
});

it('should have the correct number of merge group contribution bars and correct length', () => {
// Assumption: The number of merge group contribution bars is 3 and the width of the third bar is 50%.
cy.get('#summary label.merge-group > input:visible')
MarcusTXK marked this conversation as resolved.
Show resolved Hide resolved
.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);
MarcusTXK marked this conversation as resolved.
Show resolved Hide resolved
expect(width2).to.be.closeTo(100, 1);
expect(width3).to.be.closeTo(50, 1);
});
});

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

const initialWidths = [];

// Store the initial widths of the contribution bars
cy.get('.summary-chart__contrib--bar')
.each(($bar) => {
const width = window.getComputedStyle($bar[0]).width;
initialWidths.push(width);
})
.then(() => {
// Reload the page and wait for the loading div to disappear
cy.reload();
cy.get('.overlay-loader').should('not.be.visible');

// Get the contribution bars again and compare their widths with the initial widths
cy.get('.summary-chart__contrib--bar')
.should('have.length', initialWidths.length)
.each(($bar, index) => {
const width = window.getComputedStyle($bar[0]).width;
expect(width).to.equal(initialWidths[index]);
});
});
});
});