Skip to content

Commit

Permalink
[fix]UT
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Sep 6, 2023
1 parent 3c4b221 commit 2cd0903
Showing 1 changed file with 75 additions and 23 deletions.
98 changes: 75 additions & 23 deletions src/mapboxgl/web-map/control/identify/__tests__/Identify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,10 +108,9 @@ describe('Identify.vue', () => {

it('clcik layer on map', async done => {
// 设置外界传入的参数,对面填充和边框的颜色
const color = '#FF0000'
const color = '#FF0000';
wrapper = mount({
template:
`
template: `
<sm-web-map style="height:700px" :mapId="mapInfo">
<sm-identify
:fields="['地区','人口数']"
Expand All @@ -137,7 +135,7 @@ describe('Identify.vue', () => {
level: 5,
center: { x: 0, y: 0 },
baseLayer: {
mapId: 1160955209,
mapId: 1160955209,
layerType: 'TILE',
name: 'China',
url: 'http://172.16.14.44:8190/iportal'
Expand All @@ -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 })
}
};
}
Expand All @@ -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: `<sm-web-map style="height:700px" :mapId="mapInfo">
<sm-identify :layers="['test']"></sm-identify>
</sm-web-map>`,
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: `
Expand Down

0 comments on commit 2cd0903

Please sign in to comment.