Skip to content

Commit d4fb89a

Browse files
committed
PB-2064: fix feature selection tests
1 parent 099d275 commit d4fb89a

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { FeaturesStore } from '@/store/modules/features/types/features'
2+
import type { ActionDispatcher } from '@/store/types'
3+
4+
import useProfileStore from '@/store/modules/profile'
5+
6+
/** Removes all selected features from the map */
7+
export default function clearSelectedFeaturesByLayerId(
8+
this: FeaturesStore,
9+
layerId: string,
10+
dispatcher: ActionDispatcher
11+
) {
12+
this.selectedFeaturesByLayerId = this.selectedFeaturesByLayerId.filter(
13+
(featuresForLayer) => featuresForLayer.layerId !== layerId
14+
)
15+
if (this.highlightedFeatureId) {
16+
this.highlightedFeatureId = undefined
17+
}
18+
const profileStore = useProfileStore()
19+
if (profileStore.feature) {
20+
profileStore.setProfileFeature(undefined, dispatcher)
21+
}
22+
}

packages/viewer/src/store/modules/features/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
} from '@/store/modules/features/types/features'
77

88
import clearAllSelectedFeatures from '@/store/modules/features/actions/clearAllSelectedFeatures'
9+
import clearSelectedFeaturesByLayerId from '@/store/modules/features/actions/clearSelectedFeaturesByLayerId'
910
import identifyFeatureAt from '@/store/modules/features/actions/identifyFeatureAt'
1011
import loadMoreFeaturesForLayer from '@/store/modules/features/actions/loadMoreFeaturesForLayer'
1112
import setHighlightedFeatureId from '@/store/modules/features/actions/setHighlightedFeatureId'
@@ -26,6 +27,7 @@ const getters: FeaturesStoreGetters = {
2627
}
2728

