1
1
/// <reference types="cypress" />
2
2
import { EditableFeatureTypes } from '@/api/features.api'
3
3
import LayerTypes from '@/api/layers/LayerTypes.enum'
4
+ import { DEFAULT_PROJECTION } from '@/config'
5
+ import { WGS84 } from '@/utils/coordinates/coordinateSystems'
6
+ import setupProj4 from '@/utils/setupProj4'
7
+ import proj4 from 'proj4'
8
+
9
+ setupProj4 ( )
4
10
5
11
const olSelector = '.ol-viewport'
6
12
7
13
// Position of the marker defined in service-kml/lonelyMarker.kml
8
14
const markerLatitude = 46.883715999352546
9
15
const markerLongitude = 7.656108679791837
10
16
17
+ function goToDrawingWithKmlLayer ( layers , withHash = true ) {
18
+ const params = {
19
+ center : proj4 ( WGS84 . epsg , DEFAULT_PROJECTION . epsg , [ markerLongitude , markerLatitude ] ) . join (
20
+ ','
21
+ ) ,
22
+ }
23
+ if ( layers ) {
24
+ params . layers = layers
25
+ }
26
+ cy . goToDrawing ( params , withHash )
27
+ }
28
+
11
29
describe ( 'Drawing new KML' , ( ) => {
12
30
it ( "Don't save new empty drawing" , ( ) => {
13
31
cy . intercept ( '**/api/kml/admin**' , ( req ) => {
@@ -67,7 +85,6 @@ describe('Drawing new KML', () => {
67
85
] )
68
86
)
69
87
} )
70
-
71
88
it ( 'Update the previously saved KML if anything is added to the drawing' , ( ) => {
72
89
let kmlId = null
73
90
cy . goToDrawing ( )
@@ -120,16 +137,7 @@ describe('Drawing existing KML - without adminId (copy)', () => {
120
137
const kmlFileUrl = `https://public.geo.admin.ch/api/kml/files/${ kmlFileId } `
121
138
const kmlUrlParam = `KML|${ kmlFileUrl } |Dessin`
122
139
beforeEach ( ( ) => {
123
- //open drawing mode
124
- cy . goToDrawing (
125
- {
126
- lang : 'fr' ,
127
- lat : markerLatitude ,
128
- lon : markerLongitude ,
129
- layers : kmlUrlParam ,
130
- } ,
131
- true
132
- )
140
+ goToDrawingWithKmlLayer ( kmlUrlParam )
133
141
} )
134
142
it ( "Don't save non modified drawing" , ( ) => {
135
143
cy . intercept ( '**/api/kml/admin**' , ( req ) => {
@@ -185,16 +193,8 @@ describe('Drawing existing KML - with adminId', () => {
185
193
} ) . as ( 'put-kml-not-allowed' )
186
194
const kmlUrlParam = `KML|${ kmlFileUrl } |Dessin@adminId=${ kmlFileAdminId } `
187
195
188
- //open drawing mode
189
- cy . goToMapViewWithDrawingIntercept (
190
- {
191
- lang : 'fr' ,
192
- lat : markerLatitude ,
193
- lon : markerLongitude ,
194
- layers : kmlUrlParam ,
195
- } ,
196
- true
197
- )
196
+ goToDrawingWithKmlLayer ( kmlUrlParam , true )
197
+
198
198
// delete the drawing
199
199
cy . get ( '[data-cy="drawing-toolbox-delete-button"]' ) . click ( )
200
200
cy . get ( '[data-cy="modal-confirm-button"]' ) . click ( )
@@ -224,16 +224,8 @@ describe('Drawing loading KML', () => {
224
224
const kmlFileUrl = `https://public.geo.admin.ch/api/kml/files/${ kmlFileId } `
225
225
const kmlUrlParam = `KML|${ kmlFileUrl } |Dessin`
226
226
227
- //open drawing mode
228
- cy . goToDrawing (
229
- {
230
- lang : 'fr' ,
231
- lat : markerLatitude ,
232
- lon : markerLongitude ,
233
- layers : kmlUrlParam ,
234
- } ,
235
- true
236
- )
227
+ goToDrawingWithKmlLayer ( kmlUrlParam )
228
+
237
229
cy . readStoreValue ( 'state.features.selectedFeatures' ) . should ( 'have.length' , 0 )
238
230
cy . readStoreValue ( 'state.drawing.featureIds' ) . should ( 'have.length' , 1 )
239
231
cy . readWindowValue ( 'drawingLayer' )
@@ -247,23 +239,15 @@ describe('Drawing loading KML', () => {
247
239
. then ( ( layer ) => layer . getSource ( ) . getFeatures ( ) )
248
240
. should ( 'have.length' , 1 )
249
241
} )
250
-
251
242
it ( 'Load kml file with adminId and open drawing mode' , ( ) => {
252
243
//load map with an injected kml layer containing a text
253
244
const kmlFileId = 'test-fileID12345678900'
254
245
const kmlFileAdminId = 'test-fileAdminID12345678900'
255
246
const kmlFileUrl = `https://public.geo.admin.ch/api/kml/files/${ kmlFileId } `
256
247
const kmlUrlParam = `KML|${ kmlFileUrl } |Dessin@adminId=${ kmlFileAdminId } `
257
- //open drawing mode
258
- cy . goToMapViewWithDrawingIntercept (
259
- {
260
- lang : 'fr' ,
261
- lat : markerLatitude ,
262
- lon : markerLongitude ,
263
- layers : kmlUrlParam ,
264
- } ,
265
- true
266
- )
248
+
249
+ goToDrawingWithKmlLayer ( kmlUrlParam )
250
+
267
251
cy . readStoreValue ( 'state.features.selectedFeatures' ) . should ( 'have.length' , 0 )
268
252
cy . readStoreValue ( 'state.ui.showDrawingOverlay' ) . should ( 'be.true' )
269
253
cy . readStoreValue ( 'state.drawing.featureIds' ) . should ( 'have.length' , 1 )
@@ -274,24 +258,12 @@ describe('Drawing loading KML', () => {
274
258
} )
275
259
276
260
describe ( 'Switching from drawing mode to normal mode' , ( ) => {
277
- beforeEach ( ( ) => {
278
- cy . goToDrawing (
279
- {
280
- lang : 'fr' ,
281
- lat : 47.097 ,
282
- lon : 7.743 ,
283
- z : 9.5 ,
284
- } ,
285
- true
286
- )
287
- } )
288
-
289
261
/**
290
262
* This test verifies multiple things that the kml layer is saved before it is loaded when
291
263
* closing the drawing immediately after drawing
292
264
*/
293
265
it ( 'Check correct passover from drawingLayer to kmlLayer when closing drawing' , ( ) => {
294
- //Open drawing mode
266
+ goToDrawingWithKmlLayer ( )
295
267
cy . readWindowValue ( 'drawingLayer' )
296
268
. then ( ( layer ) => layer . getSource ( ) . getFeatures ( ) )
297
269
. should ( 'have.length' , 0 )
0 commit comments