2026-07-07 10:37:00 +02:00
|
|
|
import CreateShortcutModal from '../../../src/components/CreateShortcutModal.vue'
|
|
|
|
|
import {
|
|
|
|
|
defaultComponentMocks,
|
|
|
|
|
defaultPlugins,
|
2026-09-15 06:23:31 +02:00
|
|
|
mockHttpError,
|
2026-07-07 10:37:00 +02:00
|
|
|
RouteLocation,
|
|
|
|
|
shallowMount
|
2026-10-02 08:13:31 +02:00
|
|
|
} from '../../../src/testing'
|
2026-07-07 10:37:00 +02:00
|
|
|
import { SpaceResource } from '@ownclouders/web-client'
|
|
|
|
|
import { mock } from 'vitest-mock-extended'
|
|
|
|
|
import { FileResource } from '@ownclouders/web-client'
|
|
|
|
|
import { SearchResource } from '@ownclouders/web-client'
|
|
|
|
|
import { useMessages, useResourcesStore } from '../../../src/composables/piniaStores'
|
|
|
|
|
|
|
|
|
|
describe('CreateShortcutModal', () => {
|
|
|
|
|
describe('method "onConfirm"', () => {
|
|
|
|
|
it('should show message on success', async () => {
|
|
|
|
|
const { wrapper } = getWrapper()
|
|
|
|
|
await wrapper.vm.onConfirm()
|
|
|
|
|
|
|
|
|
|
const { upsertResource } = useResourcesStore()
|
|
|
|
|
expect(upsertResource).toHaveBeenCalled()
|
|
|
|
|
const { showMessage } = useMessages()
|
|
|
|
|
expect(showMessage).toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
it('should show error message on fail', async () => {
|
|
|
|
|
console.error = vi.fn()
|
|
|
|
|
const { wrapper } = getWrapper({ rejectPutFileContents: true })
|
|
|
|
|
await wrapper.vm.onConfirm()
|
|
|
|
|
|
|
|
|
|
const { upsertResource } = useResourcesStore()
|
|
|
|
|
expect(upsertResource).not.toHaveBeenCalled()
|
|
|
|
|
const { showErrorMessage } = useMessages()
|
|
|
|
|
expect(showErrorMessage).toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
describe('method "searchTask"', () => {
|
|
|
|
|
it('should set "searchResult" correctly', async () => {
|
|
|
|
|
const { wrapper } = getWrapper()
|
|
|
|
|
await (wrapper.vm as any).searchTask.perform('new file')
|
|
|
|
|
expect((wrapper.vm as any).searchResult.values.length).toBe(3)
|
|
|
|
|
})
|
|
|
|
|
it('should reset "searchResult" on error', async () => {
|
|
|
|
|
console.error = vi.fn()
|
|
|
|
|
const { wrapper } = getWrapper({ rejectSearch: true })
|
|
|
|
|
await (wrapper.vm as any).searchTask.perform('new folder')
|
|
|
|
|
expect((wrapper.vm as any).searchResult).toBe(null)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function getWrapper({ rejectPutFileContents = false, rejectSearch = false } = {}) {
|
|
|
|
|
const mocks = {
|
|
|
|
|
...defaultComponentMocks({
|
|
|
|
|
currentRoute: mock<RouteLocation>({ name: 'files-spaces-generic' })
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rejectPutFileContents) {
|
2026-09-15 06:23:31 +02:00
|
|
|
mocks.$clientService.webdav.putFileContents.mockRejectedValue(() => mockHttpError())
|
2026-07-07 10:37:00 +02:00
|
|
|
} else {
|
|
|
|
|
mocks.$clientService.webdav.putFileContents.mockResolvedValue(mock<FileResource>())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rejectSearch) {
|
2026-09-15 06:23:31 +02:00
|
|
|
mocks.$clientService.webdav.search.mockRejectedValue(() => mockHttpError())
|
2026-07-07 10:37:00 +02:00
|
|
|
} else {
|
|
|
|
|
mocks.$clientService.webdav.search.mockResolvedValue({
|
|
|
|
|
resources: [
|
|
|
|
|
mock<SearchResource>({ name: 'New File' }),
|
|
|
|
|
mock<SearchResource>({ name: 'New File (1)' }),
|
|
|
|
|
mock<SearchResource>({ name: 'New Folder' })
|
|
|
|
|
],
|
|
|
|
|
totalResults: 3
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
mocks,
|
|
|
|
|
wrapper: shallowMount(CreateShortcutModal, {
|
|
|
|
|
props: {
|
|
|
|
|
space: mock<SpaceResource>(),
|
|
|
|
|
modal: undefined
|
|
|
|
|
},
|
|
|
|
|
global: {
|
|
|
|
|
plugins: [
|
|
|
|
|
...defaultPlugins({
|
|
|
|
|
piniaOptions: { resourcesStore: { currentFolder: mock<FileResource>() } }
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
mocks,
|
|
|
|
|
provide: mocks
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|