2222import { action } from './deleteAction'
2323import { expect } from '@jest/globals'
2424import { File , Folder , Permission , View , FileAction } from '@nextcloud/files'
25+ import * as auth from '@nextcloud/auth'
2526import * as eventBus from '@nextcloud/event-bus'
2627import axios from '@nextcloud/axios'
2728import logger from '../logger'
@@ -37,26 +38,55 @@ const trashbinView = {
3738} as View
3839
3940describe ( 'Delete action conditions tests' , ( ) => {
41+ afterEach ( ( ) => {
42+ jest . restoreAllMocks ( )
43+ } )
44+
45+ const file = new File ( {
46+ id : 1 ,
47+ source : 'https://cloud.domain.com/remote.php/dav/files/test/foobar.txt' ,
48+ owner : 'test' ,
49+ mime : 'text/plain' ,
50+ permissions : Permission . ALL ,
51+ } )
52+
53+ const file2 = new File ( {
54+ id : 1 ,
55+ source : 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt' ,
56+ owner : 'admin' ,
57+ mime : 'text/plain' ,
58+ permissions : Permission . ALL ,
59+ } )
60+
4061 test ( 'Default values' , ( ) => {
4162 expect ( action ) . toBeInstanceOf ( FileAction )
4263 expect ( action . id ) . toBe ( 'delete' )
43- expect ( action . displayName ( [ ] , view ) ) . toBe ( 'Delete' )
64+ expect ( action . displayName ( [ file ] , view ) ) . toBe ( 'Delete' )
4465 expect ( action . iconSvgInline ( [ ] , view ) ) . toBe ( '<svg>SvgMock</svg>' )
4566 expect ( action . default ) . toBeUndefined ( )
4667 expect ( action . order ) . toBe ( 100 )
4768 } )
4869
4970 test ( 'Default trashbin view values' , ( ) => {
50- expect ( action . displayName ( [ ] , trashbinView ) ) . toBe ( 'Delete permanently' )
71+ expect ( action . displayName ( [ file ] , trashbinView ) ) . toBe ( 'Delete permanently' )
72+ } )
73+
74+ test ( 'Shared node values' , ( ) => {
75+ jest . spyOn ( auth , 'getCurrentUser' ) . mockReturnValue ( null )
76+ expect ( action . displayName ( [ file2 ] , view ) ) . toBe ( 'Unshare' )
77+ } )
78+
79+ test ( 'Shared and owned nodes values' , ( ) => {
80+ expect ( action . displayName ( [ file , file2 ] , view ) ) . toBe ( 'Delete and unshare' )
5181 } )
5282} )
5383
5484describe ( 'Delete action enabled tests' , ( ) => {
5585 test ( 'Enabled with DELETE permissions' , ( ) => {
5686 const file = new File ( {
5787 id : 1 ,
58- source : 'https://cloud.domain.com/remote.php/dav/files/admin /foobar.txt' ,
59- owner : 'admin ' ,
88+ source : 'https://cloud.domain.com/remote.php/dav/files/test /foobar.txt' ,
89+ owner : 'test ' ,
6090 mime : 'text/plain' ,
6191 permissions : Permission . ALL ,
6292 } )
@@ -68,8 +98,8 @@ describe('Delete action enabled tests', () => {
6898 test ( 'Disabled without DELETE permissions' , ( ) => {
6999 const file = new File ( {
70100 id : 1 ,
71- source : 'https://cloud.domain.com/remote.php/dav/files/admin /foobar.txt' ,
72- owner : 'admin ' ,
101+ source : 'https://cloud.domain.com/remote.php/dav/files/test /foobar.txt' ,
102+ owner : 'test ' ,
73103 mime : 'text/plain' ,
74104 permissions : Permission . READ ,
75105 } )
@@ -86,14 +116,14 @@ describe('Delete action enabled tests', () => {
86116 test ( 'Disabled if not all nodes can be deleted' , ( ) => {
87117 const folder1 = new Folder ( {
88118 id : 1 ,
89- source : 'https://cloud.domain.com/remote.php/dav/files/admin /Foo/' ,
90- owner : 'admin ' ,
119+ source : 'https://cloud.domain.com/remote.php/dav/files/test /Foo/' ,
120+ owner : 'test ' ,
91121 permissions : Permission . DELETE ,
92122 } )
93123 const folder2 = new Folder ( {
94124 id : 2 ,
95- source : 'https://cloud.domain.com/remote.php/dav/files/admin /Bar/' ,
96- owner : 'admin ' ,
125+ source : 'https://cloud.domain.com/remote.php/dav/files/test /Bar/' ,
126+ owner : 'test ' ,
97127 permissions : Permission . READ ,
98128 } )
99129
@@ -111,8 +141,8 @@ describe('Delete action execute tests', () => {
111141
112142 const file = new File ( {
113143 id : 1 ,
114- source : 'https://cloud.domain.com/remote.php/dav/files/admin /foobar.txt' ,
115- owner : 'admin ' ,
144+ source : 'https://cloud.domain.com/remote.php/dav/files/test /foobar.txt' ,
145+ owner : 'test ' ,
116146 mime : 'text/plain' ,
117147 permissions : Permission . READ | Permission . UPDATE | Permission . DELETE ,
118148 } )
@@ -121,7 +151,7 @@ describe('Delete action execute tests', () => {
121151
122152 expect ( exec ) . toBe ( true )
123153 expect ( axios . delete ) . toBeCalledTimes ( 1 )
124- expect ( axios . delete ) . toBeCalledWith ( 'https://cloud.domain.com/remote.php/dav/files/admin /foobar.txt' )
154+ expect ( axios . delete ) . toBeCalledWith ( 'https://cloud.domain.com/remote.php/dav/files/test /foobar.txt' )
125155
126156 expect ( eventBus . emit ) . toBeCalledTimes ( 1 )
127157 expect ( eventBus . emit ) . toBeCalledWith ( 'files:node:deleted' , file )
@@ -133,16 +163,16 @@ describe('Delete action execute tests', () => {
133163
134164 const file1 = new File ( {
135165 id : 1 ,
136- source : 'https://cloud.domain.com/remote.php/dav/files/admin /foo.txt' ,
137- owner : 'admin ' ,
166+ source : 'https://cloud.domain.com/remote.php/dav/files/test /foo.txt' ,
167+ owner : 'test ' ,
138168 mime : 'text/plain' ,
139169 permissions : Permission . READ | Permission . UPDATE | Permission . DELETE ,
140170 } )
141171
142172 const file2 = new File ( {
143173 id : 2 ,
144- source : 'https://cloud.domain.com/remote.php/dav/files/admin /bar.txt' ,
145- owner : 'admin ' ,
174+ source : 'https://cloud.domain.com/remote.php/dav/files/test /bar.txt' ,
175+ owner : 'test ' ,
146176 mime : 'text/plain' ,
147177 permissions : Permission . READ | Permission . UPDATE | Permission . DELETE ,
148178 } )
@@ -151,8 +181,8 @@ describe('Delete action execute tests', () => {
151181
152182 expect ( exec ) . toStrictEqual ( [ true , true ] )
153183 expect ( axios . delete ) . toBeCalledTimes ( 2 )
154- expect ( axios . delete ) . toHaveBeenNthCalledWith ( 1 , 'https://cloud.domain.com/remote.php/dav/files/admin /foo.txt' )
155- expect ( axios . delete ) . toHaveBeenNthCalledWith ( 2 , 'https://cloud.domain.com/remote.php/dav/files/admin /bar.txt' )
184+ expect ( axios . delete ) . toHaveBeenNthCalledWith ( 1 , 'https://cloud.domain.com/remote.php/dav/files/test /foo.txt' )
185+ expect ( axios . delete ) . toHaveBeenNthCalledWith ( 2 , 'https://cloud.domain.com/remote.php/dav/files/test /bar.txt' )
156186
157187 expect ( eventBus . emit ) . toBeCalledTimes ( 2 )
158188 expect ( eventBus . emit ) . toHaveBeenNthCalledWith ( 1 , 'files:node:deleted' , file1 )
@@ -165,8 +195,8 @@ describe('Delete action execute tests', () => {
165195
166196 const file = new File ( {
167197 id : 1 ,
168- source : 'https://cloud.domain.com/remote.php/dav/files/admin /foobar.txt' ,
169- owner : 'admin ' ,
198+ source : 'https://cloud.domain.com/remote.php/dav/files/test /foobar.txt' ,
199+ owner : 'test ' ,
170200 mime : 'text/plain' ,
171201 permissions : Permission . READ | Permission . UPDATE | Permission . DELETE ,
172202 } )
@@ -175,7 +205,7 @@ describe('Delete action execute tests', () => {
175205
176206 expect ( exec ) . toBe ( false )
177207 expect ( axios . delete ) . toBeCalledTimes ( 1 )
178- expect ( axios . delete ) . toBeCalledWith ( 'https://cloud.domain.com/remote.php/dav/files/admin /foobar.txt' )
208+ expect ( axios . delete ) . toBeCalledWith ( 'https://cloud.domain.com/remote.php/dav/files/test /foobar.txt' )
179209
180210 expect ( eventBus . emit ) . toBeCalledTimes ( 0 )
181211 expect ( logger . error ) . toBeCalledTimes ( 1 )
0 commit comments