Skip to content

Commit

Permalink
【fix】UT
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Apr 14, 2024
1 parent 09f18d0 commit bfcb359
Show file tree
Hide file tree
Showing 20 changed files with 452 additions and 120,463 deletions.
2 changes: 1 addition & 1 deletion src/common/_mixin/VmUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class VmUpdater extends Vue {
}
let setFun = 'set' + item.replace(item[0], item[0].toUpperCase());
// 子组件的viewModel
this.viewModel && this.viewModel[setFun](newVal);
this.viewModel && this.viewModel[setFun]?.(newVal);
}
},
{ deep: true }
Expand Down
1 change: 0 additions & 1 deletion src/leaflet/web-map/__tests__/WebMap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SmWebMap from '../WebMap.vue';
import { message } from 'ant-design-vue';
import L from '../../leaflet-wrapper';
import mockFetch from 'vue-iclient/test/unit/mocks/FetchRequest';
import mapWrapperLoaded from 'vue-iclient/test/unit/mapWrapperLoaded.js';
import iportal_serviceProxy from '../../../../test/unit/mocks/data/iportal_serviceProxy.json';
import flushPromises from 'flush-promises';
import uniqueLayer_point from 'vue-iclient/test/unit/mocks/data/WebMap/uniqueLayer_point';
Expand Down
95 changes: 23 additions & 72 deletions src/mapboxgl/attributes/__tests__/Attributes.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { mount, config } from '@vue/test-utils';
import SmAttributes from '../Attributes.vue';
import SmWebMap from '.././../web-map/WebMap.vue';
import mapLoaded from 'vue-iclient/test/unit/mapLoaded.js';
import createEmptyMap from 'vue-iclient/test/unit/createEmptyMap';
import mapSubComponentLoaded from 'vue-iclient/test/unit/mapSubComponentLoaded';

