@@ -7,16 +7,23 @@ import * as ncEventBus from '@nextcloud/event-bus'
77import { Folder } from '@nextcloud/files'
88import isSvg from 'is-svg'
99import { beforeEach , describe , expect , it , vi } from 'vitest'
10- import { PERMISSION_ALL , PERMISSION_NONE } from '../../../../core/src/OC/constants.js'
1110import { trashbinView } from '../files_views/trashbinView.ts'
1211import { restoreAction } from './restoreAction.ts'
1312
13+ // TODO: once core is migrated to the new frontend use the import instead:
14+ // import { PERMISSION_ALL, PERMISSION_NONE } from '../../../../core/src/OC/constants.js'
15+ export const PERMISSION_NONE = 0
16+ export const PERMISSION_ALL = 31
17+
1418const axiosMock = vi . hoisted ( ( ) => ( {
1519 request : vi . fn ( ) ,
1620} ) )
17- vi . mock ( '@nextcloud/axios' , ( ) => ( { default : axiosMock } ) )
21+ vi . mock ( '@nextcloud/axios' , async ( origial ) => ( { ... ( await origial ( ) ) , default : axiosMock } ) )
1822vi . mock ( '@nextcloud/auth' )
1923
24+ const errorSpy = vi . spyOn ( window . console , 'error' ) . mockImplementation ( ( ) => { } )
25+ beforeEach ( ( ) => errorSpy . mockClear ( ) )
26+
2027describe ( 'files_trashbin: file actions - restore action' , ( ) => {
2128 it ( 'has id set' , ( ) => {
2229 expect ( restoreAction . id ) . toBe ( 'restore' )
@@ -99,9 +106,9 @@ describe('files_trashbin: file actions - restore action', () => {
99106
100107 expect ( await restoreAction . exec ( node , trashbinView , '/' ) ) . toBe ( true )
101108 expect ( axiosMock . request ) . toBeCalled ( )
102- expect ( axiosMock . request . mock . calls [ 0 ] [ 0 ] . method ) . toBe ( 'MOVE' )
103- expect ( axiosMock . request . mock . calls [ 0 ] [ 0 ] . url ) . toBe ( node . encodedSource )
104- expect ( axiosMock . request . mock . calls [ 0 ] [ 0 ] . headers . destination ) . toContain ( '/restore/' )
109+ expect ( axiosMock . request . mock . calls [ 0 ] ! [ 0 ] . method ) . toBe ( 'MOVE' )
110+ expect ( axiosMock . request . mock . calls [ 0 ] ! [ 0 ] . url ) . toBe ( node . encodedSource )
111+ expect ( axiosMock . request . mock . calls [ 0 ] ! [ 0 ] . headers . destination ) . toContain ( '/restore/' )
105112 } )
106113
107114 it ( 'deletes node from current view after successfull request' , async ( ) => {
@@ -115,7 +122,7 @@ describe('files_trashbin: file actions - restore action', () => {
115122 expect ( emitSpy ) . toBeCalledWith ( 'files:node:deleted' , node )
116123 } )
117124
118- it ( 'does not delete node from view if reuest failed' , async ( ) => {
125+ it ( 'does not delete node from view if request failed' , async ( ) => {
119126 const node = new Folder ( { owner : 'test' , source : 'https://example.com/remote.php/dav/trashbin/test/folder' , root : '/trashbin/test/' , permissions : PERMISSION_ALL } )
120127
121128 axiosMock . request . mockImplementationOnce ( ( ) => {
@@ -126,6 +133,7 @@ describe('files_trashbin: file actions - restore action', () => {
126133 expect ( await restoreAction . exec ( node , trashbinView , '/' ) ) . toBe ( false )
127134 expect ( axiosMock . request ) . toBeCalled ( )
128135 expect ( emitSpy ) . not . toBeCalled ( )
136+ expect ( errorSpy ) . toBeCalled ( )
129137 } )
130138
131139 it ( 'batch: only returns success if all requests worked' , async ( ) => {
@@ -143,6 +151,7 @@ describe('files_trashbin: file actions - restore action', () => {
143151 } )
144152 expect ( await restoreAction . execBatch ! ( [ node , node ] , trashbinView , '/' ) ) . toStrictEqual ( [ false , true ] )
145153 expect ( axiosMock . request ) . toBeCalledTimes ( 2 )
154+ expect ( errorSpy ) . toBeCalled ( )
146155 } )
147156 } )
148157} )
0 commit comments