Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R20-1451] Added missing debouncing to suggestions and limit to 128 chars #1235

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ Feature: Search listing - Suggestions

When I type "The" into the search input
Then the search suggestions should not be displayed

@mockserver
Example: Search bar max input length
Given the page endpoint for path "/suggestions" returns fixture "/search-listing/suggestions/page-suggestions" with status 200
And the search network request is stubbed with fixture "/search-listing/suggestions/search-response" and status 200
And the search autocomplete request is stubbed with "/search-listing/suggestions/response" fixture

When I visit the page "/suggestions"
Then the search input should be have a max length of 128
6 changes: 6 additions & 0 deletions examples/nuxt-app/test/features/site/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ Feature: Site search
When I clear the search filters
Then the filters toggle should show 0 applied filters
And the search input should have the value ""

@mockserver
Example: Search bar max input length
Given the "/api/tide/search/**" network request is stubbed with fixture "/site/search-response" and status 200 as alias "siteSearchReq"
When I visit the page "/search"
Then the search input should be have a max length of 128
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ Then('the search form should be hidden', () => {
cy.get(`.tide-search-header`).should('not.exist')
})

Then(
'the search input should be have a max length of {int}',
(maxLength: number) => {
cy.get(`.rpl-search-bar input`).should('have.attr', 'maxlength', maxLength)

cy.get(`.rpl-search-bar input`).type(new Array(maxLength + 5).join('A'))
cy.get(`.rpl-search-bar input`).should(
'have.value',
new Array(maxLength + 1).join('A')
)
}
)

Then('only the search filters should be visible', () => {
cy.get(`.tide-search-header .rpl-search-bar`).should('not.exist')
cy.get(`.tide-search-header .rpl-search-bar-refine`).should('not.exist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
computed
} from '#imports'
import { submitForm } from '@formkit/vue'
import { useDebounceFn } from '@vueuse/core'
import useTideSearch from './../composables/useTideSearch'
import type { TidePageBase, TideSiteData } from '@dpc-sdp/ripple-tide-api/types'
import type {
Expand Down Expand Up @@ -267,7 +268,10 @@ const handleFilterReset = (event: rplEventPayload) => {

const handleUpdateSearchTerm = (term: string) => {
searchTerm.value.q = term
getDebouncedSuggestions(term)
}

const getDebouncedSuggestions = useDebounceFn((term: string) => {
if (
props.autocompleteQuery &&
props.searchListingConfig?.suggestions?.enabled !== false
Expand All @@ -278,7 +282,7 @@ const handleUpdateSearchTerm = (term: string) => {
clearSuggestions()
}
}
}
}, 300)

const handleUpdateSearch = (term: string | Record<string, any>) => {
if (term && typeof term === 'object') {
Expand Down Expand Up @@ -404,6 +408,7 @@ watch(
:placeholder="searchListingConfig?.labels?.placeholder"
:suggestions="suggestions"
:global-events="false"
:maxlength="128"
@submit="handleSearchSubmit"
@update:input-value="handleUpdateSearchTerm"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ref
} from '#imports'
import { submitForm } from '@formkit/vue'
import { useDebounceFn } from '@vueuse/core'
import useTideSearch from './../../composables/useTideSearch'
import type {
TideSearchListingResultItem,
Expand Down Expand Up @@ -364,14 +365,17 @@ const handleFilterReset = (event: rplEventPayload) => {

const handleUpdateSearchTerm = (term: string) => {
searchTerm.value.q = term
getDebouncedSuggestions()
}

const getDebouncedSuggestions = useDebounceFn(() => {
if (
props.autocompleteQuery &&
props.searchListingConfig?.suggestions?.enabled !== false
) {
getSuggestions()
}
}
}, 300)

const handleUpdateSearch = (term: string | Record<string, any>) => {
if (term && typeof term === 'object') {
Expand Down Expand Up @@ -564,6 +568,7 @@ const locationOrGeolocation = computed(() => {
:inputValue="searchTerm.q"
:placeholder="searchListingConfig.labels?.placeholder"
:global-events="false"
:maxlength="128"
@submit="handleSearchSubmit"
@update:input-value="handleUpdateSearchTerm"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"
:suggestions="results"
:showNoResults="true"
:debounce="5000"
:maxSuggestionsDisplayed="8"
:placeholder="placeholder"
:getOptionId="(itm:any) => itm?.id || itm?.name"
Expand Down
Loading