Skip to content

Commit 60d3f5a

Browse files
committed
BGDIINF_SB-3186: Avoid flaky tests on cypress cloud
Some tests that rely on clicking on the map requires that the map has been fully rendered otherwise the test will failed. Somehow when using cypress cloud it seems that the openlayer rendering is a bit delayed and some tests are therefore failing.
1 parent 9a339ba commit 60d3f5a

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

src/modules/map/components/cesium/CesiumMap.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ export default {
256256
if (this.isProjectionWebMercator) {
257257
this.createViewer()
258258
} else {
259-
log.debug('Projection is not yet set to WebMercator, Cesium will not load yet')
259+
log.warn('Projection is not yet set to WebMercator, Cesium will not load yet')
260260
}
261+
log.info('CesiumMap component mounted and ready')
261262
},
262263
beforeUnmount() {
263264
if (this.viewer) {
@@ -294,6 +295,7 @@ export default {
294295
'click',
295296
'toggleFloatingTooltip',
296297
'setCenter',
298+
'mapModuleReady',
297299
]),
298300
async createViewer() {
299301
this.viewer = new Viewer(this.$refs.viewer, {
@@ -384,6 +386,7 @@ export default {
384386
// reduce screen space error to downgrade visual quality but speed up tests
385387
globe.maximumScreenSpaceError = 30
386388
}
389+
this.mapModuleReady()
387390
},
388391
highlightSelectedFeatures() {
389392
const [firstFeature] = this.selectedFeatures

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

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { get as getProjection } from 'ol/proj'
44
import { register } from 'ol/proj/proj4'
55
import proj4 from 'proj4'
66
import { onMounted, provide, ref } from 'vue'
7+
import { useStore } from 'vuex'
78
89
import { IS_TESTING_WITH_CYPRESS } from '@/config'
910
import OpenLayersBackgroundLayer from '@/modules/map/components/openlayers/OpenLayersBackgroundLayer.vue'
@@ -15,6 +16,9 @@ import OpenLayersVisibleLayers from '@/modules/map/components/openlayers/OpenLay
1516
import useMapInteractions from '@/modules/map/components/openlayers/utils/map-interactions.composable'
1617
import useViewBasedOnProjection from '@/modules/map/components/openlayers/utils/map-views.composable'
1718
import allCoordinateSystems, { WGS84 } from '@/utils/coordinates/coordinateSystems'
19+
import log from '@/utils/logging'
20+
21+
const store = useStore()
1822
1923
// register any custom projection in OpenLayers
2024
register(proj4)
@@ -40,9 +44,17 @@ if (IS_TESTING_WITH_CYPRESS) {
4044
window.map = map
4145
}
4246
47+
map.once('rendercomplete', () => {
48+
// This is needed for cypress in order to start the tests only
49+
// when openlayer is rendered otherwise some tests will fail.
50+
store.dispatch('mapModuleReady')
51+
log.info('Openlayer map rendered')
52+
})
53+
4354
onMounted(() => {
4455
map.setTarget(mapElement.value)
4556
useMapInteractions(map)
57+
log.info('OpenLayersMap component mounted and ready')
4658
})
4759
</script>
4860

src/modules/map/components/openlayers/utils/map-interactions.composable.js

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useStore } from 'vuex'
77

88
import { useMouseOnMap } from '@/modules/map/components/common/mouse-click.composable'
99
import { LV95 } from '@/utils/coordinates/coordinateSystems'
10+
import log from '@/utils/logging'
1011

1112
export default function useMapInteractions(map) {
1213
const { onLeftClickDown, onLeftClickUp, onRightClick, onMouseMove } = useMouseOnMap()
@@ -67,6 +68,9 @@ export default function useMapInteractions(map) {
6768
mapElement.addEventListener('pointerdown', onPointerDown)
6869
mapElement.addEventListener('pointerup', onPointerUp)
6970
mapElement.addEventListener('pointermove', onMouseMove)
71+
log.info('setup map pointer events')
72+
} else {
73+
log.warn('failed to setup map pointer events')
7074
}
7175
setInteractionAccordingToProjection()
7276

src/store/modules/app.store.js

+10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ export default {
77
* @type Boolean
88
*/
99
isReady: false,
10+
11+
/**
12+
* Flag telling that the Map Module is ready. This is usefull for E2E testing which should
13+
* not start before the Map Module is ready.
14+
*/
15+
isMapReady: false,
1016
},
1117
getters: {},
1218
actions: {
1319
setAppIsReady: ({ commit }) => {
1420
commit('setAppIsReady')
1521
},
22+
mapModuleReady: ({ commit }) => {
23+
commit('mapModuleReady')
24+
},
1625
},
1726
mutations: {
1827
setAppIsReady: (state) => (state.isReady = true),
28+
mapModuleReady: (state) => (state.isMapReady = true),
1929
},
2030
}

src/views/MapView.vue

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import InfoboxModule from '@/modules/infobox/InfoboxModule.vue'
2222
import MapFooter from '@/modules/map/components/footer/MapFooter.vue'
2323
import MapModule from '@/modules/map/MapModule.vue'
2424
import MenuModule from '@/modules/menu/MenuModule.vue'
25+
import log from '@/utils/logging'
2526
import OpenFullAppLink from '@/utils/OpenFullAppLink.vue'
2627
2728
export default {
@@ -41,6 +42,9 @@ export default {
4142
isDrawing: (state) => state.ui.showDrawingOverlay,
4243
}),
4344
},
45+
mounted() {
46+
log.info(`Map view mounted`)
47+
},
4448
}
4549
</script>
4650

tests/e2e-cypress/support/commands.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Cypress.Commands.add(
189189
onBeforeLoad: (win) => mockGeolocation(win, geolocationMockupOptions),
190190
})
191191
// waiting for the app to load and layers to be configured.
192-
cy.waitUntilState((state) => state.app.isReady, { timeout: 10000 })
192+
cy.waitUntilState((state) => state.app.isMapReady, { timeout: 10000 })
193193
cy.waitUntilState(
194194
(state) => {
195195
const active = state.layers.activeLayers.length

0 commit comments

Comments
 (0)