Skip to content

Commit

Permalink
Merge pull request #1110 from dpc-sdp/bugfix/allow-custom-query-sugge…
Browse files Browse the repository at this point in the history
…stor-key

[R20-1928] add suggestionsKey prop to address lookup
  • Loading branch information
lambry authored Apr 15, 2024
2 parents e23f4fb + eb1620d commit d51b319
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 13 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions examples/nuxt-app/test/features/maps/vicpol.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ Feature: Vicpol map
| Videos |
When I click the tab labelled "Mappy"
Then the ripple map component should be visible

@mockserver
Scenario: Search for location i.e. name
Given the page endpoint for path "/police-station-location" returns fixture "/map-table/vicpol/page" with status 200
Given the "/api/tide/elasticsearch/elasticsearch_index_develop_node/_search" network request is stubbed with fixture "/map-table/vicpol/response" and status 200 as alias "searchReq"
Given the "/api/tide/app-search/vicpol-postcode-localities/elasticsearch/_search" network request is stubbed with fixture "/map-table/vicpol/locations-brunswick" and status 200 as alias "locationsReq"
Given I visit the page "/police-station-location"
When I enter the term "Brunswick" into the location search input
Then the location search results should contain "Brunswick"
And the location search results should contain "Brunswick East"
When I click the location search term "Brunswick East"
Then the location search value should be "Brunswick East"
14 changes: 12 additions & 2 deletions examples/nuxt-app/test/features/maps/vsba.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ Feature: School buildings map
And I wait 8 seconds
Then the map matches the image snapshot "map-location-search"

@mockserver
Scenario: Search for locality
Given the "/api/tide/elasticsearch/elasticsearch_index_develop_node/_search" network request is stubbed with fixture "/map-table/vsba/response-all" and status 200 as alias "searchReq"
Given the "/api/tide/app-search/vic-postcode-localities/elasticsearch/_search" network request is stubbed with fixture "/map-table/vsba/localities-all" and status 200 as alias "localitiesReq"
And I visit the page "/map"
Then the ripple map component should be visible
When I enter the term "Maidstone" into the location search input
Then the location search results should contain "Maidstone"
When I click the location search term "Maidstone"
And I wait 8 seconds
Then the map matches the image snapshot "map-locality-search"

@mockserver
Scenario: No results message
Given the "/api/tide/elasticsearch/elasticsearch_index_develop_node/elasticsearch/_search" network request is stubbed with fixture "/map-table/vsba/response-all" and status 200 as alias "searchReq"
Expand All @@ -52,7 +64,6 @@ Feature: School buildings map
Then the map no results message should contain "Sorry, no results match your search. Try again with different search options or check back later. "
Then the map matches the image snapshot "map-no-results"


