Skip to content

Commit 00ed78e

Browse files
committed
test(dav): Add test for request cancelation
Signed-off-by: Christopher Ng <[email protected]>
1 parent 5e64a5d commit 00ed78e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/composables/dav.spec.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import type { Ref } from 'vue'
2424
import { describe, it, expect, vi, afterEach } from 'vitest'
2525
import { shallowMount } from '@vue/test-utils'
26-
import { defineComponent, ref, toRef } from 'vue'
26+
import { defineComponent, ref, toRef, nextTick } from 'vue'
2727
import { useDAVFiles } from './dav'
2828

2929
const nextcloudFiles = vi.hoisted(() => ({
@@ -228,4 +228,33 @@ describe('dav composable', () => {
228228
await waitRefLoaded(isLoading)
229229
expect(nextcloudFiles.getFavoriteNodes).toBeCalled()
230230
})
231+
232+
it('request cancelation works', async () => {
233+
const client = {
234+
stat: vi.fn((v) => ({ data: { path: v } })),
235+
getDirectoryContents: vi.fn((p, o) => ({ data: [] })),
236+
search: vi.fn((p, o) => ({ data: { results: [], truncated: false } })),
237+
}
238+
nextcloudFiles.davGetClient.mockImplementationOnce(() => client)
239+
nextcloudFiles.davResultToNode.mockImplementationOnce((v) => v)
240+
241+
const view = ref<'files' | 'recent' | 'favorites'>('files')
242+
const path = ref('/')
243+
const { loadFiles, isLoading } = useDAVFiles(view, path, ref(false))
244+
245+
const abort = vi.spyOn(AbortController.prototype, 'abort')
246+
247+
loadFiles()
248+
view.value = 'recent'
249+
await waitRefLoaded(isLoading)
250+
expect(abort).toBeCalledTimes(1)
251+
252+
view.value = 'files'
253+
await nextTick()
254+
view.value = 'recent'
255+
await nextTick()
256+
view.value = 'favorites'
257+
await waitRefLoaded(isLoading)
258+
expect(abort).toBeCalledTimes(2)
259+
})
231260
})

0 commit comments

Comments
 (0)