44 */
55import { action } from './downloadAction'
66import { expect } from '@jest/globals'
7- import { File , Folder , Permission , View , FileAction , DefaultType } from '@nextcloud/files'
7+ import {
8+ File ,
9+ Folder ,
10+ Permission ,
11+ View ,
12+ FileAction ,
13+ DefaultType ,
14+ } from '@nextcloud/files'
815
916const view = {
1017 id : 'files' ,
@@ -104,7 +111,9 @@ describe('Download action execute tests', () => {
104111 // Silent action
105112 expect ( exec ) . toBe ( null )
106113 expect ( link . download ) . toEqual ( '' )
107- expect ( link . href ) . toEqual ( 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt' )
114+ expect ( link . href ) . toEqual (
115+ 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt' ,
116+ )
108117 expect ( link . click ) . toHaveBeenCalledTimes ( 1 )
109118 } )
110119
@@ -122,7 +131,9 @@ describe('Download action execute tests', () => {
122131 // Silent action
123132 expect ( exec ) . toStrictEqual ( [ null ] )
124133 expect ( link . download ) . toEqual ( '' )
125- expect ( link . href ) . toEqual ( 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt' )
134+ expect ( link . href ) . toEqual (
135+ 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt' ,
136+ )
126137 expect ( link . click ) . toHaveBeenCalledTimes ( 1 )
127138 } )
128139
@@ -139,7 +150,11 @@ describe('Download action execute tests', () => {
139150 // Silent action
140151 expect ( exec ) . toBe ( null )
141152 expect ( link . download ) . toEqual ( '' )
142- expect ( link . href . startsWith ( '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22FooBar%22%5D&downloadStartSecret=' ) ) . toBe ( true )
153+ expect (
154+ link . href . startsWith (
155+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22FooBar%22%5D&downloadStartSecret=' ,
156+ ) ,
157+ ) . toBe ( true )
143158 expect ( link . click ) . toHaveBeenCalledTimes ( 1 )
144159 } )
145160
@@ -164,7 +179,76 @@ describe('Download action execute tests', () => {
164179 // Silent action
165180 expect ( exec ) . toStrictEqual ( [ null , null ] )
166181 expect ( link . download ) . toEqual ( '' )
167- expect ( link . href . startsWith ( '/index.php/apps/files/ajax/download.php?dir=%2FDir&files=%5B%22foo.txt%22%2C%22bar.txt%22%5D&downloadStartSecret=' ) ) . toBe ( true )
168182 expect ( link . click ) . toHaveBeenCalledTimes ( 1 )
183+
184+ expect ( link . href ) . toMatch (
185+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22foo.txt%22%2C%22bar.txt%22%5D&downloadStartSecret=' ,
186+ )
187+ } )
188+
189+ test ( 'Download multiple nodes from different sources' , async ( ) => {
190+ const files = [
191+ new File ( {
192+ id : 1 ,
193+ source : 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 1/foo.txt' ,
194+ owner : 'admin' ,
195+ mime : 'text/plain' ,
196+ permissions : Permission . READ ,
197+ } ) ,
198+ new File ( {
199+ id : 2 ,
200+ source : 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 2/bar.txt' ,
201+ owner : 'admin' ,
202+ mime : 'text/plain' ,
203+ permissions : Permission . READ ,
204+ } ) ,
205+ new File ( {
206+ id : 3 ,
207+ source : 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 2/baz.txt' ,
208+ owner : 'admin' ,
209+ mime : 'text/plain' ,
210+ permissions : Permission . READ ,
211+ } ) ,
212+ ]
213+
214+ const exec = await action . execBatch ! ( files , view , '/Dir' )
215+
216+ // Silent action
217+ expect ( exec ) . toStrictEqual ( [ null , null , null ] )
218+ expect ( link . download ) . toEqual ( '' )
219+ expect ( link . click ) . toHaveBeenCalledTimes ( 1 )
220+
221+ expect ( link . href ) . toMatch (
222+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22foo.txt%22%2C%22bar.txt%22%2C%22baz.txt%22%5D&downloadStartSecret=' ,
223+ )
224+ } )
225+
226+ test ( 'Download node and parent folder' , async ( ) => {
227+ const files = [
228+ new File ( {
229+ id : 1 ,
230+ source : 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 1/foo.txt' ,
231+ owner : 'admin' ,
232+ mime : 'text/plain' ,
233+ permissions : Permission . READ ,
234+ } ) ,
235+ new Folder ( {
236+ id : 2 ,
237+ source : 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 1' ,
238+ owner : 'admin' ,
239+ permissions : Permission . READ ,
240+ } ) ,
241+ ]
242+
243+ const exec = await action . execBatch ! ( files , view , '/Dir' )
244+
245+ // Silent action
246+ expect ( exec ) . toStrictEqual ( [ null , null ] )
247+ expect ( link . download ) . toEqual ( '' )
248+ expect ( link . click ) . toHaveBeenCalledTimes ( 1 )
249+
250+ expect ( link . href ) . toMatch (
251+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22foo.txt%22%2C%22Folder%201%22%5D&downloadStartSecret=' ,
252+ )
169253 } )
170254} )
0 commit comments