Skip to content

Commit 7d289cc

Browse files
committed
Move radius test into test for Circle mixin and include Path there
1 parent 82ca3db commit 7d289cc

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

tests/mixin-tests/circle-tests.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { getWrapperWithMap } from '@/tests/test-helpers';
2+
import { testPathFunctionality } from './path-tests';
3+
4+
export const testCircleFunctionality = (component, componentName = 'it') => {
5+
// The Circle mixin includes the Path mixin.
6+
testPathFunctionality(component, componentName);
7+
8+
// Radius
9+
10+
test(`${componentName} has a getRadius method`, () => {
11+
const { wrapper } = getWrapperWithMap(component);
12+
13+
expect(typeof wrapper.vm.mapObject.getRadius).toEqual('function');
14+
});
15+
16+
test(`${componentName} accepts and uses radius prop`, () => {
17+
const radius = 100;
18+
const { wrapper } = getWrapperWithMap(component, { radius });
19+
20+
expect(wrapper.vm.mapObject.getRadius()).toEqual(radius);
21+
});
22+
23+
test(`${componentName} updates radius when prop changes`, async () => {
24+
const { wrapper } = getWrapperWithMap(component, { radius: 100 });
25+
26+
const newRadius = 2000;
27+
wrapper.setProps({ radius: newRadius });
28+
await wrapper.vm.$nextTick();
29+
30+
expect(wrapper.vm.mapObject.getRadius()).toEqual(newRadius);
31+
});
32+
};

tests/unit/components/LCircle.spec.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getWrapperWithMap } from '@/tests/test-helpers';
2-
import { testPathFunctionality } from '@/tests/mixin-tests/path-tests';
2+
import { testCircleFunctionality } from '@/tests/mixin-tests/circle-tests';
33
import LCircle from '@/components/LCircle.vue';
44
import L from 'leaflet';
55

@@ -10,6 +10,10 @@ describe('component: LCircle.vue', () => {
1010
expect(wrapper.vm.mapObject).toBeDefined();
1111
});
1212

13+
// Circle mixin
14+
15+
testCircleFunctionality(LCircle, 'LCircle.vue');
16+
1317
// latLng property
1418

1519
test('LCircle.vue accepts and uses latLng prop as an array', () => {
@@ -45,25 +49,4 @@ describe('component: LCircle.vue', () => {
4549

4650
expect(wrapper.vm.mapObject.getLatLng()).toEqual(newLatLng);
4751
});
48-
49-
// radius property
50-
51-
test('LCircle.vue accepts and uses radius prop', () => {
52-
const radius = 42;
53-
const { wrapper } = getWrapperWithMap(LCircle, { radius });
54-
expect(wrapper.vm.mapObject.getRadius()).toBe(radius);
55-
});
56-
57-
test('LCircle.vue updates the mapObject radius when prop changes', async () => {
58-
const radius = 42;
59-
const { wrapper } = getWrapperWithMap(LCircle, { radius });
60-
61-
const newRadius = 137;
62-
wrapper.setProps({ radius: newRadius });
63-
await wrapper.vm.$nextTick();
64-
65-
expect(wrapper.vm.mapObject.getRadius()).toBe(newRadius);
66-
});
67-
68-
testPathFunctionality(LCircle, 'LCircle.vue');
6952
});

0 commit comments

Comments
 (0)