2829
const actions = {
30+
clearSelectedFeaturesByLayerId,
2931
clearAllSelectedFeatures,
3032
identifyFeatureAt,
3133
loadMoreFeaturesForLayer,

packages/viewer/src/store/modules/layers/actions/identifyFeatures.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ export function identifyFeatures(
5353
const mapStore = useMapStore()
5454
const selectedFeatures = featuresStore.selectedFeatures
5555
const clickInfo = mapStore.clickInfo
56-
57-
if (!clickInfo || !clickInfo.features || !this.isFeatureSelected(clickInfo)) {
56+
if (!clickInfo || !clickInfo.features) {
5857
return
5958
}
6059

@@ -64,11 +63,19 @@ export function identifyFeatures(
6463
let updateFeatures = shouldUpdateFeatures
6564

6665
if (layerId) {
66+
// Check if there are selected features from this layer
6767
updateFeatures = selectedFeatures.some(
6868
(feature) => 'layer' in feature && feature.layer.id === layerId
6969
)
70-
}
7170

71+
// If the layer is now invisible, we should clear features but not re-identify
72+
const layers = this.getLayersById(layerId)
73+
const layer = layers.length > 0 ? layers[0] : undefined
74+
if (layer && !layer.isVisible && updateFeatures) {
75+
featuresStore.clearSelectedFeaturesByLayerId(layerId, dispatcher)
76+
return
77+
}
78+
}
7279
if (updateFeatures) {
7380
featuresStore
7481
.identifyFeatureAt(

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ describe('Testing the feature selection', () => {
8989
if (featureInfoPosition) {
9090
queryParams.featureInfo = featureInfoPosition
9191
}
92-
console.log('goToMapViewWithFeatureSelection queryParams', queryParams)
9392
cy.goToMapView({ queryParams })
9493
}
9594

@@ -371,8 +370,9 @@ describe('Testing the feature selection', () => {
371370
}
372371
it('can select an area to identify features inside it', () => {
373372
const fileName = 'external-kml-file.kml'
373+
const fileNameWithKMLExtension = `KML|${fileName}`
374374
const localKmlFile = `import-tool/${fileName}`
375-
cy.goToMapView({ queryParams: { layers: 'test.wms.layer' } })
375+
cy.goToMapView({ queryParams: { layers: 'test.wms.layer', bgLayer: 'test.background.layer2' } })
376376
cy.wait(['@routeChange', '@layerConfig', '@topics', '@topic-ech'])
377377

378378
const featureCountWithKml = DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION + 1
@@ -404,7 +404,7 @@ describe('Testing the feature selection', () => {
404404
cy.checkOlLayer([
405405
'test.background.layer2',
406406
{ id: 'test.wms.layer', opacity: 0.75 },
407-
fileName,
407+
fileNameWithKMLExtension,
408408
])
409409

410410
cy.get('[data-cy="ol-map"]').as('olMap').should('be.visible')
@@ -515,7 +515,7 @@ describe('Testing the feature selection', () => {
515515
cy.wait('@emptyIdentify')
516516
cy.get('@highlightedFeatures').should('not.exist')
517517

518-
cy.get('@routeChange.all').should('have.length', 6)
518+
cy.get('@routeChange.all').should('have.length', 10)
519519
cy.get('@layerConfig.all').should('have.length', 1)
520520
cy.get('@topics.all').should('have.length', 1)
521521
cy.get('@topic-ech.all').should('have.length', 1)
@@ -527,6 +527,7 @@ describe('Testing the feature selection', () => {
527527
})
528528
it('can select feature by click, add more feature, and deselect feature', () => {
529529
const fileName = '4-points.kml'
530+
const fileNameWithKMLExtension = `KML|${fileName}`
530531
const localKmlFile = `import-tool/${fileName}`
531532
cy.goToMapView()
532533
cy.wait(['@routeChange', '@layerConfig', '@topics', '@topic-ech'])
@@ -556,7 +557,7 @@ describe('Testing the feature selection', () => {
556557

557558
cy.closeMenuIfMobile()
558559

559-
cy.checkOlLayer(['test.background.layer2', fileName])
560+
cy.checkOlLayer(['test.background.layer2', fileNameWithKMLExtension])
560561

561562
cy.get('[data-cy="ol-map"]').as('olMap').should('be.visible')
562563
cy.getPinia().then((pinia) => {
@@ -580,16 +581,21 @@ describe('Testing the feature selection', () => {
580581
)
581582

582583
clickOnMap(pixel3, false)
584+
cy.wait('@routeChange')
585+
cy.wait('@routeChange')
583586
cy.getPinia().then((pinia) => {
584587
const featuresStore3 = useFeaturesStore(pinia)
585588
expect(featuresStore3.selectedFeatures.length).to.eq(1)
586589
})
587590
clickOnMap(pixel1, true)
591+
cy.wait('@routeChange')
592+
cy.wait('@routeChange')
588593
cy.getPinia().then((pinia) => {
589594
const featuresStore4 = useFeaturesStore(pinia)
590595
expect(featuresStore4.selectedFeatures.length).to.eq(2)
591596
})
592597
clickOnMap(pixel1, true)
598+
cy.wait('@routeChange')
593599
cy.getPinia().then((pinia) => {
594600
const featuresStore5 = useFeaturesStore(pinia)
595601
expect(featuresStore5.selectedFeatures.length).to.eq(1)
@@ -598,8 +604,9 @@ describe('Testing the feature selection', () => {
598604
})
599605
it('can print feature information', () => {
600606
const fileName = 'external-kml-file.kml'
607+
const fileNameWithKMLExtension = `KML|${fileName}`
601608
const localKmlFile = `import-tool/${fileName}`
602-
cy.goToMapView({ queryParams: { layers: 'test.wms.layer' } })
609+
cy.goToMapView({ queryParams: { layers: 'test.wms.layer', bgLayer: 'test.background.layer2' } })
603610
cy.wait(['@routeChange', '@layerConfig', '@topics', '@topic-ech'])
604611

605612
cy.openMenuIfMobile()
@@ -630,7 +637,7 @@ describe('Testing the feature selection', () => {
630637
cy.checkOlLayer([
631638
'test.background.layer2',
632639
{ id: 'test.wms.layer', opacity: 0.75 },
633-
fileName,
640+
fileNameWithKMLExtension,
634641
])
635642

636643
cy.get('[data-cy="ol-map"]').as('olMap').should('be.visible')

0 commit comments

Comments
 (0)