Skip to content

Commit

Permalink
Merge pull request #2402 from concord-consortium/187809206-add-tolera…
Browse files Browse the repository at this point in the history
…nce-statements

187809206 add tolerance statements
  • Loading branch information
nstclair-cc authored Sep 16, 2024
2 parents 2b88ec1 + f02af94 commit 7b1f57b
Showing 1 changed file with 165 additions and 0 deletions.
165 changes: 165 additions & 0 deletions cypress/e2e/functional/tile_tests/geometry_tool_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,171 @@ context('Geometry Tool', function () {
geometryToolTile.getGraphPoint().should("have.length", 0);
geometryToolTile.getSelectedGraphPoint().should("have.length", 0);

// Create first polygon from existing points
cy.log('Create first polygon from existing points');
clueCanvas.clickToolbarButton('geometry', 'point');
geometryToolTile.clickGraphPosition(0, 0);
geometryToolTile.clickGraphPosition(10, 0);
geometryToolTile.clickGraphPosition(5, 5);
clueCanvas.clickToolbarButton('geometry', 'polygon');
geometryToolTile.getGraphPoint().should("have.length", 3);
geometryToolTile.getGraphPoint().eq(0).click();
geometryToolTile.getGraphPoint().eq(1).click();
geometryToolTile.getGraphPoint().eq(2).click();
geometryToolTile.getGraphPoint().eq(0).click();
geometryToolTile.getGraphPolygon().should("have.length", 1);
geometryToolTile.getGraphPoint().should("have.length", 3);

// Add a point to the existing polygon
cy.log('Add a point to the existing polygon');
geometryToolTile.clickGraphPosition(10, 0); // Reuse existing point
geometryToolTile.clickGraphPosition(15, 5);
geometryToolTile.clickGraphPosition(5, 5); // Reuse existing point
clueCanvas.clickToolbarButton('geometry', 'polygon');
// check number of points
geometryToolTile.getGraphPoint().should("have.length", 4);

// Verify the polygon count is still 1
geometryToolTile.getGraphPolygon().should("have.length", 1);

// Create a second polygon that shares the same points as the first
cy.log('Create a second polygon that shares a point with the first');
clueCanvas.clickToolbarButton('geometry', 'polygon');
geometryToolTile.clickGraphPosition(15, 10); // new point
geometryToolTile.clickGraphPosition(15, 5); // shared point
geometryToolTile.clickGraphPosition(20, 5); // new point
geometryToolTile.clickGraphPosition(15, 10); // close the polygon

// Point should be shared
geometryToolTile.getGraphPoint().should("have.length", 6); // New point added

// Store the original point coordinates for comparison
let originalCx, originalCy;
clueCanvas.clickToolbarButton('geometry', 'select');
geometryToolTile.clickGraphPosition(15, 5); // shared point
geometryToolTile.getSelectedGraphPoint().then(($point) => {
originalCx = parseFloat($point.attr('cx'));
originalCy = parseFloat($point.attr('cy'));
cy.wrap(originalCx).as('originalCx');
cy.wrap(originalCy).as('originalCy');
});

// Add length labels to two line segments
// Select line segments by clicking between two points
geometryToolTile.clickGraphPosition(7.5, 5); // Middle of the first segment between (5, 5) and (10, 5)
clueCanvas.clickToolbarButton('geometry', 'label');
geometryToolTile.getModalTitle().should('contain.text', 'Length');
geometryToolTile.chooseLabelOption('length');

geometryToolTile.clickGraphPosition(15, 7.5); // Middle of the second segment between (15, 5) and (15, 10)
clueCanvas.clickToolbarButton('geometry', 'label');
geometryToolTile.getModalTitle().should('contain.text', 'Length');
geometryToolTile.chooseLabelOption('length');
geometryToolTile.clickGraphPosition(20, 20); // deselect

let origPointLabel1 = 10.0;
let origPointLabel2 = 5.0;

// Verify that the first point label is close to 10.0
geometryToolTile.getGraphPointLabel().eq(2).invoke('text').then((text) => {
const value = parseFloat(text);
expect(value).to.be.closeTo(origPointLabel1, 0.1); // Allow tolerance for value close to 10.0
});

// Verify that the second point label is close to 5.0
geometryToolTile.getGraphPointLabel().eq(3).invoke('text').then((text) => {
const value = parseFloat(text);
expect(value).to.be.closeTo(origPointLabel2, 0.1); // Allow tolerance for value close to 5.0
});

// Move the point
clueCanvas.clickToolbarButton('geometry', 'select');
geometryToolTile.clickGraphPosition(15, 5); // shared point

// Simulate 4 right arrow key presses
for (let i = 0; i < 4; i++) {
geometryToolTile.getSelectedGraphPoint().trigger('keydown', { keyCode: 39 });
}

// Simulate 4 up arrow key presses
for (let i = 0; i < 4; i++) {
geometryToolTile.getSelectedGraphPoint().trigger('keydown', { keyCode: 38 });
}

// Updated expected values after the point move
let updatedValue1 = origPointLabel1 + 0.4; // 10.4
let updatedValue2 = origPointLabel2 - 0.4; // 4.6

// Verify that the point values changed
geometryToolTile.getSelectedGraphPoint().then(($point) => {
const newPx = parseFloat($point.attr('cx'));
const newPy = parseFloat($point.attr('cy'));

expect(newPx).to.be.greaterThan(originalCx);
expect(newPy).to.be.lessThan(originalCy);
});

// Verify that the first line segment has changed to a value close to 10.4
geometryToolTile.getGraphPointLabel().eq(2).invoke('text').then((text) => {
const lineSegment1 = parseFloat(text);
expect(lineSegment1).to.be.closeTo(updatedValue1, 0.1); // Tolerance for value close to 10.4
});

// Verify that the second line segment has changed to a value close to 4.6
geometryToolTile.getGraphPointLabel().eq(3).invoke('text').then((text) => {
const lineSegment2 = parseFloat(text);
expect(lineSegment2).to.be.closeTo(updatedValue2, 0.1); // Tolerance for value close to 4.6
});

// Move the point back to the original position
// Simulate 4 left arrow key presses
for (let i = 0; i < 4; i++) {
geometryToolTile.getSelectedGraphPoint().trigger('keydown', { keyCode: 37 });
}

// Simulate 4 down arrow key presses
for (let i = 0; i < 4; i++) {
geometryToolTile.getSelectedGraphPoint().trigger('keydown', { keyCode: 40 });
}

// Verify that the point has returned to its original coordinates
geometryToolTile.getSelectedGraphPoint().then(($point) => {
const resetPx = parseFloat($point.attr('cx'));
const resetPy = parseFloat($point.attr('cy'));

expect(resetPx).to.equal(originalCx);
expect(resetPy).to.equal(originalCy);
});

// Verify that the first line segment has returned to a value close to 10.0
geometryToolTile.getGraphPointLabel().eq(2).invoke('text').then((text) => {
const lineSegment1 = parseFloat(text);
expect(lineSegment1).to.be.closeTo(origPointLabel1, 0.1); // Tolerance for value close to 10.0
});

// Verify that the second line segment has returned to a value close to 5.0
geometryToolTile.getGraphPointLabel().eq(3).invoke('text').then((text) => {
const lineSegment2 = parseFloat(text);
expect(lineSegment2).to.be.closeTo(origPointLabel2, 0.1); // Tolerance for value close to 5.0
});

// Verify the point is still shared
geometryToolTile.getGraphPoint().should("have.length", 6); // New point added

// Delete the first polygon
clueCanvas.clickToolbarButton('geometry', 'select');
geometryToolTile.clickGraphPosition(5, 3); //click inside the polygon
clueCanvas.clickToolbarButton('geometry', 'delete');
geometryToolTile.getGraphPolygon().should("have.length", 1);
geometryToolTile.getGraphPoint().should("have.length", 3);

// Delete the second
clueCanvas.clickToolbarButton('geometry', 'select');
geometryToolTile.clickGraphPosition(17, 7); // click inside the polygon
clueCanvas.clickToolbarButton('geometry', 'delete');
geometryToolTile.getGraphPolygon().should("have.length", 0);
geometryToolTile.getGraphPoint().should("have.length", 0);

// Create polygon from existing points
clueCanvas.clickToolbarButton('geometry', 'point');
geometryToolTile.clickGraphPosition(0, 0);
Expand Down

0 comments on commit 7b1f57b

Please sign in to comment.