refactor tests

Co-authored-by: pranavm2109 <mishrap@dickinson.edu>
This commit is contained in:
Shahir Ahmed
2025-03-19 21:18:45 -04:00
parent 573b6d9ba7
commit b322392f97

View File

@@ -177,30 +177,22 @@ section Checkout from website
diagramStartX = parseFloat($diagram.attr('x')); diagramStartX = parseFloat($diagram.attr('x'));
}) })
.then(() => { .then(() => {
// Get all legend lines that include "Sam" cy.get('text.legend').then(($lines) => {
cy.get('text.legend')
.filter((i, el) => el.textContent.includes('long'))
.then(($lines) => {
// Check that there are two lines // Check that there are two lines
expect($lines.length).to.be.equal(9); expect($lines.length).to.be.equal(9);
// Check that for all but the last line it nearly fills the max width // Check that all lines are under the max width
$lines.each((index, el) => { $lines.each((index, el) => {
const bbox = el.getBBox(); const bbox = el.getBBox();
if (index < $lines.length - 1) {
expect(bbox.width).to.be.closeTo(320, 5);
} else {
// Last line may be shorter
expect(bbox.width).to.be.lte(320); expect(bbox.width).to.be.lte(320);
}
}); });
// check margin between diagram and legend is maintained // check baseline margin between diagram and legend is maintained
const longestBBox = $lines.get(0).getBBox(); // longest Line's bbox const longestBBox = $lines.get(7).getBBox(); // longest Line's bbox
if (diagramStartX && longestBBox) { if (diagramStartX && longestBBox) {
const legendRightEdge = longestBBox.x + longestBBox.width; const legendRightEdge = longestBBox.x + longestBBox.width;
const margin = diagramStartX - legendRightEdge; const margin = diagramStartX - legendRightEdge;
expect(margin).to.be.closeTo(100, 2); // expect margin to be around 100 expect(margin).to.be.closeTo(150, 2);
} }
}); });
}); });