Skip to content

Commit

Permalink
test(dav): Update tests
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 453a22d commit 5e64a5d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/composables/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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'
Expand All @@ -44,6 +45,14 @@ const waitLoaded = (vue: ReturnType<typeof shallowMount>) => new Promise((resolv
w()
})

const waitRefLoaded = (isLoading: Ref<boolean>) => new Promise((resolve) => {
const w = () => {
if (isLoading.value) window.setTimeout(w, 50)
else resolve(true)
}
w()
})

const TestComponent = defineComponent({
props: ['currentView', 'currentPath', 'isPublic'],
setup(props) {
Expand Down Expand Up @@ -209,16 +218,14 @@ describe('dav composable', () => {
expect(isLoading.value).toBe(true)
await loadFiles()
expect(isLoading.value).toBe(false)
expect(client.getDirectoryContents).toBeCalledWith(`${nextcloudFiles.davRootPath}/`, { details: true })
expect(client.getDirectoryContents).toBeCalledWith(`${nextcloudFiles.davRootPath}/`, expect.objectContaining({ details: true }))

view.value = 'recent'
await loadFiles()
expect(isLoading.value).toBe(false)
expect(client.search).toBeCalled()
await waitRefLoaded(isLoading)
expect(client.search).toBeCalledWith('/', expect.objectContaining({ details: true }))

view.value = 'favorites'
await loadFiles()
expect(isLoading.value).toBe(false)
await waitRefLoaded(isLoading)
expect(nextcloudFiles.getFavoriteNodes).toBeCalled()
})
})

0 comments on commit 5e64a5d

Please sign in to comment.