Skip to content

Commit 460227e

Browse files
committed
add tests for actions
1 parent f1464b8 commit 460227e

File tree

5 files changed

+685
-70
lines changed

5 files changed

+685
-70
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"workbench.colorTheme": "Visual Studio Light"
2+
"workbench.colorTheme": "Default Dark Modern"
33
}

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/components/Routing.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export default Vue.extend({
136136
return this.selectedRouteTypesToAvoid
137137
},
138138
set(value: string): void {
139-
console.error(this.selectedRouteTypesToAvoid)
140139
this.setSelectedRouteTypesToAvoid(value)
141140
},
142141
},
@@ -155,7 +154,6 @@ export default Vue.extend({
155154
},
156155
mounted() {
157156
this.initializeTool()
158-
console.error('jetzt bin ich gemounted')
159157
},
160158
methods: {
161159
...mapActions('plugin/routing', [
@@ -174,7 +172,6 @@ export default Vue.extend({
174172
const localKey = this.selectableRouteTypesToAvoid.find(
175173
(element) => element.key === myKey
176174
).localKey
177-
console.error(localKey)
178175
return localKey
179176
},
180177
},

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

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,18 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
1818
commit,
1919
state,
2020
}) {
21-
console.error(configuration)
2221
dispatch('initializeConfigStyle') // testen
2322
drawLayer = createDrawLayer(drawSource)
24-
map.addLayer(drawLayer) // testen, ob es passiert ist
25-
console.error(map.getLayers().getArray())
26-
map.on('click', function (event) {
23+
map?.addLayer(drawLayer) // testen, ob es passiert ist
24+
map?.on('click', function (event) {
2725
const formattedCoordinate = event.coordinate
28-
console.error('formatierte Koordinate: ' + formattedCoordinate)
2926

3027
// prüfen, ob im state schon startAddress vorhanden ist - falls ja, die neue Koordinate als endAddress speichern
3128
if (state.start.length === 0) {
3229
commit('setStart', formattedCoordinate) // wurde setStart als commit aufgerufen und meine formatierte Coordinate reingeschrieben? Im State überprüfen
3330
} else if (state.end.length === 0) {
3431
commit('setEnd', formattedCoordinate)
3532
}
36-
console.error(event)
37-
console.error('Start:' + state.start + 'Ende: ' + state.end)
3833
})
3934
},
4035
// limitNumberWithinRange(value) {
@@ -44,24 +39,17 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
4439
// return Math.min(Math.max(parsed, MIN), MAX)
4540
// },
4641
translateCoordinateToWGS84({ rootGetters: { configuration } }, Coordinate) {
47-
console.error('Translate Methode', configuration?.epsg, Coordinate)
4842
const wgs84Coordinate = transform(
4943
Coordinate,
5044
configuration?.epsg,
5145
'EPSG:4326'
5246
)
53-
console.error('Koordinate in WGS84: ', wgs84Coordinate)
5447
return wgs84Coordinate
5548
},
5649
resetCoordinates({ commit, state }) {
5750
// TODO: Fehler beheben: "unknown local mutation type: resetCoordinates"
5851
commit('setStart', [])
5952
commit('setEnd', [])
60-
console.error(
61-
'Start- und Endpunkt im Store nach reset:',
62-
state.start,
63-
state.end
64-
)
6553
},
6654
createUrl({ rootGetters: { configuration }, state }) {
6755
// TODO: Travel-Modes mit Switch Case (?) in finale Form bringen o. bessere Lösung finden
@@ -71,57 +59,46 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
7159
'/' +
7260
configuration?.routing?.format
7361

74-
console.error(url)
7562
return url
7663
},
7764
async sendRequest({ commit, dispatch, state }) {
7865
const searchCoordinates = [
7966
await dispatch('translateCoordinateToWGS84', state.start),
8067
await dispatch('translateCoordinateToWGS84', state.end),
8168
]
82-
console.error(searchCoordinates)
8369
const url = await dispatch('createUrl')
84-
console.error('Die übergebene URL: ', url)
85-
const fetchDirections = async () => {
86-
try {
87-
const response = await fetch(url, {
88-
method: 'POST',
89-
headers: {
90-
'Content-Type': 'application/json',
91-
},
92-
body: JSON.stringify({
93-
coordinates: searchCoordinates,
94-
geometry: true,
95-
instructions: true,
96-
language: 'en',
97-
options: {
98-
avoid_polygons: {
99-
coordinates: [],
100-
type: 'MultiPolygon',
101-
},
70+
71+
// Direkt auf die verschachtelte Funktion warten
72+
try {
73+
const response = await fetch(url, {
74+
method: 'POST',
75+
headers: {
76+
'Content-Type': 'application/json',
77+
},
78+
body: JSON.stringify({
79+
coordinates: searchCoordinates,
80+
geometry: true,
81+
instructions: true,
82+
language: 'en',
83+
options: {
84+
avoid_polygons: {
85+
coordinates: [],
86+
type: 'MultiPolygon',
10287
},
103-
preference: 'recommended',
104-
units: 'm',
105-
}),
106-
})
107-
if (!response.ok) {
108-
throw new Error(`HTTP error! Status: ${response.status}`)
109-
}
110-
const data = await response.json()
111-
console.error('Response:', data)
112-
commit('setSearchResponseData', data)
113-
dispatch('drawRoute')
114-
console.error(
115-
'Zu vermeidende Routen aus dem Store:',
116-
state.selectedRouteTypesToAvoid
117-
)
118-
console.error('Travel Mode aus dem Store:', state.selectedTravelMode)
119-
console.error('Preference aus dem Store:', state.selectedPreference)
120-
} catch (error) {
121-
console.error('Error:', error)
88+
},
89+
preference: 'recommended',
90+
units: 'm',
91+
}),
92+
})
93+
if (!response.ok) {
94+
throw new Error(`HTTP error! Status: ${response.status}`)
12295
}
96+
const data = await response.json()
97+
commit('setSearchResponseData', data)
98+
dispatch('drawRoute')
99+
} catch (error) {
100+
console.error('Error:', error)
123101
}
124-
fetchDirections()
125102
},
126103
createSearchUrl(searchInput) {
127104
const url =
@@ -139,22 +116,21 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
139116
if (!response.ok) {
140117
throw new Error(`HTTP error! Status: ${response.status}`)
141118
}
142-
console.error(response.text())
143119
} catch (error) {
144120
console.error('send Search Error', error)
145121
}
146122
}
147123
},
148124
drawRoute({ rootGetters: { configuration }, state }) {
149-
console.error(`stored response: `, state.searchResponseData)
125+
if (!state.searchResponseData?.features?.length) {
126+
console.error('No features available for drawing')
127+
return
128+
}
129+
150130
const transformedCoordinates =
151131
state.searchResponseData.features[0].geometry.coordinates.map(
152132
(coordinate) => transform(coordinate, 'EPSG:4326', 'EPSG:25832')
153133
)
154-
console.error(
155-
`coordinates transformed for drawing purpose: `,
156-
transformedCoordinates
157-
)
158134
const routeLineString = new LineString(transformedCoordinates)
159135

160136
const routeFeature = new Feature({
@@ -167,8 +143,8 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
167143
)
168144
)
169145
drawSource.addFeature(routeFeature)
170-
console.error(drawSource.getFeatures())
171146
},
147+
172148
checkConfig({ rootGetters: { configuration }, commit }) {
173149
if (configuration?.routing?.selectableTravelModes) {
174150
commit(
@@ -190,10 +166,12 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
190166
: commit('setDisplayPreferences', false)
191167
},
192168
addFeatures({ commit }, { geoJSON, overwrite = false }) {
193-
const features = new GeoJSON().readFeatures(geoJSON).map((feature) => {
194-
return feature
195-
})
169+
if (!geoJSON || !geoJSON.features?.length) {
170+
console.error('Invalid geoJSON data')
171+
return
172+
}
196173

174+
const features = new GeoJSON().readFeatures(geoJSON)
197175
if (overwrite) {
198176
drawSource.clear()
199177
}

0 commit comments

Comments
 (0)