|
| 1 | +import { PolarActionHandler } from '@polar/lib-custom-types' |
| 2 | +import proj4 from 'proj4' |
| 3 | +import { register } from 'ol/proj/proj4' |
| 4 | +import { makeStoreModule } from '../store/index' |
| 5 | +import { getInitialState } from '../store/state' |
| 6 | +import { RoutingState, RoutingGetters } from '../types' |
| 7 | + |
| 8 | +describe('plugin-routing', () => { |
| 9 | + describe('store', () => { |
| 10 | + describe('actions', () => { |
| 11 | + describe('resetCoordinates', () => { |
| 12 | + const routingStore = makeStoreModule() |
| 13 | + const resetCoordinates = routingStore.actions |
| 14 | + ?.resetCoordinates as PolarActionHandler<RoutingState, RoutingGetters> |
| 15 | + |
| 16 | + if (typeof resetCoordinates === 'undefined') { |
| 17 | + throw new Error( |
| 18 | + 'Action resetCoordinates is missing in RoutingStore. Tests could not be run.' |
| 19 | + ) |
| 20 | + } |
| 21 | + |
| 22 | + let actionContext |
| 23 | + beforeEach(() => { |
| 24 | + actionContext = { |
| 25 | + state: getInitialState(), |
| 26 | + commit: jest.fn(), |
| 27 | + } |
| 28 | + }) |
| 29 | + |
| 30 | + it('reset the start and end coordinates', () => { |
| 31 | + resetCoordinates(actionContext) |
| 32 | + expect(actionContext.commit).toHaveBeenCalledWith('setStart', []) |
| 33 | + expect(actionContext.commit).toHaveBeenCalledWith('setEnd', []) |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + describe('createUrl', () => { |
| 38 | + const routingStore = makeStoreModule() |
| 39 | + const createUrl = routingStore.actions?.createUrl as PolarActionHandler< |
| 40 | + RoutingState, |
| 41 | + RoutingGetters |
| 42 | + > |
| 43 | + |
| 44 | + if (typeof createUrl === 'undefined') { |
| 45 | + throw new Error( |
| 46 | + 'Action createUrl is missing in RoutingStore. Tests could not be run.' |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + let actionContext |
| 51 | + beforeEach(() => { |
| 52 | + actionContext = { |
| 53 | + rootGetters: { |
| 54 | + configuration: { |
| 55 | + routing: { |
| 56 | + serviceUrl: |
| 57 | + 'https://geodienste.hamburg.de/web_ors/v2/directions/', |
| 58 | + format: 'geojson', |
| 59 | + }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + state: { |
| 63 | + selectedTravelMode: 'car', |
| 64 | + }, |
| 65 | + } |
| 66 | + }) |
| 67 | + |
| 68 | + it('create the correct request url', () => { |
| 69 | + const url = createUrl(actionContext) |
| 70 | + expect(url).toBe( |
| 71 | + 'https://geodienste.hamburg.de/web_ors/v2/directions/car/geojson' |
| 72 | + ) |
| 73 | + }) |
| 74 | + }) |
| 75 | + |
| 76 | + describe('checkConfig', () => { |
| 77 | + const routingStore = makeStoreModule() |
| 78 | + const checkConfig = routingStore.actions |
| 79 | + ?.checkConfig as PolarActionHandler<RoutingState, RoutingGetters> |
| 80 | + |
| 81 | + if (typeof checkConfig === 'undefined') { |
| 82 | + throw new Error( |
| 83 | + 'Action checkConfig is missing in RoutingStore. Tests could not be run.' |
| 84 | + ) |
| 85 | + } |
| 86 | + |
| 87 | + let actionContext |
| 88 | + beforeEach(() => { |
| 89 | + actionContext = { |
| 90 | + rootGetters: { |
| 91 | + configuration: { |
| 92 | + routing: { |
| 93 | + selectableTravelModes: ['cycling-regular', 'foot-walking'], |
| 94 | + selectablePreferences: ['fastest', 'shortest', 'recommended'], |
| 95 | + displayPreferences: true, |
| 96 | + displayRouteTypesToAvoid: false, |
| 97 | + }, |
| 98 | + }, |
| 99 | + }, |
| 100 | + commit: jest.fn(), |
| 101 | + } |
| 102 | + }) |
| 103 | + |
| 104 | + it('store selectableTravelModes from config in store', () => { |
| 105 | + checkConfig(actionContext) |
| 106 | + expect(actionContext.commit).toHaveBeenCalledWith( |
| 107 | + 'setSelectableTravelModes', |
| 108 | + ['cycling-regular', 'foot-walking'] |
| 109 | + ) |
| 110 | + expect(actionContext.commit).toHaveBeenCalledWith( |
| 111 | + 'setSelectablePreferences', |
| 112 | + ['fastest', 'shortest', 'recommended'] |
| 113 | + ) |
| 114 | + expect(actionContext.commit).toHaveBeenCalledWith( |
| 115 | + 'setDisplayPreferences', |
| 116 | + true |
| 117 | + ) |
| 118 | + expect(actionContext.commit).toHaveBeenCalledWith( |
| 119 | + 'setDisplayRouteTypesToAvoid', |
| 120 | + false |
| 121 | + ) |
| 122 | + }) |
| 123 | + }) |
| 124 | + }) |
| 125 | + }) |
| 126 | +}) |
0 commit comments