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

fix: change search scope without search term #11997

Merged
merged 1 commit into from
Dec 4, 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
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