Skip to content

Commit 24c56e8

Browse files
authored
Merge pull request #488 from geoadmin/bug_BGDIINF_SB-2890_fix_e2e_tests
BGDIINF_SB-2890 : fix some e2e tests
2 parents 75d2d46 + f056e88 commit 24c56e8

File tree

8 files changed

+96
-116
lines changed

8 files changed

+96
-116
lines changed

src/modules/drawing/lib/__tests__/drawingUtils.spec.js

+27-35
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
toLv95,
66
wrapXCoordinates,
77
} from '@/modules/drawing/lib/drawingUtils'
8-
import { WEBMERCATOR, WGS84 } from '@/utils/coordinates/coordinateSystems'
8+
import { LV95, WEBMERCATOR, WGS84 } from '@/utils/coordinates/coordinateSystems'
99
import setupProj4 from '@/utils/setupProj4'
1010
import { expect } from 'chai'
1111
import { describe, it } from 'vitest'
@@ -16,46 +16,38 @@ setupProj4()
1616
describe('Unit test functions from drawingUtils.js', () => {
1717
describe('toLv95(coordinate, "EPSG:4326")', () => {
1818
it('reprojects points from EPSG:4326', () => {
19-
expect(toLv95([6.57268, 46.51333], WGS84.epsg)).to.eql([
20-
2533541.8057776038, 1151703.909974419,
21-
])
19+
expect(LV95.isInBounds(...toLv95([6.57268, 46.51333], WGS84.epsg))).to.be.true
2220
})
2321
it('reprojects points from EPSG:3857', () => {
24-
expect(toLv95([731667, 5862995], WEBMERCATOR.epsg)).to.eql([
25-
2533541.530335663, 1151703.3642947723,
26-
])
22+
expect(LV95.isInBounds(...toLv95([731667, 5862995], WEBMERCATOR.epsg))).to.be.true
2723
})
2824
it('reprojects lines', () => {
29-
expect(
30-
toLv95(
31-
[
32-
[6.57268, 46.51333],
33-
[6.7, 46.7],
34-
],
35-
WGS84.epsg
36-
)
37-
).to.eql([
38-
[2533541.8057776038, 1151703.909974419],
39-
[2543508.4227881124, 1172354.2517551924],
40-
])
25+
const result = toLv95(
26+
[
27+
[6.57268, 46.51333],
28+
[6.7, 46.7],
29+
],
30+
WGS84.epsg
31+
)
32+
expect(result).to.be.an('Array').lengthOf(2)
33+
result.forEach((coord) => {
34+
expect(LV95.isInBounds(...coord)).to.be.true
35+
})
4136
})
4237
it('reprojects polygons', () => {
43-
expect(
44-
toLv95(
45-
[
46-
[6.57268, 46.51333],
47-
[6.7, 46.7],
48-
[6.9, 46.9],
49-
[6.57268, 46.51333],
50-
],
51-
WGS84.epsg
52-
)
53-
).to.eql([
54-
[2533541.8057776038, 1151703.909974419],
55-
[2543508.4227881124, 1172354.2517551924],
56-
[2558957.32134749, 1194462.5957064652],
57-
[2533541.8057776038, 1151703.909974419],
58-
])
38+
const result = toLv95(
39+
[
40+
[6.57268, 46.51333],
41+
[6.7, 46.7],
42+
[6.9, 46.9],
43+
[6.57268, 46.51333],
44+
],
45+
WGS84.epsg
46+
)
47+
expect(result).to.be.an('Array').lengthOf(4)
48+
result.forEach((coord) => {
49+
expect(LV95.isInBounds(...coord)).to.be.true
50+
})
5951
})
6052
})
6153

src/modules/map/components/openlayers/OpenLayersMap.vue

+14-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ import OpenLayersPopover from '@/modules/map/components/openlayers/OpenLayersPop
124124
import OpenLayersVectorLayer from '@/modules/map/components/openlayers/OpenLayersVectorLayer.vue'
125125
import { ClickInfo, ClickType } from '@/store/modules/map.store'
126126
import { CrossHairs } from '@/store/modules/position.store'
127-
import { LV95, WEBMERCATOR } from '@/utils/coordinates/coordinateSystems'
127+
import allCoordinateSystems, {
128+
LV95,
129+
WEBMERCATOR,
130+
WGS84,
131+
} from '@/utils/coordinates/coordinateSystems'
128132
import { LV95_RESOLUTIONS } from '@/utils/coordinates/SwissCoordinateSystem.class'
129133
import { createGeoJSONFeature } from '@/utils/layerUtils'
130134
import log from '@/utils/logging'
@@ -136,6 +140,7 @@ import { defaults as getDefaultInteractions, MouseWheelZoom } from 'ol/interacti
136140
import DoubleClickZoomInteraction from 'ol/interaction/DoubleClickZoom'
137141
import DragRotateInteraction from 'ol/interaction/DragRotate'
138142
import 'ol/ol.css'
143+
import { get as getProjection } from 'ol/proj'
139144
import { register } from 'ol/proj/proj4'
140145
import proj4 from 'proj4'
141146
import { mapActions, mapGetters, mapState } from 'vuex'
@@ -372,6 +377,14 @@ export default {
372377
mounted() {
373378
// register any custom projection in OpenLayers
374379
register(proj4)
380+
// setting the boundaries for projection, in the OpenLayers context, whenever bounds are defined
381+
// this will help OpenLayers know when tiles shouldn't be requested because coordinates are out of bounds
382+
allCoordinateSystems
383+
.filter((projection) => projection.bounds && projection.epsg !== WGS84.epsg)
384+
.forEach((projection) => {
385+
const olProjection = getProjection(projection.epsg)
386+
olProjection?.setExtent(projection.bounds.flatten)
387+
})
375388
this.map.setTarget(this.$refs.map)
376389
// Setting up OL objects
377390
this.mercatorView = new View({

src/utils/setupProj4.js

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { LV03, LV95, WEBMERCATOR } from '@/utils/coordinates/coordinateSystems'
22
import log from '@/utils/logging'
3-
import { get as getProjection } from 'ol/proj'
4-
import { register } from 'ol/proj/proj4'
53
import proj4 from 'proj4'
64

75
/**
@@ -28,16 +26,6 @@ const setupProj4 = (projections = [WEBMERCATOR, LV95, LV03]) => {
2826
throw err
2927
}
3028
})
31-
// registering all "custom" projection with OpenLayers as well
32-
register(proj4)
33-
// setting the boundaries for projection, in the OpenLayers context, whenever bounds are defined
34-
// this will help OpenLayers know when tiles shouldn't be requested because coordinates are out of bounds
35-
projections
36-
.filter((projection) => projection.bounds)
37-
.forEach((projection) => {
38-
const olProjection = getProjection(projection.epsg)
39-
olProjection?.setExtent(projection.bounds.flatten)
40-
})
4129
}
4230

4331
export default setupProj4

tests/e2e-cypress/integration/3d/navigation.cy.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import {
44
CAMERA_MIN_ZOOM_DISTANCE,
55
} from '@/modules/map/components/cesium/constants'
66
import { calculateResolution } from '@/modules/map/components/cesium/utils/cameraUtils'
7-
import { calculateWebMercatorZoom } from '@/store/modules/position.store'
7+
import { WGS84 } from '@/utils/coordinates/coordinateSystems'
8+
import setupProj4 from '@/utils/setupProj4'
89
import { Cartesian3 } from 'cesium'
10+
import proj4 from 'proj4'
11+
12+
setupProj4()
913

1014
describe('Testing 3D navigation', () => {
1115
context('camera limits', () => {
@@ -68,11 +72,15 @@ describe('Testing 3D navigation', () => {
6872
expect(center[0]).to.eq(lon)
6973
expect(center[1]).to.eq(lat)
7074
})
71-
cy.readStoreValue('state.position.zoom').should((zoom) => {
75+
cy.readStoreValue('state').then((state) => {
76+
const { zoom, projection } = state.position
7277
const height = viewer.camera.positionCartographic.height
7378
const resolution = calculateResolution(height, viewer.canvas.clientWidth)
7479
expect(zoom).to.approximately(
75-
calculateWebMercatorZoom(resolution, lat),
80+
projection.getZoomForResolutionAndCenter(
81+
resolution,
82+
proj4(WGS84.epsg, projection.epsg, [lon, lat])
83+
),
7684
0.001
7785
)
7886
})

tests/e2e-cypress/integration/3d/transitionTo3d.cy.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/// <reference types="cypress" />
22

3+
import { DEFAULT_PROJECTION } from '@/config'
4+
import { WGS84 } from '@/utils/coordinates/coordinateSystems'
5+
import setupProj4 from '@/utils/setupProj4'
36
import { Math as CesiumMath } from 'cesium'
7+
import proj4 from 'proj4'
8+
9+
setupProj4()
410

511
describe('Testing transitioning between 2D and 3D', () => {
612
context('3D toggle button', () => {
@@ -90,8 +96,7 @@ describe('Testing transitioning between 2D and 3D', () => {
9096
const lat = 46
9197
const lon = 7
9298
cy.goToMapView({
93-
lat,
94-
lon,
99+
center: proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [lon, lat]),
95100
z: 9,
96101
})
97102
cy.get('[data-cy="3d-button"]').click()

tests/e2e-cypress/integration/drawing/kml.cy.js

+27-55
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
/// <reference types="cypress" />
22
import { EditableFeatureTypes } from '@/api/features.api'
33
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()
410

511
const olSelector = '.ol-viewport'
612

713
// Position of the marker defined in service-kml/lonelyMarker.kml
814
const markerLatitude = 46.883715999352546
915
const markerLongitude = 7.656108679791837
1016

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+
1129
describe('Drawing new KML', () => {
1230
it("Don't save new empty drawing", () => {
1331
cy.intercept('**/api/kml/admin**', (req) => {
@@ -67,7 +85,6 @@ describe('Drawing new KML', () => {
6785
])
6886
)
6987
})
70-
7188
it('Update the previously saved KML if anything is added to the drawing', () => {
7289
let kmlId = null
7390
cy.goToDrawing()
@@ -120,16 +137,7 @@ describe('Drawing existing KML - without adminId (copy)', () => {
120137
const kmlFileUrl = `https://public.geo.admin.ch/api/kml/files/${kmlFileId}`
121138
const kmlUrlParam = `KML|${kmlFileUrl}|Dessin`
122139
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)
133141
})
134142
it("Don't save non modified drawing", () => {
135143
cy.intercept('**/api/kml/admin**', (req) => {
@@ -185,16 +193,8 @@ describe('Drawing existing KML - with adminId', () => {
185193
}).as('put-kml-not-allowed')
186194
const kmlUrlParam = `KML|${kmlFileUrl}|Dessin@adminId=${kmlFileAdminId}`
187195

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+
198198
// delete the drawing
199199
cy.get('[data-cy="drawing-toolbox-delete-button"]').click()
200200
cy.get('[data-cy="modal-confirm-button"]').click()
@@ -224,16 +224,8 @@ describe('Drawing loading KML', () => {
224224
const kmlFileUrl = `https://public.geo.admin.ch/api/kml/files/${kmlFileId}`
225225
const kmlUrlParam = `KML|${kmlFileUrl}|Dessin`
226226

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+
237229
cy.readStoreValue('state.features.selectedFeatures').should('have.length', 0)
238230
cy.readStoreValue('state.drawing.featureIds').should('have.length', 1)
239231
cy.readWindowValue('drawingLayer')
@@ -247,23 +239,15 @@ describe('Drawing loading KML', () => {
247239
.then((layer) => layer.getSource().getFeatures())
248240
.should('have.length', 1)
249241
})
250-
251242
it('Load kml file with adminId and open drawing mode', () => {
252243
//load map with an injected kml layer containing a text
253244
const kmlFileId = 'test-fileID12345678900'
254245
const kmlFileAdminId = 'test-fileAdminID12345678900'
255246
const kmlFileUrl = `https://public.geo.admin.ch/api/kml/files/${kmlFileId}`
256247
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+
267251
cy.readStoreValue('state.features.selectedFeatures').should('have.length', 0)
268252
cy.readStoreValue('state.ui.showDrawingOverlay').should('be.true')
269253
cy.readStoreValue('state.drawing.featureIds').should('have.length', 1)
@@ -274,24 +258,12 @@ describe('Drawing loading KML', () => {
274258
})
275259

276260
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-
289261
/**
290262
* This test verifies multiple things that the kml layer is saved before it is loaded when
291263
* closing the drawing immediately after drawing
292264
*/
293265
it('Check correct passover from drawingLayer to kmlLayer when closing drawing', () => {
294-
//Open drawing mode
266+
goToDrawingWithKmlLayer()
295267
cy.readWindowValue('drawingLayer')
296268
.then((layer) => layer.getSource().getFeatures())
297269
.should('have.length', 0)

tests/e2e-cypress/integration/drawing/marker-text.cy.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference types="cypress" />
22

33
import { EditableFeatureTypes } from '@/api/features.api'
4-
import { LV95 } from '@/utils/coordinates/coordinateSystems'
4+
import { DEFAULT_PROJECTION } from '@/config'
55
import { BLACK, GREEN, LARGE, MEDIUM, RED, SMALL } from '@/utils/featureStyleUtils'
66

77
const drawingStyleMarkerPopup = '[data-cy="drawing-style-marker-popup"]'
@@ -19,8 +19,8 @@ const createAPoint = (
1919
kind,
2020
x = 0,
2121
y = 0,
22-
xx = LV95.defaultCenter[0],
23-
yy = LV95.defaultCenter[1]
22+
xx = DEFAULT_PROJECTION.bounds.center[0],
23+
yy = DEFAULT_PROJECTION.bounds.center[1]
2424
) => {
2525
let kmlId
2626
cy.clickDrawingTool(kind)
@@ -91,7 +91,9 @@ const interceptGreenIcons = () => {
9191

9292
describe('Drawing marker/points', () => {
9393
beforeEach(() => {
94-
cy.goToDrawing()
94+
cy.goToDrawing({
95+
center: DEFAULT_PROJECTION.bounds.center.join(','),
96+
})
9597
})
9698
it('Re-requests all icons from an icon sets with the new color whenever the color changed', () => {
9799
interceptGreenIcons()

0 commit comments

Comments
 (0)