Skip to content

Commit 9e6d8d7

Browse files
pakbsommerfe
authored andcommitted
PB-2064: replace last use of removed readStoreValue function
and fix some TS error found in legacyParamImport.cy.ts
1 parent ad667a8 commit 9e6d8d7

File tree

4 files changed

+45
-36
lines changed

4 files changed

+45
-36
lines changed

packages/viewer/tests/cypress/cypress.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ declare global {
6868
/**
6969
* Cypress-wait-until wrapper to wait for a specific (Vuex) store state.
7070
*
71-
* Cy.readStoreValue doesn't work as `.its` will prevent retries.
72-
*
7371
* @param predicate
7472
* @param options
7573
*/

packages/viewer/tests/cypress/tests-e2e/geolocation.cy.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/// <reference types="cypress" />
22

3-
import { constants, registerProj4, WGS84, type SingleCoordinate } from '@swissgeo/coordinates'
3+
import { constants, registerProj4, type SingleCoordinate, WGS84 } from '@swissgeo/coordinates'
44
import proj4 from 'proj4'
55

66
import {
77
getGeolocationButtonAndClickIt,
88
testErrorMessage,
9-
checkStorePosition,
109
} from '@/../tests/cypress/tests-e2e/utils'
1110
import { DEFAULT_PROJECTION } from '@/config/map.config'
1211
import useGeolocationStore from '@/store/modules/geolocation'
@@ -26,6 +25,17 @@ const testCases: TestCase[] = [
2625
{ description: 'on 3D Map', is3D: true },
2726
]
2827

28+
function checkPosition(
29+
position: SingleCoordinate | undefined,
30+
expectedX: number,
31+
expectedY: number
32+
) {
33+
expect(position).to.be.an('Array')
34+
expect(position!.length).to.eq(2)
35+
expect(position![0]).to.approximately(expectedX, 0.1)
36+
expect(position![1]).to.approximately(expectedY, 0.1)
37+
}
38+
2939
// PB-701: TODO Those tests below are not working as expected, as the cypress-browser-permissions is not
3040
// working and the geolocation is always allowed, this needs to be reworked and probably need to
3141
// use another plugin.
@@ -111,45 +121,47 @@ describe('Geolocation cypress', () => {
111121
})
112122

113123
// check initial center and zoom
114-
checkStorePosition('state.position.center', x0, y0)
115124
cy.getPinia().then((pinia) => {
116125
const positionStore = usePositionStore(pinia)
117126
expect(positionStore.zoom).to.eq(startingZoom)
127+
checkPosition(positionStore.center, x0, y0)
118128
})
119129

120130
getGeolocationButtonAndClickIt()
121-
checkStorePosition('state.geolocation.position', geoX, geoY)
122131

123-
// check that the map has been centered on the geolocation and zoom is updated
124-
checkStorePosition('state.position.center', geoX, geoY)
125132
cy.getPinia().then((pinia) => {
126-
const positionStore2 = usePositionStore(pinia)
127-
expect(positionStore2.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP)
133+
const geolocationStore = useGeolocationStore(pinia)
134+
checkPosition(geolocationStore.position, geoX, geoY)
135+
136+
// check that the map has been centered on the geolocation and zoom is updated
137+
const positionStore = usePositionStore(pinia)
138+
checkPosition(positionStore.center, geoX, geoY)
139+
expect(positionStore.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP)
128140
})
129141

130142
// Check if the zoom is changed
131143
cy.get('[data-cy="zoom-in"]').click()
132144
cy.getPinia().then((pinia) => {
133-
const positionStore3 = usePositionStore(pinia)
134-
expect(positionStore3.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP + 1)
145+
const positionStore = usePositionStore(pinia)
146+
expect(positionStore.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP + 1)
147+
checkPosition(positionStore.center, geoX, geoY)
135148
})
136-
checkStorePosition('state.position.center', geoX, geoY)
137149

138150
cy.get('[data-cy="zoom-in"]').click()
139151
cy.get('[data-cy="zoom-in"]').click()
140152
cy.getPinia().then((pinia) => {
141-
const positionStore4 = usePositionStore(pinia)
142-
expect(positionStore4.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP + 3)
153+
const positionStore = usePositionStore(pinia)
154+
expect(positionStore.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP + 3)
143155
})
144156

145157
cy.get('[data-cy="zoom-out"]').click()
146158
cy.get('[data-cy="zoom-out"]').click()
147159
cy.get('[data-cy="zoom-out"]').click()
148160
cy.getPinia().then((pinia) => {
149-
const positionStore5 = usePositionStore(pinia)
150-
expect(positionStore5.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP)
161+
const positionStore = usePositionStore(pinia)
162+
expect(positionStore.zoom).to.eq(constants.SWISS_ZOOM_LEVEL_1_25000_MAP)
163+
checkPosition(positionStore.center, geoX, geoY)
151164
})
152-
checkStorePosition('state.position.center', geoX, geoY)
153165
})
154166
it('access from outside Switzerland shows an error message', () => {
155167
// undefined island

packages/viewer/tests/cypress/tests-e2e/legacyParamImport.cy.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/// <reference types="cypress" />
22

3-
import type { ExternalWMSLayer, ExternalWMTSLayer } from '@swissgeo/layers'
3+
import type { ExternalWMSLayer, ExternalWMTSLayer, KMLLayer } from '@swissgeo/layers'
44

55
import { registerProj4, WGS84 } from '@swissgeo/coordinates'
6+
import { LayerType } from '@swissgeo/layers'
67
import { KMLStyle } from '@swissgeo/layers'
78
import proj4 from 'proj4'
89
import { assertDefined } from 'support/utils'
@@ -211,10 +212,11 @@ describe('Test on legacy param import', () => {
211212
expect(activeLayers2).to.be.an('Array').length(1)
212213
const [kmlLayer] = activeLayers2
213214
assertDefined(kmlLayer)
215+
expect(kmlLayer.type).to.eq(LayerType.KML)
214216
expect(kmlLayer.baseUrl).to.eq(`${kmlServiceBaseUrl}${kmlServiceFilePath}`)
215217
expect(kmlLayer.opacity).to.eq(0.6)
216218
expect(kmlLayer.isVisible).to.be.true
217-
expect(kmlLayer.style).to.eq(KMLStyle.GEOADMIN)
219+
expect((kmlLayer as KMLLayer).style).to.eq(KMLStyle.GEOADMIN)
218220
})
219221
})
220222
it('is able to import an external KML from a legacy adminId query param', () => {
@@ -232,10 +234,11 @@ describe('Test on legacy param import', () => {
232234
expect(activeLayers3).to.be.an('Array').length(1)
233235
const [kmlLayer2] = activeLayers3
234236
assertDefined(kmlLayer2)
237+
expect(kmlLayer2.type).to.eq(LayerType.KML)
235238
expect(kmlLayer2.baseUrl).to.eq(`${kmlServiceBaseUrl}${kmlServiceFilePath}`)
236239
expect(kmlLayer2.opacity).to.eq(1)
237240
expect(kmlLayer2.isVisible).to.be.true
238-
expect(kmlLayer2.adminId).to.equal(adminId)
241+
expect((kmlLayer2 as KMLLayer).adminId).to.equal(adminId)
239242
})
240243
})
241244
it("don't keep KML adminId in URL after import", () => {
@@ -253,10 +256,11 @@ describe('Test on legacy param import', () => {
253256
expect(activeLayers4).to.be.an('Array').length(1)
254257
const [kmlLayer3] = activeLayers4
255258
assertDefined(kmlLayer3)
259+
expect(kmlLayer3.type).to.eq(LayerType.KML)
256260
expect(kmlLayer3.baseUrl).to.eq(`${kmlServiceBaseUrl}${kmlServiceFilePath}`)
257261
expect(kmlLayer3.opacity).to.eq(1)
258262
expect(kmlLayer3.isVisible).to.be.true
259-
expect(kmlLayer3.adminId).to.be.equal(adminId)
263+
expect((kmlLayer3 as KMLLayer).adminId).to.be.equal(adminId)
260264
})
261265
cy.url().should('not.contain', adminId)
262266
})
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference types="cypress" />
22

