Skip to content
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
11 changes: 9 additions & 2 deletions packages/web-app-files/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const extensions = (appInfo: ApplicationInformation) => {
const { currentFolder } = storeToRefs(useResourcesStore())
const { currentSpace } = storeToRefs(useSpacesStore())
const router = useRouter()
const { search: searchFunction } = useSearch()
// preview and list search need their own (restartable) tasks, so that one doesn't cancel the other
const { search: previewSearchFunction } = useSearch()
const { search: listSearchFunction } = useSearch()
const { $gettext } = useGettext()
const { can } = useAbility()

Expand All @@ -51,7 +53,12 @@ export const extensions = (appInfo: ApplicationInformation) => {
const folderViewExtensions = useFolderViews()
const sideBarPanelExtensions = useSideBarPanels()
const vaultIndicator = useVaultIndicator()
const searchProvider = new SDKSearch(capabilityStore, searchFunction, configStore)
const searchProvider = new SDKSearch(
capabilityStore,
previewSearchFunction,
configStore,
listSearchFunction
)

return computed<Extension[]>(() => [
...fileActionExtensions,
Expand Down
5 changes: 3 additions & 2 deletions packages/web-app-files/src/search/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ export default class Provider implements SearchProvider {
constructor(
capabilityStore: CapabilityStore,
searchFunction: SearchFunction,
configStore: ConfigStore
configStore: ConfigStore,
listSearchFunction: SearchFunction = searchFunction
) {
this.id = 'files.sdk'
this.displayName = $gettext('Files')
this.previewSearch = new Preview(searchFunction, configStore)
this.listSearch = new List(searchFunction)
this.listSearch = new List(listSearchFunction)
this.capabilityStore = capabilityStore
}

Expand Down
36 changes: 36 additions & 0 deletions packages/web-app-files/tests/unit/extensions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { mock } from 'vitest-mock-extended'
import { unref } from 'vue'
import { ApplicationInformation, SearchExtension } from '@opencloud-eu/web-pkg'
import { SearchResource } from '@opencloud-eu/web-client'
import { defaultComponentMocks, getComposableWrapper } from '@opencloud-eu/web-test-helpers'
import { extensions } from '../../src/extensions'

describe('files app extensions', () => {
describe('search provider', () => {
it('does not cancel a running list search when a preview search starts', async () => {
const mocks = defaultComponentMocks()
const listResources = [mock<SearchResource>({ id: '1', name: 'foo' })]
let resolveListRequest: (value: { resources: SearchResource[]; totalResults: number }) => void
mocks.$clientService.webdav.search
.mockImplementationOnce(() => new Promise((resolve) => (resolveListRequest = resolve)))
.mockResolvedValue({ resources: [], totalResults: 0 })

const wrapper = getComposableWrapper(
() => {
const searchExtension = unref(extensions(mock<ApplicationInformation>())).find(
({ type }) => type === 'search'
) as SearchExtension
return { searchProvider: searchExtension.searchProvider }
},
{ mocks, provide: mocks }
)
const { listSearch, previewSearch } = wrapper.vm.searchProvider

const listResult = listSearch.search('foo')
await previewSearch.search('foo')
resolveListRequest({ resources: listResources, totalResults: 1 })

await expect(listResult).resolves.toMatchObject({ totalResults: 1 })
})
})
})
Loading