|
| 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 | +}; |
0 commit comments