@mockserver
Scenario: Filters should display when expanded
Given the "/api/tide/elasticsearch/elasticsearch_index_develop_node/_search" network request is stubbed with fixture "/map-table/vsba/response-all" and status 200 as alias "searchReq"
Expand Down Expand Up @@ -86,4 +97,3 @@ Feature: School buildings map
And I click the tab labelled "List"
Then the search listing layout should be "table"
And the custom collection component results count should read "Displaying 1-5 of 2159 results"

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 8.186846,
"hits": [
{
"_index": ".ent-search-engine-documents-vicpol-postcode-localities",
"_id": "doc-6614936834893a271be59712",
"_score": 8.186846,
"_ignored": [
"name.date",
"bbox.location",
"bbox.date",
"center.date",
"lga.date",
"name.location",
"center.float",
"lga.float",
"name.float",
"lga.location",
"areatype.location",
"postcode.date",
"areatype.float",
"areatype.date"
],
"_source": {
"name": "Brunswick",
"areatype": "locality",
"center": "-37.7663709,144.9612873",
"bbox": [
"144.9487312433437",
"-37.77914470698591",
"144.97699374149008",
"-37.754216423454395"
],
"postcode": [
"3056"
],
"lga": [
"Merri-Bek City"
],
"id": "doc-6614936834893a271be59712"
}
},
{
"_index": ".ent-search-engine-documents-vicpol-postcode-localities",
"_id": "doc-6614936834893a271be59713",
"_score": 6.8628817,
"_ignored": [
"name.date",
"bbox.location",
"bbox.date",
"center.date",
"lga.date",
"name.location",
"center.float",
"lga.float",
"name.float",
"lga.location",
"areatype.location",
"postcode.date",
"areatype.float",
"areatype.date"
],
"_source": {
"name": "Brunswick East",
"areatype": "locality",
"center": "-37.7688661,144.9774309",
"bbox": [
"144.97015817888433",
"-37.78006112595512",
"144.986858061226",
"-37.75690570182761"
],
"postcode": [
"3057"
],
"lga": [
"Merri-Bek City"
],
"id": "doc-6614936834893a271be59713"
}
},
{
"_index": ".ent-search-engine-documents-vicpol-postcode-localities",
"_id": "doc-6614936834893a271be59714",
"_score": 6.391987,
"_ignored": [
"name.date",
"bbox.location",
"bbox.date",
"center.date",
"lga.date",
"name.location",
"center.float",
"lga.float",
"name.float",
"lga.location",
"areatype.location",
"postcode.date",
"areatype.float",
"areatype.date"
],
"_source": {
"name": "Brunswick West",
"areatype": "locality",
"center": "-37.7631082,144.9428497",
"bbox": [
"144.92670325333916",
"-37.77675670579521",
"144.95387035489512",
"-37.751059631280654"
],
"postcode": [
"3055"
],
"lga": [
"Merri-Bek City"
],
"id": "doc-6614936834893a271be59714"
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"_source": {
"postcode": "3012",
"name": "West Footscray",
"locality": "West Footscray",
"bbox": [
"144.8599086043824",
"-37.81372139711867",
Expand All @@ -52,7 +52,7 @@
],
"_source": {
"postcode": "3012",
"name": "Tottenham",
"locality": "Tottenham",
"bbox": [
"144.83922398137892",
"-37.81488230937047",
Expand All @@ -76,7 +76,7 @@
],
"_source": {
"postcode": "3012",
"name": "Kingsville",
"locality": "Kingsville",
"bbox": [
"144.86922793105745",
"-37.81282436915469",
Expand All @@ -100,7 +100,7 @@
],
"_source": {
"postcode": "3012",
"name": "Maidstone",
"locality": "Maidstone",
"bbox": [
"144.86355002689623",
"-37.79115929674402",
Expand All @@ -124,7 +124,7 @@
],
"_source": {
"postcode": "3012",
"name": "Brooklyn",
"locality": "Brooklyn",
"bbox": [
"144.8221039848139",
"-37.82573699929589",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"_source": {
"postcode": "3594",
"name": "Nyah",
"locality": "Nyah",
"bbox": ["143.3305362", "-35.19168", "143.3939623", "-35.09963"],
"id": "doc-659659adcfe7a91138d6cdc8"
}
Expand All @@ -47,7 +47,7 @@
],
"_source": {
"postcode": "3595",
"name": "Nyah West",
"locality": "Nyah West",
"bbox": ["143.308664", "-35.21418", "143.376329", "-35.142365"],
"id": "doc-6596599fcfe7a9121bd6c766"
}
Expand Down
5 changes: 4 additions & 1 deletion examples/nuxt-app/test/fixtures/map-table/vsba/page.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@
"locationQueryConfig": {
"component": "TideSearchAddressLookup",
"dslTransformFunction": "schoolBuildings",
"mapResultsMappingFn": "schoolBuildings"
"mapResultsMappingFn": "schoolBuildings",
"props": {
"suggestionsKey": "locality"
}
},
"resultsConfig": {
"layout": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ When(`I click the location search term {string}`, (term) => {
.click()
})

Then(`the location search value should be {string}`, (term) => {
cy.get('.tide-search-address-lookup .rpl-search-bar__input').should(
'have.value',
term
)
})

Then(`the map matches the image snapshot {string}`, (title) => {
cy.get('.rpl-primary-nav').invoke('remove')
cy.get('.rpl-map').matchImage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface Props {
inputValue?: any
resultsloaded?: boolean
suggestionsIndex?: string
suggestionsKey?: string
controlMapZooming?: boolean
label?: string
placeholder?: string
Expand All @@ -52,6 +53,7 @@ const props = withDefaults(defineProps<Props>(), {
inputValue: null,
resultsloaded: false,
suggestionsIndex: 'vic-postcode-localities',
suggestionsKey: 'name',
controlMapZooming: true,
label: 'Search by postcode or suburb',
placeholder: 'Enter postcode or suburb'
Expand Down Expand Up @@ -96,15 +98,15 @@ const fetchSuggestions = async (query: string) => {
should: [
{
match: {
name: {
[props.suggestionsKey]: {
query,
operator: 'and'
}
}
},
{
prefix: {
name: {
[props.suggestionsKey]: {
value: query,
case_insensitive: true
}
Expand Down Expand Up @@ -135,7 +137,7 @@ const fetchSuggestions = async (query: string) => {
const center = getSingleResultValue(itm._source.center)?.split(',')
return {
name: getSingleResultValue(itm._source.name),
name: getSingleResultValue(itm._source[props.suggestionsKey]),
postcode: getSingleResultValue(itm._source.postcode),
bbox: itm._source.bbox,
center: center?.length === 2 ? [center[1], center[0]] : undefined
Expand Down

0 comments on commit d51b319

Please sign in to comment.