Skip to content

Commit ecda228

Browse files
committed
PB-1383: layer tests
- some more tests coverage corrections - removal of some useless comments - adding some comments to tell people why some changes have happened PB-1383: adding proj4 registration to layers so openlayers supports layers with only swiss projections - Issue with the drag and drop reordering test: when it was called alone, it would pass, when it would be called after the one reordering layers with the buttons, it would fail because a menu popup would show which was not planned. Rather than place a "force" which could pass even if the element is somehow obscured for a non legitimate reason, I switched the order of the tests - Issue with the call of layer capabilities: We've changed the number of expected calls in the tests, as the capabilities are called once per layer, not once in total. If we need to rework the capabilities handling, we'll have to change this test once again.
1 parent 5d29868 commit ecda228

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

packages/layers/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ export * from '@/types/capabilities'
77
export * from '@/types/timeConfig'
88

99
export * from '@/validation'
10+
1011
import { register } from 'ol/proj/proj4'
1112

13+
/**
14+
* We need this to register the Swiss projections within the openlayers library.
15+
*
16+
* If we don't, layers with only Swiss projections can't be rendered by openlayers.
17+
*/
1218
registerProj4(proj4)
1319
register(proj4)

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

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ describe('Test of layer handling', () => {
329329
})
330330
it('reads and adds an external WMTS correctly', () => {
331331
cy.getExternalWmtsMockConfig().then((layerObjects) => {
332-
layerObjects.forEach((layerObject) => (layerObject.isVisible = true))
333332
const [mockExternalWmts1, _, mockExternalWmts3] = layerObjects
334333

335334
cy.goToMapView({
@@ -351,14 +350,14 @@ describe('Test of layer handling', () => {
351350
const layersStore6 = useLayersStore(pinia)
352351
const visibleLayers2 = layersStore6.visibleLayers
353352
expect(visibleLayers2).to.have.lengthOf(layerObjects.length)
354-
visibleLayers2.forEach((layer) => {
353+
visibleLayers2.forEach((layer: Layer) => {
355354
expect(layer.isLoading).to.be.false
356355
expect(layer.isExternal).to.be.true
357356
})
358357
layerObjects.forEach((layer, index) => {
359358
expect(visibleLayers2[index]?.id).to.be.eq(layer.id)
360359
expect(visibleLayers2[index]?.baseUrl).to.be.eq(layer.baseUrl)
361-
expect(visibleLayers2[index]?.name).to.be.eq(layer.id)
360+
expect(visibleLayers2[index]?.name).to.be.eq(layer.name)
362361
expect(visibleLayers2[index]?.isVisible).to.eq(layer.isVisible)
363362
expect(visibleLayers2[index]?.opacity).to.eq(layer.opacity)
364363
})
@@ -454,10 +453,10 @@ describe('Test of layer handling', () => {
454453
}
455454
}),
456455
])
457-
cy.log(`Make sure that the external backend have not been called twice`)
456+
cy.log(`Make sure that the external backend have been called once per layer`)
458457
cy.get(`@externalWMTS-GetCap-${mockExternalWmts1?.baseUrl}.all`).should(
459458
'have.length',
460-
1
459+
2
461460
)
462461
cy.get(`@externalWMTS-GetCap-${mockExternalWmts3?.baseUrl}.all`).should(
463462
'have.length',
@@ -1115,6 +1114,40 @@ describe('Test of layer handling', () => {
11151114
.should(`${upArrowEnable ? 'not.' : ''}be.disabled`)
11161115
})
11171116
}
1117+
it('reorder layers when they are drag and dropped', () => {
1118+
const [bottomLayerId, middleLayerId, topLayerId] = visibleLayerIds
1119+
cy.get(`[data-cy^="menu-active-layer-${bottomLayerId}-"]`)
1120+
.should('be.visible')
1121+
.drag(`[data-cy^="menu-active-layer-${topLayerId}-"]`)
1122+
const checkLayerOrder = (
1123+
expectedBottomLayerId: string,
1124+
expectedMiddleLayerId: string,
1125+
expectedTopLayerId: string
1126+
) => {
1127+
cy.location('hash').then((hash) => {
1128+
const layersParam = new URLSearchParams(hash).get('layers') ?? ''
1129+
const layers = layersParam.split(';')
1130+
cy.wrap(layers).should('have.lengthOf', 3)
1131+
const [firstUrlLayer, secondUrlLayer, thirdUrlLayer] = layers
1132+
cy.wrap(firstUrlLayer).should('contain', expectedBottomLayerId)
1133+
cy.wrap(secondUrlLayer).should('contain', expectedMiddleLayerId)
1134+
cy.wrap(thirdUrlLayer).should('contain', expectedTopLayerId)
1135+
})
1136+
}
1137+
// the bottom layer should now be on top, so the order is now
1138+
// - bottomLayer
1139+
// - topLayer
1140+
// - middleLayer
1141+
checkLayerOrder(`${middleLayerId}`, `${topLayerId}`, `${bottomLayerId}`)
1142+
cy.get(`[data-cy^="menu-active-layer-${middleLayerId}-"]`)
1143+
.should('be.visible')
1144+
.drag(`[data-cy^="menu-active-layer-${topLayerId}-"]`)
1145+
// new state is
1146+
// - bottomLayer
1147+
// - middleLayer
1148+
// - topLayer
1149+
checkLayerOrder(`${topLayerId}`, `${middleLayerId}`, `${bottomLayerId}`)
1150+
})
11181151
it('Reorder layers using the "move" button', () => {
11191152
const [bottomLayerId, middleLayerId, topLayerId] = visibleLayerIds
11201153
cy.openLayerSettings(`${bottomLayerId}`)
@@ -1248,40 +1281,6 @@ describe('Test of layer handling', () => {
12481281
{ id: `${topLayerId}`, opacity: 0.7 },
12491282
])
12501283
})
1251-
it('reorder layers when they are drag and dropped', () => {
1252-
const [bottomLayerId, middleLayerId, topLayerId] = visibleLayerIds
1253-
cy.get(`[data-cy^="menu-active-layer-${bottomLayerId}-"]`)
1254-
.should('be.visible')
1255-
.drag(`[data-cy^="menu-active-layer-${topLayerId}-"]`)
1256-
const checkLayerOrder = (
1257-
expectedBottomLayerId: string,
1258-
expectedMiddleLayerId: string,
1259-
expectedTopLayerId: string
1260-
) => {
1261-
cy.location('hash').then((hash) => {
1262-
const layersParam = new URLSearchParams(hash).get('layers') ?? ''
1263-
const layers = layersParam.split(';')
1264-
cy.wrap(layers).should('have.lengthOf', 3)
1265-
const [firstUrlLayer, secondUrlLayer, thirdUrlLayer] = layers
1266-
cy.wrap(firstUrlLayer).should('contain', expectedBottomLayerId)
1267-
cy.wrap(secondUrlLayer).should('contain', expectedMiddleLayerId)
1268-
cy.wrap(thirdUrlLayer).should('contain', expectedTopLayerId)
1269-
})
1270-
}
1271-
// the bottom layer should now be on top, so the order is now
1272-
// - bottomLayer
1273-
// - topLayer
1274-
// - middleLayer
1275-
checkLayerOrder(`${middleLayerId}`, `${topLayerId}`, `${bottomLayerId}`)
1276-
cy.get(`[data-cy^="menu-active-layer-${middleLayerId}-"]`)
1277-
.should('be.visible')
1278-
.drag(`[data-cy^="menu-active-layer-${topLayerId}-"]`)
1279-
// new state is
1280-
// - bottomLayer
1281-
// - middleLayer
1282-
// - topLayer
1283-
checkLayerOrder(`${topLayerId}`, `${middleLayerId}`, `${bottomLayerId}`)
1284-
})
12851284
})
12861285
context('External layers', () => {
12871286
it('does not show a red icon for internal layers', () => {

0 commit comments

Comments
 (0)