Skip to content

Commit 88fc290

Browse files
committed
Add tests for LPolyline.vue and Polyline mixin
1 parent cc2c9f3 commit 88fc290

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

tests/mixin-tests/polyline-tests.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { getWrapperWithMap } from '@/tests/test-helpers';
2+
import { testPathFunctionality } from './path-tests';
3+
import L from 'leaflet';
4+
5+
export const toLeafletLL = (latLngs) => latLngs.map(ll => L.latLng(ll));
6+
7+
export const testPolylineFunctionality = (component, componentName = 'it') => {
8+
// The Polyline mixin includes the Path mixin.
9+
testPathFunctionality(component, componentName);
10+
11+
// SmoothFactor
12+
13+
test(`${componentName} accepts and uses smoothFactor prop`, () => {
14+
const smoothFactor = 1.5;
15+
const { wrapper } = getWrapperWithMap(component, { smoothFactor });
16+
17+
expect(wrapper.vm.mapObject.options.smoothFactor).toEqual(smoothFactor);
18+
});
19+
20+
test(`${componentName} updates smoothFactor when prop changes`, async () => {
21+
const { wrapper } = getWrapperWithMap(component, { smoothFactor: 1.5 });
22+
23+
const newSmoothFactor = 2.2;
24+
wrapper.setProps({ smoothFactor: newSmoothFactor });
25+
await wrapper.vm.$nextTick();
26+
27+
expect(wrapper.vm.mapObject.options.smoothFactor).toEqual(newSmoothFactor);
28+
});
29+
30+
test(`${componentName} updates smoothFactor using setSmoothFactor`, async () => {
31+
const { wrapper } = getWrapperWithMap(component, { smoothFactor: 1.5 });
32+
33+
const newSmoothFactor = 2.2;
34+
wrapper.vm.setSmoothFactor(newSmoothFactor);
35+
await wrapper.vm.$nextTick();
36+
37+
expect(wrapper.vm.mapObject.options.smoothFactor).toEqual(newSmoothFactor);
38+
});
39+
40+
// NoClip
41+
42+
test(`${componentName} accepts and uses noClip prop when true`, () => {
43+
const { wrapper } = getWrapperWithMap(component, { noClip: true });
44+
45+
expect(wrapper.vm.mapObject.options.noClip).toBeTruthy();
46+
});
47+
48+
test(`${componentName} accepts and uses noClip prop when false`, () => {
49+
const { wrapper } = getWrapperWithMap(component, { noClip: false });
50+
51+
expect(wrapper.vm.mapObject.options.noClip).toBeFalsy();
52+
});
53+
54+
test(`${componentName} updates noClip when prop changes to false`, async () => {
55+
const { wrapper } = getWrapperWithMap(component, { noClip: true });
56+
57+
wrapper.setProps({ noClip: false });
58+
await wrapper.vm.$nextTick();
59+
60+
expect(wrapper.vm.mapObject.options.noClip).toBeFalsy();
61+
});
62+
63+
test(`${componentName} updates noClip when prop changes to true`, async () => {
64+
const { wrapper } = getWrapperWithMap(component, { noClip: false });
65+
66+
wrapper.setProps({ noClip: true });
67+
await wrapper.vm.$nextTick();
68+
69+
expect(wrapper.vm.mapObject.options.noClip).toBeTruthy();
70+
});
71+
72+
test(`${componentName} updates noClip to false using setNoClip`, async () => {
73+
const { wrapper } = getWrapperWithMap(component, { noClip: true });
74+
75+
wrapper.vm.setNoClip(false);
76+
await wrapper.vm.$nextTick();
77+
78+
expect(wrapper.vm.mapObject.options.noClip).toBeFalsy();
79+
});
80+
81+
test(`${componentName} updates noClip to true using setNoClip`, async () => {
82+
const { wrapper } = getWrapperWithMap(component, { noClip: false });
83+
84+
wrapper.vm.setNoClip(true);
85+
await wrapper.vm.$nextTick();
86+
87+
expect(wrapper.vm.mapObject.options.noClip).toBeTruthy();
88+
});
89+
90+
// AddLatLng
91+
92+
test(`${componentName} adds a point to an empty polyline`, async () => {
93+
const { wrapper } = getWrapperWithMap(component);
94+
95+
const newLatLng = [1, 2];
96+
wrapper.vm.addLatLng(newLatLng);
97+
await wrapper.vm.$nextTick();
98+
99+
expect(wrapper.vm.mapObject.getLatLngs()).toEqual(toLeafletLL([newLatLng]));
100+
});
101+
102+
test(`${componentName} adds multiple points`, async () => {
103+
const { wrapper } = getWrapperWithMap(component, {
104+
105+
});
106+
107+
const newLatLngs = [[1, 2], [2, 3], [3, 4]];
108+
newLatLngs.forEach(ll => wrapper.vm.addLatLng(ll));
109+
await wrapper.vm.$nextTick();
110+
111+
expect(wrapper.vm.mapObject.getLatLngs().length).toEqual(3);
112+
});
113+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { getWrapperWithMap } from '@/tests/test-helpers';
2+
import { testPolylineFunctionality, toLeafletLL } from '@/tests/mixin-tests/polyline-tests';
3+
import LPolyline from '@/components/LPolyline.vue';
4+
5+
describe('component: LPolyline.vue', () => {
6+
test('LPolyline.vue has a mapObject', () => {
7+
const { wrapper } = getWrapperWithMap(LPolyline);
8+
9+
expect(wrapper.vm.mapObject).toBeDefined();
10+
});
11+
12+
// Polyline mixin
13+
14+
testPolylineFunctionality(LPolyline, 'LPolyline.vue');
15+
16+
// latLngs property
17+
18+
test('LPolyline.vue accepts and uses latLngss prop', () => {
19+
const latLngs = [[3.14, 2.79], [31.4, 27.9]];
20+
const { wrapper } = getWrapperWithMap(LPolyline, { latLngs });
21+
22+
expect(wrapper.vm.mapObject.getLatLngs()).toEqual(toLeafletLL(latLngs));
23+
});
24+
25+
test('LPolyline.vue updates the mapObject latLngs when prop is changed', async () => {
26+
const { wrapper } = getWrapperWithMap(LPolyline, { latLng: [[11, 22], [22, 33]] });
27+
28+
const newLatLngs = [[1, 1], [3, 3]];
29+
wrapper.setProps({ latLngs: newLatLngs });
30+
await wrapper.vm.$nextTick();
31+
32+
expect(wrapper.vm.mapObject.getLatLngs()).toEqual(toLeafletLL(newLatLngs));
33+
});
34+
});

0 commit comments

Comments
 (0)