|
23 | 23 | import type { Ref } from 'vue'
|
24 | 24 | import { describe, it, expect, vi, afterEach } from 'vitest'
|
25 | 25 | import { shallowMount } from '@vue/test-utils'
|
26 |
| -import { defineComponent, ref, toRef } from 'vue' |
| 26 | +import { defineComponent, ref, toRef, nextTick } from 'vue' |
27 | 27 | import { useDAVFiles } from './dav'
|
28 | 28 |
|
29 | 29 | const nextcloudFiles = vi.hoisted(() => ({
|
@@ -228,4 +228,33 @@ describe('dav composable', () => {
|
228 | 228 | await waitRefLoaded(isLoading)
|
229 | 229 | expect(nextcloudFiles.getFavoriteNodes).toBeCalled()
|
230 | 230 | })
|
| 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 | + }) |
231 | 260 | })
|
0 commit comments