Skip to content

Commit bb98f2c

Browse files
committed
PB-1875: add tests
- Added tests to ensure that, whenever both center and features are present at startup, we prioritize the center
1 parent 46a10b5 commit bb98f2c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/mapviewer/tests/cypress/support/intercepts.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,11 @@ let lastIdentifiedFeatures = []
250250
*
251251
* Features IDs will start from 1 + offset (if an offset is given) and coordinates will be randomly
252252
* selected within the LV95 extent (or within the selection box, if one is given).
253+
*
254+
* @param coordinates {[Number, Number] | undefined} : if this is set, the coordinates of each
255+
* feature generated is set to the given coordinates rather than random coordinates.
253256
*/
254-
const addFeatureIdentificationIntercepts = () => {
257+
export function addFeatureIdentificationIntercepts(coordinates) {
255258
let featureTemplate = {}
256259
let featureDetailTemplate = {}
257260
cy.fixture('features/features.fixture').then((featuresFixture) => {
@@ -356,7 +359,7 @@ const addFeatureIdentificationIntercepts = () => {
356359
featureDetail.bbox = [...coordinate, ...coordinate]
357360
featureDetail.geometry.coordinates = [coordinate]
358361
} else {
359-
const randomCoordinate = [
362+
const randomCoordinate = coordinates ?? [
360363
Cypress._.random(LV95.bounds.lowerX, LV95.bounds.upperX),
361364
Cypress._.random(LV95.bounds.lowerY, LV95.bounds.upperY),
362365
]

packages/mapviewer/tests/cypress/tests-e2e/featureSelection.cy.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import proj4 from 'proj4'
55
import { DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION } from '@/config/map.config'
66
import { FeatureInfoPositions } from '@/store/modules/ui.store'
77

8+
import { addFeatureIdentificationIntercepts } from '../support/intercepts'
9+
810
registerProj4(proj4)
911

1012
describe('Testing the feature selection', () => {
@@ -84,6 +86,7 @@ describe('Testing the feature selection', () => {
8486
goToMapViewWithFeatureSelection()
8587
checkFeatures()
8688
checkFeatureInfoPosition(FeatureInfoPositions.NONE)
89+
8790
// --------------------------------- WIDTH < 400 pixels ---------------------------------------
8891
cy.log(
8992
'When using a viewport with width inferior to 400 pixels, we should always go to infobox when featureInfo is not None.'
@@ -97,6 +100,42 @@ describe('Testing the feature selection', () => {
97100
checkFeatures()
98101
checkFeatureInfoPosition(FeatureInfoPositions.BOTTOMPANEL)
99102
})
103+
it('Centers correctly the map when pre-selected features are present', () => {
104+
cy.log('We ensure that when no center is defined, we are on the center of the extent')
105+
const preDefinedCenter = [2671500, 1190000]
106+
107+
// we override the interception to ensure the features are in a fixed position
108+
cy.goToMapView(
109+
{
110+
layers: `${standardLayer}@features=1:2:3:4:5:6:7:8:9:10`,
111+
},
112+
true,
113+
{},
114+
{
115+
addFeatureIdentificationIntercepts: () =>
116+
addFeatureIdentificationIntercepts(preDefinedCenter),
117+
}
118+
)
119+
120+
cy.readStoreValue('state.position.center').should((storeCenter) => {
121+
expect(storeCenter.length).to.eq(2)
122+
expect(storeCenter[0]).to.to.approximately(preDefinedCenter[0], 0.01)
123+
expect(storeCenter[1]).to.to.approximately(preDefinedCenter[1], 0.01)
124+
})
125+
126+
cy.log(
127+
'We ensure that when a center is defined, we are on that center on application startup'
128+
)
129+
cy.goToMapView({
130+
layers: `${standardLayer}@features=1:2:3:4:5:6:7:8:9:10`,
131+
center: `${preDefinedCenter.join(',')}`,
132+
})
133+
cy.readStoreValue('state.position.center').should((storeCenter) => {
134+
expect(storeCenter.length).to.eq(2)
135+
expect(storeCenter[0]).to.to.approximately(preDefinedCenter[0], 0.01)
136+
expect(storeCenter[1]).to.to.approximately(preDefinedCenter[1], 0.01)
137+
})
138+
})
100139
it.skip('Adds pre-selected features and place the tooltip according to URL param on a bigger screen', () => {
101140
// currently, this breaks on the CI, but works perfectly fine locally. It sets the featureInfo param
102141
// to 'bottomPanel', when it should be set to 'default'.

0 commit comments

Comments
 (0)