-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BGDIINF_SB-3154 : add e2e test to cover crosshair URL param
Handles correctly removal of crosshair param from the URL (removes the crosshair entirely) Changing a bit how the store sync router handles interaction with the store, to make sure we wait for the dispatch to have occurred (hence the async...await instead of previous then(...)) Adding a Cypress utility (and necessary code in the app) so that Cypress can now wait for the sync between the URL and the store be finished. Adding another Cypress utility function that changes a URL param on the fly, without reloading the app. For that I needed to expose to Cypress the VueRouter instance and its history.
- Loading branch information
Showing
6 changed files
with
200 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { DEFAULT_PROJECTION } from '@/config' | ||
import { CrossHairs } from '@/store/modules/position.store' | ||
|
||
describe('Testing the crosshair URL param', () => { | ||
context('At app startup', () => { | ||
it('does not add the crosshair by default', () => { | ||
cy.goToMapView() | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.be.null | ||
expect(positionStore.crossHairPosition).to.be.null | ||
}) | ||
}) | ||
it('adds the crosshair at the center of the map if only the crosshair param is given', () => { | ||
cy.goToMapView({ | ||
crosshair: CrossHairs.point, | ||
}) | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.eq(CrossHairs.point) | ||
expect(positionStore.crossHairPosition).to.eql(positionStore.center) | ||
}) | ||
}) | ||
it('sets the crosshair at the given coordinate if provided in the URL (and not at map center)', () => { | ||
const crossHairPosition = DEFAULT_PROJECTION.bounds.center.map((value) => value + 1000) | ||
cy.goToMapView({ | ||
crosshair: `${CrossHairs.bowl},${crossHairPosition.join(',')}`, | ||
}) | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.eq(CrossHairs.bowl) | ||
expect(positionStore.crossHairPosition).to.eql(crossHairPosition) | ||
}) | ||
}) | ||
}) | ||
context('Changes of URL param value while the app has been loaded', () => { | ||
it('Changes the crosshair types correctly if changed after app load', () => { | ||
cy.goToMapView({ | ||
crosshair: CrossHairs.point, | ||
}) | ||
cy.readStoreValue('state.position.crossHair').should('eq', CrossHairs.point) | ||
cy.changeUrlParam('crosshair', CrossHairs.marker) | ||
cy.readStoreValue('state.position.crossHair').should('eq', CrossHairs.marker) | ||
}) | ||
it('Changes the crosshair position if set after app reload', () => { | ||
cy.goToMapView({ | ||
crosshair: CrossHairs.cross, | ||
}) | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.eq(CrossHairs.cross) | ||
expect(positionStore.crossHairPosition).to.eql(positionStore.center) | ||
}) | ||
|
||
const newCrossHairPosition = DEFAULT_PROJECTION.bounds.center.map( | ||
(value) => value - 12345 | ||
) | ||
cy.changeUrlParam( | ||
'crosshair', | ||
`${CrossHairs.cross},${newCrossHairPosition.join(',')}`, | ||
// a change of the crosshair param with position triggers two dispatches: setCrossHair and setCrossHairPosition | ||
2 | ||
) | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.eq(CrossHairs.cross) | ||
expect(positionStore.crossHairPosition).to.eql(newCrossHairPosition) | ||
}) | ||
}) | ||
it('removes the crosshair if the URL param is removed (or set to null)', () => { | ||
cy.goToMapView({ | ||
crosshair: CrossHairs.circle, | ||
}) | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.eq(CrossHairs.circle) | ||
expect(positionStore.crossHairPosition).to.eql(positionStore.center) | ||
}) | ||
cy.changeUrlParam('crosshair', null, 2) | ||
cy.readStoreValue('state.position').then((positionStore) => { | ||
expect(positionStore.crossHair).to.be.null | ||
expect(positionStore.crossHairPosition).to.be.null | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters