From 5e64a5d84f9ca2541f2e1f47b3309b3735915105 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 15 Apr 2024 15:38:43 -0700 Subject: [PATCH] test(dav): Update tests Signed-off-by: Christopher Ng --- lib/composables/dav.spec.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/composables/dav.spec.ts b/lib/composables/dav.spec.ts index 2f755b8d..8be7af86 100644 --- a/lib/composables/dav.spec.ts +++ b/lib/composables/dav.spec.ts @@ -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' @@ -44,6 +45,14 @@ const waitLoaded = (vue: ReturnType) => new Promise((resolv w() }) +const waitRefLoaded = (isLoading: Ref) => 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) { @@ -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() }) })