-
Notifications
You must be signed in to change notification settings - Fork 379
/
Copy pathLMarker.spec.js
92 lines (85 loc) · 2.9 KB
/
LMarker.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { createLocalVue, mount } from '@vue/test-utils';
import L from 'leaflet';
import LMarker from '@/components/LMarker.vue';
import LMap from '@/components/LMap.vue';
const localVue = createLocalVue();
function getWrapperWithMap (component, propsData, mountOptions) {
const mapWrapper = mount(LMap, {
localVue
});
const wrapper = mount({
...component,
// trick from here https://github.com/vuejs/vue-test-utils/issues/560#issuecomment-461865315
created () {
this.$parent = mapWrapper.vm;
}
}, {
localVue,
propsData,
sync: false, // avoid warning, see
// Removing sync mode #1137 https://github.com/vuejs/vue-test-utils/issues/1137
...mountOptions
});
return {
wrapper,
mapWrapper
};
}
describe('LMarker.vue', () => {
test('LMarker.vue change prop latLng', async () => {
const initLatlng = L.latLng([11, 22]);
const wrapperAndMap = getWrapperWithMap(LMarker, {
latLng: initLatlng
});
const wrapper = wrapperAndMap.wrapper;
expect(wrapper.exists()).toBe(true);
expect(wrapper.vm.mapObject.getLatLng().equals(initLatlng)).toBe(true);
const newLatLng = L.latLng([1, 1]);
wrapper.setProps({ latLng: newLatLng });
await wrapper.vm.$nextTick();
const curLatLng = wrapper.vm.mapObject.getLatLng();
expect(curLatLng.equals(newLatLng)).toBe(true);
});
test('LMarker.vue default slot text', async () => {
const markerText = 'Hello from marker!';
const wrapperAndMap = getWrapperWithMap(LMarker, {
latLng: [0, 0]
}, {
slots: {
default: markerText
}
});
const wrapper = wrapperAndMap.wrapper;
const mapWrapper = wrapperAndMap.mapWrapper;
expect(mapWrapper.text()).toContain('Leaflet');
expect(wrapper.exists()).toBe(true);
await wrapper.vm.$nextTick();
expect(wrapper.text()).toEqual(markerText);
});
test('LMarker.vue draggable change', async () => {
const wrapperAndMap = getWrapperWithMap(LMarker, {
latLng: [0, 0]
});
const wrapper = wrapperAndMap.wrapper;
const markerObject = wrapper.vm.mapObject;
expect(markerObject.dragging.enabled()).toBeFalsy();
wrapper.setProps({ draggable: true });
await wrapper.vm.$nextTick();
expect(markerObject.dragging.enabled()).toBeTruthy();
wrapper.setProps({ draggable: false });
await wrapper.vm.$nextTick();
expect(markerObject.dragging.enabled()).toBeFalsy();
});
test('LMarker.vue not change prop latLng to null', async () => {
const initLatlng = L.latLng([11, 22]);
const wrapperAndMap = getWrapperWithMap(LMarker, {
latLng: initLatlng
});
const wrapper = wrapperAndMap.wrapper;
expect(wrapper.exists()).toBe(true);
expect(wrapper.vm.mapObject.getLatLng().equals(initLatlng)).toBe(true);
wrapper.setProps({ latLng: null });
await wrapper.vm.$nextTick();
expect(wrapper.vm.mapObject.getLatLng().equals(initLatlng)).toBe(true);
});
});