33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import type { Ref } from 'vue'
6+ import type { ComponentPublicInstance , Ref } from 'vue'
77import { describe , it , expect , vi , beforeEach } from 'vitest'
88import { shallowMount } from '@vue/test-utils'
99import { defineComponent , ref , toRef , nextTick , h } from 'vue'
@@ -20,9 +20,10 @@ const nextcloudFiles = vi.hoisted(() => ({
2020} ) )
2121vi . mock ( '@nextcloud/files' , ( ) => nextcloudFiles )
2222
23- const waitLoaded = ( vue : ReturnType < typeof shallowMount > ) => new Promise ( ( resolve ) => {
23+ // eslint-disable-next-line @typescript-eslint/ban-types
24+ const waitLoaded = ( vm : ComponentPublicInstance < { } , { isLoading : boolean } > ) => new Promise ( ( resolve ) => {
2425 const w = ( ) => {
25- if ( vue . vm . isLoading ) window . setTimeout ( w , 50 )
26+ if ( vm . isLoading ) window . setTimeout ( w , 50 )
2627 else resolve ( true )
2728 }
2829 w ( )
@@ -90,14 +91,15 @@ describe('dav composable', () => {
9091 } )
9192
9293 // wait until files are loaded
93- await waitLoaded ( vue )
94+ await waitLoaded ( vue . vm )
9495
9596 expect ( vue . vm . files ) . toEqual ( [ 'node 1' , 'node 2' ] )
9697 } )
9798
9899 it ( 'reloads on path change' , async ( ) => {
99100 const client = {
100- getDirectoryContents : vi . fn ( ( ) => ( { data : [ ] } ) ) ,
101+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
102+ getDirectoryContents : vi . fn ( ( _path : string ) => ( { data : [ ] } ) ) ,
101103 }
102104 nextcloudFiles . davGetClient . mockImplementationOnce ( ( ) => client )
103105
@@ -110,21 +112,22 @@ describe('dav composable', () => {
110112 } )
111113
112114 // wait until files are loaded
113- await waitLoaded ( vue )
115+ await waitLoaded ( vue . vm )
114116
115117 expect ( client . getDirectoryContents ) . toBeCalledTimes ( 1 )
116118 expect ( client . getDirectoryContents . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ nextcloudFiles . davRootPath } /` )
117119
118120 vue . setProps ( { currentPath : '/other' } )
119- await waitLoaded ( vue )
121+ await waitLoaded ( vue . vm )
120122
121123 expect ( client . getDirectoryContents ) . toBeCalledTimes ( 2 )
122124 expect ( client . getDirectoryContents . mock . calls [ 1 ] [ 0 ] ) . toBe ( `${ nextcloudFiles . davRootPath } /other` )
123125 } )
124126
125127 it ( 'reloads on view change' , async ( ) => {
126128 const client = {
127- getDirectoryContents : vi . fn ( ( ) => ( { data : [ ] } ) ) ,
129+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
130+ getDirectoryContents : vi . fn ( ( _path : string ) => ( { data : [ ] } ) ) ,
128131 search : vi . fn ( ( ) => ( { data : { results : [ ] , truncated : false } } ) ) ,
129132 }
130133 nextcloudFiles . davGetClient . mockImplementationOnce ( ( ) => client )
@@ -138,14 +141,14 @@ describe('dav composable', () => {
138141 } )
139142
140143 // wait until files are loaded
141- await waitLoaded ( vue )
144+ await waitLoaded ( vue . vm )
142145
143146 expect ( client . search ) . not . toBeCalled ( )
144147 expect ( client . getDirectoryContents ) . toBeCalledTimes ( 1 )
145148 expect ( client . getDirectoryContents . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ nextcloudFiles . davRootPath } /` )
146149
147150 vue . setProps ( { currentView : 'recent' } )
148- await waitLoaded ( vue )
151+ await waitLoaded ( vue . vm )
149152
150153 // Uses search instead of getDirectoryContents
151154 expect ( client . getDirectoryContents ) . toBeCalledTimes ( 1 )
0 commit comments