Skip to content

Commit ad37233

Browse files
author
Nicolò Maria Mezzopera
committed
Merge branch 'master' of github.com:KoRiGaN/Vue2Leaflet
2 parents 716afc3 + 3ecab9b commit ad37233

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Leaflet plugins can easily work with Vue2Leaflet, if you want to use one I would
8989
* [vue2-leaflet-gpx](https://github.com/tdcook/vue2-leaflet-gpx) wrapper for [leaflet-gpx](https://github.com/mpetazzoni/leaflet-gpx)
9090
* [vue2-leaflet-locatecontrol](https://github.com/vUdav/vue2-leaflet-locatecontrol) wrapper for [Leaflet.Locate](https://github.com/domoritz/leaflet-locatecontrol)
9191
* [vue2-leaflet-polygonfillpattern](https://github.com/guillaumejounel/vue2-leaflet-polygonfillpattern) wrapper for [leaflet-polygon-fillPattern](https://github.com/lwsu/leaflet-polygon-fillPattern)
92+
* [vue2-leaflet-axesgrid](https://github.com/mudin/vue2-leaflet-axesgrid) wrapper for [AxesGrid](https://github.com/mudin/Leaflet.AxesGrid)
9293

9394
If you have created a plugin and want it to be listed here, let me know :-).
9495

docs/plugins/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ wrapper for [Leaflet.Locate](https://github.com/domoritz/leaflet-locatecontrol)
6262
## [vue2-leaflet-polygonfillpattern](https://github.com/guillaumejounel/vue2-leaflet-polygonfillpattern)
6363

6464
wrapper for [leaflet-polygon-fillPattern](https://github.com/lwsu/leaflet-polygon-fillPattern)
65+
66+
## [vue2-leaflet-axesgrid](https://github.com/mudin/vue2-leaflet-axesgrid)
67+
68+
wrapper for [AxesGrid](https://github.com/mudin/Leaflet.AxesGrid)

tests/unit/LMarker.spec.js

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

0 commit comments

Comments
 (0)