From 2cd0903d2ae96b82e7e8d513473779b521522265 Mon Sep 17 00:00:00 2001 From: "luoxiao-supermap.com" Date: Wed, 6 Sep 2023 11:12:27 +0800 Subject: [PATCH] [fix]UT --- .../identify/__tests__/Identify.spec.js | 98 ++++++++++++++----- 1 file changed, 75 insertions(+), 23 deletions(-) diff --git a/src/mapboxgl/web-map/control/identify/__tests__/Identify.spec.js b/src/mapboxgl/web-map/control/identify/__tests__/Identify.spec.js index a7ce6ac1..470425c1 100644 --- a/src/mapboxgl/web-map/control/identify/__tests__/Identify.spec.js +++ b/src/mapboxgl/web-map/control/identify/__tests__/Identify.spec.js @@ -3,8 +3,7 @@ import SmIdentify from '../Identify.vue'; import Identify from '../index'; import SmWebMap from '../../../WebMap.vue'; import mapLoaded from 'vue-iclient/test/unit/mapLoaded.js'; -import { LineStyle, CircleStyle, FillStyle } from '../../../../_types/index' - +import { LineStyle, CircleStyle, FillStyle } from '../../../../_types/index'; describe('Identify.vue', () => { let wrapper; @@ -109,10 +108,9 @@ describe('Identify.vue', () => { it('clcik layer on map', async done => { // 设置外界传入的参数,对面填充和边框的颜色 - const color = '#FF0000' + const color = '#FF0000'; wrapper = mount({ - template: - ` + template: ` { level: 5, center: { x: 0, y: 0 }, baseLayer: { - mapId: 1160955209, + mapId: 1160955209, layerType: 'TILE', name: 'China', url: 'http://172.16.14.44:8190/iportal' @@ -152,7 +150,7 @@ describe('Identify.vue', () => { line: new LineStyle({ 'line-width': 3, 'line-color': '#3fb1e3' }), circle: new CircleStyle({ 'circle-color': '#3fb1e3', 'circle-radius': 6 }), fill: new FillStyle({ 'fill-color': '#3fb1e3', 'fill-opacity': 0.8 }), - stokeLine: new LineStyle({ 'line-width': 3, 'line-color': color }), + stokeLine: new LineStyle({ 'line-width': 3, 'line-color': color }) } }; } @@ -161,34 +159,88 @@ describe('Identify.vue', () => { identifyWrapper = wrapper.vm.$children[0].$children[0]; identifyWrapper.$on('loaded', callback); await mapLoaded(wrapper.vm.$children[0]); - identifyWrapper.setViewModel() + identifyWrapper.setViewModel(); const spy = jest.spyOn(identifyWrapper.viewModel, 'addOverlayToMap'); // 手动设置点击事件的参数,确认是再点击面 const layer = { - "id":"第七次人口普查全国各省人口数(未包含港澳台", - "type":"fill", - "source":"第七次人口普查全国各省人口数(未包含港澳台", - "minzoom":0, - "maxzoom":22, - "layout":{}, - "paint":{"fill-color":{"r":0.5098039215686274,"g":0.42745098039215684,"b":0.7294117647058823,"a":1}, - "fill-opacity":0.9} - } + id: '第七次人口普查全国各省人口数(未包含港澳台', + type: 'fill', + source: '第七次人口普查全国各省人口数(未包含港澳台', + minzoom: 0, + maxzoom: 22, + layout: {}, + paint: { + 'fill-color': { r: 0.5098039215686274, g: 0.42745098039215684, b: 0.7294117647058823, a: 1 }, + 'fill-opacity': 0.9 + } + }; // 设置过了条件,点击的行政区域 - const filter = '["all",["==","地区","青海"]]' - - // - identifyWrapper.viewModel.addOverlayToMap(layer, filter) + const filter = '["all",["==","地区","青海"]]'; + + // + identifyWrapper.viewModel.addOverlayToMap(layer, filter); // 确保修改图层的函数被执行 expect(spy).toHaveBeenCalledTimes(1); - + // 判断图层颜色是否被修改 - expect(identifyWrapper.viewModel.layerStyle.stokeLine.paint['line-color']).toBe(color) + expect(identifyWrapper.viewModel.layerStyle.stokeLine.paint['line-color']).toBe(color); done(); }); + it('clcik layer not on map', async done => { + wrapper = mount({ + template: ` + + `, + components: { + SmIdentify, + SmWebMap + }, + data() { + return { + mapInfo: { + extent: { + leftBottom: { x: 0, y: 0 }, + rightTop: { x: 0, y: 0 } + }, + level: 5, + center: { x: 0, y: 0 }, + baseLayer: { + mapId: 1160955209, + layerType: 'TILE', + name: 'China', + url: 'http://172.16.14.44:8190/iportal' + }, + layers: [], + description: '', + projection: 'EPSG:3857', + title: 'testMap', + version: '1.0' + } + }; + } + }); + const callback = jest.fn(); + identifyWrapper = wrapper.vm.$children[0].$children[0]; + identifyWrapper.$on('loaded', callback); + await mapLoaded(wrapper.vm.$children[0]); + identifyWrapper.bindQueryRenderedFeatures( + { + target: { + getLayer: jest.fn(), + queryRenderedFeatures: (a, b) => { + expect(b.layers.length).toBe(0); + done(); + } + }, + point: { x: 0, y: 0 } + }, + ['test'] + ); + }); + it('grab', async done => { wrapper = mount({ template: `