From 33ca14b7648dcd5e746bedea8ca4772a4925b511 Mon Sep 17 00:00:00 2001 From: chenxianhui Date: Tue, 16 Apr 2024 16:31:00 +0800 Subject: [PATCH] fix ut --- src/mapboxgl/web-map/WebMapViewModel.ts | 4 ++-- .../layer-list/__tests__/LayerList.spec.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/mapboxgl/web-map/WebMapViewModel.ts b/src/mapboxgl/web-map/WebMapViewModel.ts index 5643b911..e11eda26 100644 --- a/src/mapboxgl/web-map/WebMapViewModel.ts +++ b/src/mapboxgl/web-map/WebMapViewModel.ts @@ -460,7 +460,7 @@ export default class WebMapViewModel extends Events { this.mapParams = mapparams; this._sourceListModel = sourceListModel; this._appreciableLayers = layers; - this._cacheLayerId.push(...layers.map(layer => layer.id)); + this._cacheLayerId.push(...layers.map(layer => layer.renderLayers).flat()); this.triggerEvent('addlayerssucceeded', { map: map, mapparams: this.mapParams @@ -555,7 +555,7 @@ export default class WebMapViewModel extends Events { webMapHandler.on('addlayerssucceeded', ({ mapparams, layers }) => { this.mapParams = mapparams; this._appreciableLayers = layers; - this._cacheLayerId.push(...layers.map(layer => layer.id)); + this._cacheLayerId.push(...layers.map(layer => layer.renderLayers).flat()); this.triggerEvent('addlayerssucceeded', { map: this.map, mapparams: this.mapParams diff --git a/src/mapboxgl/web-map/control/layer-list/__tests__/LayerList.spec.js b/src/mapboxgl/web-map/control/layer-list/__tests__/LayerList.spec.js index 4d1ec574..09ad86ab 100644 --- a/src/mapboxgl/web-map/control/layer-list/__tests__/LayerList.spec.js +++ b/src/mapboxgl/web-map/control/layer-list/__tests__/LayerList.spec.js @@ -77,7 +77,10 @@ describe('LayerList.vue', () => { return { on: (event, callback) => { callback(commonMap); - } + }, + initializeMap: jest.fn(), + clean: jest.fn(), + getLayerCatalog: () => [{id: 'test', type: 'fill', title:'test', visible: true, renderLayers:['test'], renderSource:{id:'s1', type: 'vector'}, dataSource: {}}] } } @@ -205,7 +208,18 @@ describe('LayerList.vue', () => { expect(callback.mock.called).toBeTruthy; expect(wrapper.vm.mapTarget).toBe('map'); wrapper.vm.$nextTick(() => { - wrapper.find('.sm-components-icon-partially-visible').trigger('click'); + const item = { + id: 'test', + visible: true, + type: 'group', + children: [{ + id: 'test1', + visible: true, + type: 'vector', + renderLayers: ['test1'] + }] + } + wrapper.vm.toggleItemVisibility(item) expect(spyProperty).toHaveBeenCalledTimes(1); done(); });