Skip to content

Commit

Permalink
fix: change search scope without search term
Browse files Browse the repository at this point in the history
Change search scope when there is no search term and the search page is active.
  • Loading branch information
LukasHirt committed Dec 4, 2024
1 parent e3087bb commit 75ca662
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-change-search-scope-without-term
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Change search scope without search term

We've fixed the change of search scope on search page when there is no search term entered.

https://github.com/owncloud/web/pull/11997
https://github.com/owncloud/web/issues/11982
7 changes: 4 additions & 3 deletions packages/web-app-search/src/portals/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<template #locationFilter>
<search-bar-filter
v-if="locationFilterAvailable"
id="files-global-search-filter"
:current-folder-available="currentFolderAvailable"
@update:model-value="onLocationFilterChange"
/>
Expand Down Expand Up @@ -271,12 +272,12 @@ export default defineComponent({
const onLocationFilterChange = (event: { value: { id: string } }) => {
locationFilterId.value = event.value.id
if (!unref(term)) {
if (isLocationCommonActive(router, 'files-common-search')) {
onKeyUpEnter()
return
}
if (isLocationCommonActive(router, 'files-common-search')) {
onKeyUpEnter()
if (!unref(term)) {
return
}
search()
Expand Down
45 changes: 41 additions & 4 deletions packages/web-app-search/tests/unit/portals/SearchBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
nextTicks
} from '@ownclouders/web-test-helpers'
import { useAvailableProviders } from '../../../src/composables'
import { SearchBarFilter, SearchLocationFilterConstants } from '@ownclouders/web-pkg'

const component = defineComponent({
emits: ['click', 'keyup'],
Expand Down Expand Up @@ -55,7 +56,8 @@ const selectors = {
providerDisplayName: '.provider .display-name',
providerMoreResultsLink: '.provider .more-results',
optionsHidden: '.tippy-box[data-state="hidden"]',
optionsVisible: '.tippy-box[data-state="visible"]'
optionsVisible: '.tippy-box[data-state="visible"]',
searchFilters: '#files-global-search-filter'
}

vi.mock('lodash-es', () => ({ debounce: (fn: unknown) => fn }))
Expand Down Expand Up @@ -222,17 +224,52 @@ describe('Search Bar portal component', () => {
wrapper.find(selectors.searchInput).trigger('keyup.enter')
expect(spyRouterPushStub).not.toHaveBeenCalled()
})
test('executes search if term is empty but route is common search', async () => {
wrapper = getMountedWrapper({
route: 'files-common-search',
store: { resourcesStore: { currentFolder: { fileId: 'root-dir' } } }
}).wrapper
wrapper
.findComponent<typeof SearchBarFilter>(selectors.searchFilters)
.vm.$emit('update:model-value', {
value: { id: SearchLocationFilterConstants.currentFolder }
})

const spyRouterPushStub = wrapper.vm.$router.push
expect(spyRouterPushStub).toHaveBeenCalledWith({
name: 'files-common-search',
query: expect.objectContaining({
term: '',
provider: 'files.sdk',
useScope: 'true',
scope: 'root-dir'
})
})
})
test('does not execute search if term is empty and route is not common search', async () => {
const { wrapper } = getMountedWrapper()
wrapper
.findComponent<typeof SearchBarFilter>(selectors.searchFilters)
.vm.$emit('update:model-value', {
value: { id: SearchLocationFilterConstants.currentFolder }
})

const spyRouterPushStub = wrapper.vm.$router.push
expect(spyRouterPushStub).not.toHaveBeenCalled()
})
})

function getMountedWrapper({
mocks = {},
userContextReady = true,
providers = [providerFiles, providerContacts]
providers = [providerFiles, providerContacts],
route = 'files-spaces-generic',
store = {}
} = {}) {
vi.mocked(useAvailableProviders).mockReturnValue(ref(providers))

const currentRoute = mock<RouteLocation>({
name: 'files-spaces-generic',
name: route,
query: {
term: '',
provider: ''
Expand All @@ -249,7 +286,7 @@ function getMountedWrapper({
global: {
plugins: [
...defaultPlugins({
piniaOptions: { authState: { userContextReady: userContextReady } }
piniaOptions: { authState: { userContextReady: userContextReady }, ...store }
})
],
mocks: localMocks,
Expand Down

0 comments on commit 75ca662

Please sign in to comment.