Skip to content

Commit 7bc261a

Browse files
committed
light mode off and three action tests
1 parent e698efd commit 7bc261a

File tree

5 files changed

+236
-12
lines changed

5 files changed

+236
-12
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
{
2-
"workbench.colorTheme": "Visual Studio Light"
3-
}

jest.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ const config: Config.InitialOptions = {
1616
testEnvironment: 'jsdom',
1717
transform: {
1818
'^[^.]+.vue$': '@vue/vue2-jest',
19-
'^.+\\.tsx?$': 'ts-jest',
19+
'^.+\\.tsx?$': [
20+
'ts-jest',
21+
{
22+
// TypeScript-Fehler ignorieren
23+
isolatedModules: true, // Option 1: Nur ein Modul auf einmal prüfen
24+
diagnostics: false, // Option 2: Alle Typfehler ignorieren
25+
},
26+
],
2027
'^.*\\.js$': 'babel-jest',
2128
},
22-
// jest-canvas-mock and setup file is required because of @masterportal/masterportalapi; setup file is based on setup file from @masterportal/masterportalapi setup
2329
setupFiles: ['jest-canvas-mock'],
2430
setupFilesAfterEnv: ['./__mocks__/jest.setup.js'],
2531
transformIgnorePatterns: [

packages/plugins/Routing/src/store/actions.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
2121
console.error(configuration)
2222
dispatch('initializeConfigStyle') // testen
2323
drawLayer = createDrawLayer(drawSource)
24-
map.addLayer(drawLayer) // testen, ob es passiert ist
25-
console.error(map.getLayers().getArray())
26-
map.on('click', function (event) {
24+
map?.addLayer(drawLayer) // testen, ob es passiert ist
25+
map?.on('click', function (event) {
2726
const formattedCoordinate = event.coordinate
2827
console.error('formatierte Koordinate: ' + formattedCoordinate)
2928

@@ -70,8 +69,6 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
7069
state.selectedTravelMode +
7170
'/' +
7271
configuration?.routing?.format
73-
74-
console.error(url)
7572
return url
7673
},
7774
async sendRequest({ commit, dispatch, state }) {
@@ -186,8 +183,8 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
186183
? commit('setDisplayPreferences', true)
187184
: commit('setDisplayPreferences', false)
188185
configuration?.routing?.displayRouteTypesToAvoid
189-
? commit('setDisplayPreferences', true)
190-
: commit('setDisplayPreferences', false)
186+
? commit('setDisplayRouteTypesToAvoid', true)
187+
: commit('setDisplayRouteTypesToAvoid', false)
191188
},
192189
addFeatures({ commit }, { geoJSON, overwrite = false }) {
193190
const features = new GeoJSON().readFeatures(geoJSON).map((feature) => {
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
})
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { search, setGazetteerUrl } from '@masterportal/masterportalapi'
2+
import { transform as transformCoordinates } from 'ol/proj'
3+
import { FeatureCollection, Feature } from 'geojson'
4+
import { MpApiParameters } from '../../types'
5+
6+
const getFeatureEPSG = (srsName: string): string => {
7+
if (srsName.includes('::')) {
8+
// Case 1 example: "urn:ogc:def:crs:EPSG::25832"
9+
const parts = srsName.split('::')
10+
11+
return `EPSG:${parts[1]}`
12+
} else if (srsName.includes(':')) {
13+
// Case 2 example: "EPSG:25832"
14+
return srsName
15+
}
16+
console.error(
17+
'@polar/plugin-address-search: Unknown formatting of projection:',
18+
srsName
19+
)
20+
throw Error('Unknown formatting of projection: ' + srsName)
21+
}
22+
23+
const mapFeatures = (
24+
results,
25+
signal: AbortSignal,
26+
queryEpsg: string,
27+
featureEpsg: string
28+
): Feature[] =>
29+
results.map((result) => {
30+
const { name, geometry } = result
31+
const coordsAsIntegers = [
32+
parseInt(geometry.coordinates[0]),
33+
parseInt(geometry.coordinates[1]),
34+
]
35+
const transformedCoordinates =
36+
featureEpsg === queryEpsg
37+
? coordsAsIntegers
38+
: transformCoordinates(coordsAsIntegers, featureEpsg, queryEpsg)
39+
40+
return {
41+
...result,
42+
signal,
43+
title: name,
44+
epsg: featureEpsg,
45+
geometry: {
46+
...geometry,
47+
coordinates: transformedCoordinates,
48+
},
49+
}
50+
})
51+
52+
export default async function (
53+
signal: AbortSignal,
54+
url: string,
55+
input: string,
56+
queryParameters: MpApiParameters
57+
): Promise<FeatureCollection> {
58+
setGazetteerUrl(url)
59+
60+
try {
61+
let results = await search(input, {
62+
...queryParameters,
63+
searchStreetBeforeWord: false,
64+
// always trigger search – control done on a higher level as minLength
65+
minCharacters: 0,
66+
})
67+
68+
// If no results were found without using the wildcard, try again with the wildcard
69+
if (results.length === 0) {
70+
results = await search(input, {
71+
...queryParameters,
72+
// always trigger search – control done on a higher level as minLength
73+
minCharacters: 0,
74+
})
75+
if (results.length === 0) {
76+
return {
77+
type: 'FeatureCollection',
78+
features: [],
79+
}
80+
}
81+
}
82+
83+
const firstResult = results[0]
84+
const srsName = firstResult.properties.position.Point[0].$.srsName
85+
86+
const featureEPSG = getFeatureEPSG(srsName)
87+
88+
const featureCollection: FeatureCollection = {
89+
type: 'FeatureCollection',
90+
features: mapFeatures(results, signal, queryParameters.epsg, featureEPSG),
91+
}
92+
93+
return featureCollection
94+
} catch (error) {
95+
console.error('@polar/plugin-address-search', error)
96+
throw new Error('An error occurred while fetching the feature collection.')
97+
}
98+
}

0 commit comments

Comments
 (0)