Skip to content

Commit

Permalink
PB-1212: Add test for extending and deleting line.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Dec 9, 2024
1 parent ac89cf9 commit 6629135
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/modules/drawing/components/AddVertexButtonOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ onUnmounted(() => {
</script>

<template>
<AddVertexButton :reverse="true" @button-mounted="onFirstButtonMounted" />
<AddVertexButton :reverse="false" @button-mounted="onLastButtonMounted" />
<AddVertexButton
:reverse="true"
data-cy="extend-from-first-node-button"
@button-mounted="onFirstButtonMounted"
/>
<AddVertexButton
:reverse="false"
data-cy="extend-from-last-node-button"
@button-mounted="onLastButtonMounted"
/>
</template>
53 changes: 53 additions & 0 deletions tests/cypress/tests-e2e/drawing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ describe('Drawing module tests', () => {
.its('request')
.should((request) => checkKMLRequest(request, [new RegExp(`${regexExpression}`)]))
}

// Check that the linestring has the expected number of points
// Only works for line string drawing
function checkLinestringNumberOfPoints(numberOfPoints) {
cy.readWindowValue('drawingLayer')
.then((drawingLayer) => drawingLayer.getSource().getFeatures())
.should((features) => {
expect(features).to.be.an('Array').lengthOf(1)
const [feature] = features
const lineStringCoordinates = feature.getGeometry().getCoordinates()
expect(lineStringCoordinates).to.be.an('Array').lengthOf(numberOfPoints)
})
}
beforeEach(() => {
cy.goToDrawing()
})
Expand Down Expand Up @@ -545,6 +558,46 @@ describe('Drawing module tests', () => {
cy.wait(250)
readCoordinateClipboard('feature-detail-coordinate-copy', "2'660'013.50, 1'185'172.00")
})
it('can create line, extend it, and delete the last node by right click', () => {
cy.viewport(1920, 1080)
cy.clickDrawingTool(EditableFeatureTypes.LINEPOLYGON)

const lineCoordinates = [
[500, 500],
[550, 550],
[600, 600],
[700, 600],
[800, 600],
[800, 400],
[900, 400],
[1000, 400],
]
lineCoordinates.forEach((coordinate) => {
cy.get('[data-cy="ol-map"]').click(...coordinate)
})
// should create a line by re-clicking the last point
cy.get('[data-cy="ol-map"]').click(...lineCoordinates.at(lineCoordinates.length - 1))
checkLinestringNumberOfPoints(8)

// Extend from the last node of line
cy.get('[data-cy="extend-from-last-node-button"]').click()
cy.get('[data-cy="ol-map"]').click(1100, 450)
// finish extending the line by clicking the last point
cy.get('[data-cy="ol-map"]').click(1100, 450)
checkLinestringNumberOfPoints(9)

// Extend from the first node of line
cy.get('[data-cy="extend-from-first-node-button"]').click()
cy.get('[data-cy="ol-map"]').click(500, 450)
cy.get('[data-cy="ol-map"]').click(600, 450)
// finish extending the line by clicking the last point
cy.get('[data-cy="ol-map"]').click(600, 450)
checkLinestringNumberOfPoints(11)

// Delete the last node by right click
cy.get('[data-cy="ol-map"]').rightclick()
checkLinestringNumberOfPoints(10)
})
it('can create line/polygons and edit them', () => {
cy.clickDrawingTool(EditableFeatureTypes.LINEPOLYGON)
cy.get('[data-cy="ol-map"]').click(100, 250)
Expand Down

0 comments on commit 6629135

Please sign in to comment.