Skip to content

Commit

Permalink
test(dav): Add test for request cancelation
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Apr 15, 2024
1 parent 5e64a5d commit 00ed78e
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/composables/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import type { Ref } from 'vue'
import { describe, it, expect, vi, afterEach } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import { defineComponent, ref, toRef } from 'vue'
import { defineComponent, ref, toRef, nextTick } from 'vue'
import { useDAVFiles } from './dav'

const nextcloudFiles = vi.hoisted(() => ({
Expand Down Expand Up @@ -228,4 +228,33 @@ describe('dav composable', () => {
await waitRefLoaded(isLoading)
expect(nextcloudFiles.getFavoriteNodes).toBeCalled()
})

it('request cancelation works', async () => {
const client = {
stat: vi.fn((v) => ({ data: { path: v } })),
getDirectoryContents: vi.fn((p, o) => ({ data: [] })),
search: vi.fn((p, o) => ({ data: { results: [], truncated: false } })),
}
nextcloudFiles.davGetClient.mockImplementationOnce(() => client)
nextcloudFiles.davResultToNode.mockImplementationOnce((v) => v)

const view = ref<'files' | 'recent' | 'favorites'>('files')
const path = ref('/')
const { loadFiles, isLoading } = useDAVFiles(view, path, ref(false))

const abort = vi.spyOn(AbortController.prototype, 'abort')

loadFiles()
view.value = 'recent'
await waitRefLoaded(isLoading)
expect(abort).toBeCalledTimes(1)

view.value = 'files'
await nextTick()
view.value = 'recent'
await nextTick()
view.value = 'favorites'
await waitRefLoaded(isLoading)
expect(abort).toBeCalledTimes(2)
})
})

0 comments on commit 00ed78e

Please sign in to comment.