Skip to content

Commit 4ede700

Browse files
committed
sendSearchRequest updates and first unit test
1 parent 2d8ffd2 commit 4ede700

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

.vscode/settings.json

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

packages/plugins/Routing/src/components/Routing.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:label="$t('common:plugins.routing.startLabel')"
88
:hint="$t('common:plugins.routing.inputHint')"
99
persistent-hint
10+
@input="sendSearchRequest"
1011
>
1112
</v-text-field>
1213
<v-text-field
@@ -161,6 +162,7 @@ export default Vue.extend({
161162
'initializeTool',
162163
'resetCoordinates',
163164
'sendRequest',
165+
'sendSearchRequest',
164166
]),
165167
...mapMutations('plugin/routing', [
166168
'setSelectedTravelMode',
@@ -179,7 +181,7 @@ export default Vue.extend({
179181
})
180182
</script>
181183

182-
<style>
184+
<style lang="scss">
183185
.polar-routing-menu {
184186
display: flex;
185187
flex-direction: column;

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
1919
state,
2020
}) {
2121
console.error(configuration)
22-
dispatch('initializeConfigStyle')
22+
dispatch('initializeConfigStyle') // testen
2323
drawLayer = createDrawLayer(drawSource)
24-
map.addLayer(drawLayer)
24+
map.addLayer(drawLayer) // testen, ob es passiert ist
2525
console.error(map.getLayers().getArray())
2626
map.on('click', function (event) {
2727
const formattedCoordinate = event.coordinate
2828
console.error('formatierte Koordinate: ' + formattedCoordinate)
2929

3030
// prüfen, ob im state schon startAddress vorhanden ist - falls ja, die neue Koordinate als endAddress speichern
3131
if (state.start.length === 0) {
32-
commit('setStart', formattedCoordinate)
32+
commit('setStart', formattedCoordinate) // wurde setStart als commit aufgerufen und meine formatierte Coordinate reingeschrieben? Im State überprüfen
3333
} else if (state.end.length === 0) {
3434
commit('setEnd', formattedCoordinate)
3535
}
@@ -84,7 +84,7 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
8484
console.error('Die übergebene URL: ', url)
8585
const fetchDirections = async () => {
8686
try {
87-
const response = await fetch( url, {
87+
const response = await fetch(url, {
8888
method: 'POST',
8989
headers: {
9090
'Content-Type': 'application/json',
@@ -123,6 +123,28 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
123123
}
124124
fetchDirections()
125125
},
126+
createSearchUrl(searchInput) {
127+
const url =
128+
'https://geodienste.hamburg.de/HH_WFS_GAGES?service=WFS&request=GetFeature&version=2.0.0&StoredQuery_ID=findeStrasse&strassenname=' +
129+
searchInput
130+
return url
131+
},
132+
async sendSearchRequest({ dispatch, state }, searchInput) {
133+
const url = dispatch('createSearchUrl', searchInput)
134+
if (searchInput.length >= state.minLength) {
135+
try {
136+
const response = await fetch(url, {
137+
method: 'GET',
138+
})
139+
if (!response.ok) {
140+
throw new Error(`HTTP error! Status: ${response.status}`)
141+
}
142+
console.error(response.text())
143+
} catch (error) {
144+
console.error('send Search Error', error)
145+
}
146+
}
147+
},
126148
drawRoute({ rootGetters: { configuration }, state }) {
127149
console.error(`stored response: `, state.searchResponseData)
128150
const transformedCoordinates =

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { RoutingState } from '../types'
2-
3-
export const getInitialState = (): RoutingState => ({
2+
const state = {
43
start: [],
54
startAddress: '',
65
end: [],
7-
endAddess: '',
6+
endAddress: '',
87
selectedTravelMode: '',
98
selectableTravelModes: [
109
{ key: 'car', localKey: 'common:plugins.routing.travelMode.car' },
1110
{ key: 'hgv', localKey: 'common:plugins.routing.travelMode.hgv' },
1211
{ key: 'bike', localKey: 'common:plugins.routing.travelMode.bike' },
1312
{ key: 'walking', localKey: 'common:plugins.routing.travelMode.walking' },
14-
{key: 'wheelchair', localKey: 'common:plugins.routing.travelMode.wheelchair',},
13+
{
14+
key: 'wheelchair',
15+
localKey: 'common:plugins.routing.travelMode.wheelchair',
16+
},
1517
],
1618
displayPreferences: false,
1719
selectedPreference: '',
@@ -46,7 +48,17 @@ export const getInitialState = (): RoutingState => ({
4648
},
4749
],
4850
serviceID: '',
49-
numberOfKeysToTriggerSearch: 3,
51+
queryParameters: {
52+
searchAddress: true,
53+
searchStreets: true,
54+
searchHouseNumbers: true,
55+
},
56+
searchInput: '',
57+
addressSearchUrl: '',
58+
minLength: 3,
59+
waitMs: 300,
5060
searchResponseData: {},
5161
mousePosition: [],
52-
})
62+
}
63+
64+
export const getInitialState = (): RoutingState => state
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { mount } from '@vue/test-utils'
2+
import createTestMountParameters, {
3+
MockParameters,
4+
} from '@polar/lib-test-mount-parameters'
5+
import { Routing } from '../components/index'
6+
import { makeStoreModule } from '../store/index'
7+
8+
describe('plugin-routing', () => {
9+
let testParameters: MockParameters
10+
11+
beforeEach(() => {
12+
testParameters = createTestMountParameters()
13+
// täuscht die Erstellung des Stores vor
14+
testParameters.store.registerModule(
15+
['plugin', 'routing'],
16+
makeStoreModule()
17+
)
18+
})
19+
20+
describe('components', () => {
21+
it('should define all elements', () => {
22+
const wrapper = mount(Routing, { ...testParameters }) // hier wird das mounten des Routing components vorgetäuscht
23+
const vBtn = wrapper.findAllComponents({ name: 'v-btn' })
24+
expect(vBtn.length).toBe(3)
25+
})
26+
})
27+
})

0 commit comments

Comments
 (0)