66import * as ncDialogs from '@nextcloud/dialogs'
77import * as ncEventBus from '@nextcloud/event-bus'
88import { Folder } from '@nextcloud/files'
9- import * as ncInitialState from '@nextcloud/initial-state'
109import { beforeEach , describe , expect , it , vi } from 'vitest'
1110import { trashbinView } from '../files_views/trashbinView.ts'
1211import * as api from '../services/api.ts'
1312import { emptyTrashAction } from './emptyTrashAction.ts'
1413
14+ const loadState = vi . hoisted ( ( ) => vi . fn ( ( app , key , fallback ) => {
15+ if ( fallback ) {
16+ return fallback
17+ }
18+ throw new Error ( )
19+ } ) )
20+
21+ vi . mock ( '@nextcloud/initial-state' , ( ) => ( {
22+ loadState,
23+ } ) )
24+
25+ beforeEach ( ( ) => vi . resetAllMocks ( ) )
26+
1527describe ( 'files_trashbin: file list actions - empty trashbin' , ( ) => {
1628 it ( 'has id set' , ( ) => {
1729 expect ( emptyTrashAction . id ) . toBe ( 'empty-trash' )
@@ -27,7 +39,7 @@ describe('files_trashbin: file list actions - empty trashbin', () => {
2739 } )
2840
2941 it ( 'is enabled on trashbin view' , ( ) => {
30- const spy = vi . spyOn ( ncInitialState , ' loadState' ) . mockImplementationOnce ( ( ) => ( { allow_delete : true } ) )
42+ loadState . mockImplementation ( ( ) => ( { allow_delete : true } ) )
3143
3244 const root = new Folder ( { owner : 'test' , source : 'https://example.com/remote.php/dav/trashbin/test/' , root : '/trashbin/test/' } )
3345 const nodes = [
@@ -36,12 +48,12 @@ describe('files_trashbin: file list actions - empty trashbin', () => {
3648
3749 expect ( emptyTrashAction . enabled ) . toBeTypeOf ( 'function' )
3850 expect ( emptyTrashAction . enabled ! ( trashbinView , nodes , root ) ) . toBe ( true )
39- expect ( spy ) . toHaveBeenCalled ( )
40- expect ( spy ) . toHaveBeenCalledWith ( 'files_trashbin' , 'config' )
51+ expect ( loadState ) . toHaveBeenCalled ( )
52+ expect ( loadState ) . toHaveBeenCalledWith ( 'files_trashbin' , 'config' )
4153 } )
4254
4355 it ( 'is not enabled on another view enabled' , ( ) => {
44- vi . spyOn ( ncInitialState , ' loadState' ) . mockImplementationOnce ( ( ) => ( { allow_delete : true } ) )
56+ loadState . mockImplementation ( ( ) => ( { allow_delete : true } ) )
4557
4658 const root = new Folder ( { owner : 'test' , source : 'https://example.com/remote.php/dav/trashbin/test/' , root : '/trashbin/test/' } )
4759 const nodes = [
@@ -62,7 +74,7 @@ describe('files_trashbin: file list actions - empty trashbin', () => {
6274 } )
6375
6476 it ( 'is not enabled when deletion is forbidden' , ( ) => {
65- const spy = vi . spyOn ( ncInitialState , ' loadState' ) . mockImplementationOnce ( ( ) => ( { allow_delete : false } ) )
77+ loadState . mockImplementation ( ( ) => ( { allow_delete : false } ) )
6678
6779 const root = new Folder ( { owner : 'test' , source : 'https://example.com/remote.php/dav/trashbin/test/' , root : '/trashbin/test/' } )
6880 const nodes = [
@@ -71,13 +83,12 @@ describe('files_trashbin: file list actions - empty trashbin', () => {
7183
7284 expect ( emptyTrashAction . enabled ) . toBeTypeOf ( 'function' )
7385 expect ( emptyTrashAction . enabled ! ( trashbinView , nodes , root ) ) . toBe ( false )
74- expect ( spy ) . toHaveBeenCalled ( )
75- expect ( spy ) . toHaveBeenCalledWith ( 'files_trashbin' , 'config' )
86+ expect ( loadState ) . toHaveBeenCalled ( )
87+ expect ( loadState ) . toHaveBeenCalledWith ( 'files_trashbin' , 'config' )
7688 } )
7789
7890 it ( 'is not enabled when not in trashbin root' , ( ) => {
79- vi . spyOn ( ncInitialState , 'loadState' ) . mockImplementationOnce ( ( ) => ( { allow_delete : true } ) )
80-
91+ loadState . mockImplementation ( ( ) => ( { allow_delete : true } ) )
8192 const root = new Folder ( { owner : 'test' , source : 'https://example.com/remote.php/dav/trashbin/test/other-folder' , root : '/trashbin/test/' } )
8293 const nodes = [
8394 new Folder ( { owner : 'test' , source : 'https://example.com/remote.php/dav/trashbin/test/folder' , root : '/trashbin/test/' } ) ,
@@ -101,6 +112,7 @@ describe('files_trashbin: file list actions - empty trashbin', () => {
101112 }
102113
103114 beforeEach ( ( ) => {
115+ vi . resetAllMocks ( )
104116 dialogBuilder = {
105117 setSeverity : vi . fn ( ( ) => dialogBuilder ) ,
106118 setText : vi . fn ( ( ) => dialogBuilder ) ,
0 commit comments