Skip to content

Commit 0cdd051

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 0cdd051

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ let lastIdentifiedFeatures = []
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).
253253
*/
254-
const addFeatureIdentificationIntercepts = () => {
254+
export function addFeatureIdentificationIntercepts(coordinates) {
255255
let featureTemplate = {}
256256
let featureDetailTemplate = {}
257257
cy.fixture('features/features.fixture').then((featuresFixture) => {
@@ -356,7 +356,7 @@ const addFeatureIdentificationIntercepts = () => {
356356
featureDetail.bbox = [...coordinate, ...coordinate]
357357
featureDetail.geometry.coordinates = [coordinate]
358358
} else {
359-
const randomCoordinate = [
359+
const randomCoordinate = coordinates ?? [
360360
Cypress._.random(LV95.bounds.lowerX, LV95.bounds.upperX),
361361
Cypress._.random(LV95.bounds.lowerY, LV95.bounds.upperY),
362362
]

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

Lines changed: 46 additions & 3 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', () => {
@@ -69,21 +71,37 @@ describe('Testing the feature selection', () => {
6971
}
7072
}
7173

72-
function goToMapViewWithFeatureSelection(featureInfoPosition = null) {
74+
function goToMapViewWithFeatureSelection(
75+
featureInfoPosition = null,
76+
featureCoordinates = null
77+
) {
7378
const params = {
7479
layers: `${standardLayer}@features=1:2:3:4:5:6:7:8:9:10`,
7580
}
81+
if (featureCoordinates) {
82+
addFeatureIdentificationIntercepts(featureCoordinates)
83+
}
7684
if (featureInfoPosition) {
7785
params.featureInfo = featureInfoPosition
7886
}
79-
cy.goToMapView(params)
87+
cy.goToMapView(
88+
params,
89+
true,
90+
{},
91+
{
92+
addFeatureIdentificationIntercepts: () => {
93+
addFeatureIdentificationIntercepts(featureCoordinates)
94+
},
95+
}
96+
)
8097
}
8198

8299
it('Adds pre-selected features and place the tooltip according to URL param on a narrow width screen', () => {
83100
cy.log('When featureInfo is not specified, we should have no tooltip visible')
84101
goToMapViewWithFeatureSelection()
85102
checkFeatures()
86103
checkFeatureInfoPosition(FeatureInfoPositions.NONE)
104+
87105
// --------------------------------- WIDTH < 400 pixels ---------------------------------------
88106
cy.log(
89107
'When using a viewport with width inferior to 400 pixels, we should always go to infobox when featureInfo is not None.'
@@ -97,6 +115,31 @@ describe('Testing the feature selection', () => {
97115
checkFeatures()
98116
checkFeatureInfoPosition(FeatureInfoPositions.BOTTOMPANEL)
99117
})
118+
it('Centers correctly the map when pre-selected features are present', () => {
119+
cy.log('We ensure that when no center is defined, we are on the center of the extent')
120+
const preDefinedCenter = [2671500, 1190000]
121+
122+
goToMapViewWithFeatureSelection(FeatureInfoPositions.NONE, preDefinedCenter)
123+
124+
cy.readStoreValue('state.position.center').should((storeCenter) => {
125+
expect(storeCenter.length).to.eq(2)
126+
expect(storeCenter[0]).to.to.approximately(preDefinedCenter[0], 0.01)
127+
expect(storeCenter[1]).to.to.approximately(preDefinedCenter[1], 0.01)
128+
})
129+
130+
cy.log(
131+
'We ensure that when a center is defined, we are on that center on application startup'
132+
)
133+
cy.goToMapView({
134+
layers: `${standardLayer}@features=1:2:3:4:5:6:7:8:9:10`,
135+
center: `${preDefinedCenter.join(',')}`,
136+
})
137+
cy.readStoreValue('state.position.center').should((storeCenter) => {
138+
expect(storeCenter.length).to.eq(2)
139+
expect(storeCenter[0]).to.to.approximately(preDefinedCenter[0], 0.01)
140+
expect(storeCenter[1]).to.to.approximately(preDefinedCenter[1], 0.01)
141+
})
142+
})
100143
it.skip('Adds pre-selected features and place the tooltip according to URL param on a bigger screen', () => {
101144
// currently, this breaks on the CI, but works perfectly fine locally. It sets the featureInfo param
102145
// to 'bottomPanel', when it should be set to 'default'.
@@ -179,7 +222,7 @@ describe('Testing the feature selection', () => {
179222
})
180223
// ------------------------------------------------------------------------------------------------
181224
cy.log('Check that after a reload, features remain selected')
182-
cy.reload()
225+
cy.reload() // ISSUE HERE : WE DON'T GET THE FEATURE, BUT IT WORKS ON SITE
183226
cy.wait(`@featureDetail_${expectedFeatureIds[1]}`)
184227
cy.url().should((url) => {
185228
new URLSearchParams(url.split('map')[1])

0 commit comments

Comments
 (0)