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'
44import proj4 from 'proj4'
55
66import {
77 getGeolocationButtonAndClickIt ,
88 testErrorMessage ,
9- checkStorePosition ,
109} from '@/../tests/cypress/tests-e2e/utils'
1110import { DEFAULT_PROJECTION } from '@/config/map.config'
1211import 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
0 commit comments