describe('Attributes.vue', () => {
let wrapper;
let mapWrapper;
const fieldConfigs = [
{ value: '平均最低气温_Num', visible: false },
{ value: 'SmID', visible: false },
Expand Down Expand Up @@ -230,32 +231,14 @@ describe('Attributes.vue', () => {
}
};

const mapInfo = {
extent: {
leftBottom: { x: 0, y: 0 },
rightTop: { x: 0, y: 0 }
},
level: 5,
center: { x: 0, y: 0 },
baseLayer: {
layerType: 'TILE',
name: 'China',
url: 'http://test'
},
layers: [],
description: '',
projection: 'EPSG:3857',
title: 'testMap',
version: '1.0'
};

beforeAll(() => {
wrapper = null;
config.mapLoad = false;
});

beforeEach(() => {
wrapper = null;
mapWrapper = null;
});

afterEach(() => {
Expand All @@ -264,41 +247,24 @@ describe('Attributes.vue', () => {
if (wrapper) {
wrapper.destroy();
}
if (mapWrapper) {
mapWrapper.destroy();
}
});

afterAll(() => {
config.mapLoad = true;
});

it('render default correctly', async done => {
wrapper = mount(
{
template: `
<div>
<sm-web-map style="height:400px" :mapId="mapInfo"></sm-web-map>
<div style="positon:relative;height:400px;width:100%">
<sm-attributes layerName="UNIQUE-民航数-0" :fieldConfigs="fieldConfigs"></sm-attributes>
</div>
</div>`,
components: {
SmAttributes,
SmWebMap
},
data() {
return {
fieldConfigs: fieldConfigs,
mapInfo: mapInfo
};
}
},
{
sync: false
mapWrapper = await createEmptyMap();
wrapper = mount(SmAttributes, {
propsData: {
layerName: "UNIQUE-民航数-0",
fieldConfigs: fieldConfigs
}
);
const callback = jest.fn();
wrapper.vm.$children[1].$on('loaded', callback);
await mapLoaded(wrapper.vm.$children[0]);
expect(callback.mock.called).toBeTruthy;
});
await mapSubComponentLoaded(wrapper);
expect(wrapper.find('.sm-component-attributes').exists()).toBe(true);
const attributes = wrapper.findAll('.sm-component-attributes');
attributes.setProps({
Expand Down Expand Up @@ -329,39 +295,24 @@ describe('Attributes.vue', () => {
});

it('associate map', async done => {
wrapper = mount({
template: `
<div>
<sm-web-map style="height:400px" :mapId="mapInfo"></sm-web-map>
<div style="positon:relative;height:400px;width:100%">
<sm-attributes layerName="UNIQUE-民航数-0" :fieldConfigs="fieldConfigs"></sm-attributes>
</div>
</div>`,
components: {
SmAttributes,
SmWebMap
},
data() {
return {
fieldConfigs: fieldConfigs,
mapInfo: mapInfo
};
mapWrapper = await createEmptyMap();
wrapper = mount(SmAttributes, {
propsData: {
layerName: "UNIQUE-民航数-0",
fieldConfigs: fieldConfigs
}
});
const callback = jest.fn();
wrapper.vm.$children[1].$on('loaded', callback);
await mapLoaded(wrapper.vm.$children[0]);
expect(callback.mock.called).toBeTruthy;
await mapSubComponentLoaded(wrapper);
let e = {
point: {
x: 0,
y: 1
}
};
wrapper.vm.$children[1].viewModel.map.fire('click', e);
const spy = jest.spyOn(wrapper.vm.$children[1].viewModel, 'zoomToFeatures');
wrapper.vm.viewModel.map.fire('click', e);
const spy = jest.spyOn(wrapper.vm.viewModel, 'zoomToFeatures');
// TODO 具名插槽 overlay 的节点找不到?
wrapper.vm.$children[1].setZoomToFeature();
wrapper.vm.setZoomToFeature();
await wrapper.vm.$nextTick();
expect(spy).toHaveBeenCalled();
done();
Expand Down
16 changes: 0 additions & 16 deletions src/mapboxgl/chart/__tests__/Chart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SmChart from '../Chart.vue';
import mockFetch from 'vue-iclient/test/unit/mocks/FetchRequest';
import chart_restData from 'vue-iclient/test/unit/mocks/data/chart_restData';
import layerData from 'vue-iclient/test/unit/mocks/data/layerData';
import mapSubComponentLoaded from 'vue-iclient/test/unit/mapSubComponentLoaded.js';
import flushPromises from 'flush-promises';

describe('Chart', () => {
Expand Down Expand Up @@ -110,7 +109,6 @@ describe('Chart', () => {
]
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.find('div#smchart-1').exists()).toBe(true);
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
Expand Down Expand Up @@ -235,7 +233,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -361,7 +358,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -482,7 +478,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -530,7 +525,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -723,7 +717,6 @@ describe('Chart', () => {
colorGroup: ['#3fb1e3', '#6be6c1', '#626c91', '#a0a7e6', '#c4ebad']
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -852,7 +845,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -892,7 +884,6 @@ describe('Chart', () => {
]
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
expect(wrapper.vm.mapTarget).toBe('map');
Expand Down Expand Up @@ -947,7 +938,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
await wrapper.setProps({
Expand Down Expand Up @@ -1057,7 +1047,6 @@ describe('Chart', () => {
]
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
expect(wrapper.vm.mapTarget).toBe('map');
Expand Down Expand Up @@ -1112,7 +1101,6 @@ describe('Chart', () => {
]
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
expect(wrapper.vm.mapTarget).toBe('map');
Expand Down Expand Up @@ -1157,7 +1145,6 @@ describe('Chart', () => {
]
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
done();
Expand Down Expand Up @@ -1210,7 +1197,6 @@ describe('Chart', () => {
]
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
expect(wrapper.vm.$el.outerHTML).toContain('canvas');
expect(wrapper.vm.mapTarget).toBe('map');
Expand Down Expand Up @@ -1279,7 +1265,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
await flushPromises();
wrapper.setProps({
mapTarget: 'map',
Expand Down Expand Up @@ -1386,7 +1371,6 @@ describe('Chart', () => {
}
}
});
await mapSubComponentLoaded(wrapper);
let data=["四川","江苏","云南","江西","海南","台湾","上海","广东","福建","北京"]
wrapper.vm._initAxisLabel({}, data)
await flushPromises();
Expand Down
7 changes: 2 additions & 5 deletions src/mapboxgl/compare/__tests__/Compare.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { mount, config } from '@vue/test-utils';
import SmWebMap from '../../web-map/WebMap.vue';
import SmCompare from '../Compare.vue';
import Compare from '../index';
import mapLoaded from 'vue-iclient/test/unit/mapLoaded.js';

jest.mock('mapbox-gl-compare', () => require('@mocks/compare'));

Expand Down Expand Up @@ -62,8 +61,7 @@ describe('Copmpare.vue', () => {
};
}
});
await mapLoaded(wrapper.vm.$children[0].$children[0]);
await mapLoaded(wrapper.vm.$children[0].$children[1]);
await wrapper.vm.$nextTick();
expect(wrapper.find('div.sm-component-compare').exists()).toBe(true);
expect(wrapper.find('div#comparison-container').exists()).toBe(true);
expect(wrapper.find('#beforeMap').exists()).toBe(true);
Expand Down Expand Up @@ -110,8 +108,7 @@ describe('Copmpare.vue', () => {
}
}
);
await mapLoaded(wrapper.vm.$children[0].$children[0]);
await mapLoaded(wrapper.vm.$children[0].$children[1]);
await wrapper.vm.$nextTick();
expect(wrapper.find('.sm-component-compare').attributes()).toHaveProperty('linesize', '5');
expect(wrapper.find('.sm-component-compare').attributes()).toHaveProperty('slidebackground', '#f00');
expect(wrapper.find('.sm-component-compare').attributes()).toHaveProperty('slidesize', '90');
Expand Down
Loading

0 comments on commit bfcb359

Please sign in to comment.