diff --git a/examples/nuxt-app/test/features/search-listing/filters.feature b/examples/nuxt-app/test/features/search-listing/filters.feature index e114d0718f..d86406479a 100644 --- a/examples/nuxt-app/test/features/search-listing/filters.feature +++ b/examples/nuxt-app/test/features/search-listing/filters.feature @@ -141,7 +141,7 @@ Feature: Search listing - Filter When I clear the search filters And the search network request should be called with the "/search-listing/filters/request-clear-empty" fixture - Then the URL should reflect that the current page number is 1 + Then the URL should reflect that the current page has been reset Then the URL should reflect that the current search term is "" Then the URL should reflect that the current active filters are as follows: | id | diff --git a/examples/nuxt-app/test/features/search-listing/pagination.feature b/examples/nuxt-app/test/features/search-listing/pagination.feature index 82fa2da687..710dda2d33 100644 --- a/examples/nuxt-app/test/features/search-listing/pagination.feature +++ b/examples/nuxt-app/test/features/search-listing/pagination.feature @@ -83,7 +83,7 @@ Feature: Searching listing - Pagination When I click the search button Given I wait 1 seconds Then the search network request should be called with the "/search-listing/pagination/request-page-1-with-term" fixture - And the URL should reflect that the current page number is 1 + And the URL should reflect that the current page has been reset And the results counter should show 1 to 4 of 10 results And the search listing results should have following items: | title | diff --git a/packages/ripple-test-utils/step_definitions/content-types/listing.ts b/packages/ripple-test-utils/step_definitions/content-types/listing.ts index 3579570e33..ebea4a4df9 100644 --- a/packages/ripple-test-utils/step_definitions/content-types/listing.ts +++ b/packages/ripple-test-utils/step_definitions/content-types/listing.ts @@ -36,6 +36,13 @@ Then( } ) +Then('the URL should reflect that the current page has been reset', () => { + cy.location().should((loc) => { + const params = new URLSearchParams(loc.search) + expect(params.get('page')).to.eq(null) + }) +}) + Then( 'the URL should reflect that the current sort option is {string}', (sortId: string) => { diff --git a/packages/ripple-tide-search/composables/useTideSearch.ts b/packages/ripple-tide-search/composables/useTideSearch.ts index 1270ccc9c9..6e456420d0 100644 --- a/packages/ripple-tide-search/composables/useTideSearch.ts +++ b/packages/ripple-tide-search/composables/useTideSearch.ts @@ -78,9 +78,8 @@ export default ({ return JSON.parse(JSON.stringify(obj).replace(re, escapedValue)) } - const activeTab: TideSearchListingTabKey = ref( - searchListingConfig?.displayMapTab ? 'map' : null - ) + const initialTab = searchListingConfig?.displayMapTab ? 'map' : null + const activeTab: TideSearchListingTabKey = ref(initialTab) const isBusy = ref(true) const searchError = ref(null) @@ -564,9 +563,8 @@ export default ({ await navigateTo({ path: route.path, query: { - page: 1, q: searchTerm.value || undefined, - activeTab: activeTab.value, + activeTab: activeTab.value !== initialTab ? activeTab.value : undefined, ...locationParams, ...filterFormValues } @@ -581,7 +579,7 @@ export default ({ ...route, query: { ...route.query, - page: newPage + page: newPage > 1 ? newPage : undefined } }) } @@ -602,7 +600,7 @@ export default ({ ...route, query: { ...route.query, - activeTab: newActiveTab + activeTab: newActiveTab !== initialTab ? newActiveTab : undefined } }) }