3+
import useUIStore from '@/store/modules/ui'
4+
35
export function moveTimeSlider(x: number) {
46
cy.get('[data-cy="time-slider-bar-cursor-grab"]').trigger('mousedown', { button: 0 })
57
cy.get('[data-cy="time-slider-bar-cursor-grab"]').trigger('mousemove', {
@@ -21,24 +23,17 @@ export function testErrorMessage(message: string) {
2123
cy.get(geolocationButtonSelector).trigger('mousemove', { clientX: 0, clientY: 0, force: true }) // Check error in store
2224

2325
// Check error in store
24-
cy.readStoreValue('state.ui.errors').then((errors) => {
25-
expect(errors).to.be.an('Set')
26+
cy.getPinia().then((pinia) => {
27+
const uiStore = useUIStore(pinia)
28+
expect(uiStore.errors).to.be.a('Set')
2629
// Make sure this is the only error (we don't want to test other errors)
27-
expect(errors.size).to.eq(1)
30+
expect(uiStore.errors.size).to.eq(1)
2831

29-
const error = errors.values().next().value
30-
expect(error.msg).to.eq(message)
32+
const error = uiStore.errors.values().next().value
33+
expect(error).to.be.an('Object')
34+
expect(error!.msg).to.eq(message)
3135
})
3236
// Check error in UI
3337
cy.get('[data-cy="error-window"]').should('be.visible')
3438
cy.get('[data-cy="error-window-close"]').should('be.visible').click() // close the error window
3539
}
36-
37-
export function checkStorePosition(storeString: string, x: number, y: number) {
38-
cy.readStoreValue(storeString).then((center) => {
39-
expect(center).to.be.an('Array')
40-
expect(center.length).to.eq(2)
41-
expect(center[0]).to.approximately(x, 0.1)
42-
expect(center[1]).to.approximately(y, 0.1)
43-
})
44-
}

0 commit comments

Comments
 (0)