|
@@ -4,7 +4,14 @@
|
|
|
*/
|
|
|
import { action } from './downloadAction'
|
|
|
import { expect } from '@jest/globals'
|
|
|
-import { File, Folder, Permission, View, FileAction, DefaultType } from '@nextcloud/files'
|
|
|
+import {
|
|
|
+ File,
|
|
|
+ Folder,
|
|
|
+ Permission,
|
|
|
+ View,
|
|
|
+ FileAction,
|
|
|
+ DefaultType,
|
|
|
+} from '@nextcloud/files'
|
|
|
|
|
|
const view = {
|
|
|
id: 'files',
|
|
@@ -104,7 +111,9 @@ describe('Download action execute tests', () => {
|
|
|
// Silent action
|
|
|
expect(exec).toBe(null)
|
|
|
expect(link.download).toEqual('')
|
|
|
- expect(link.href).toEqual('https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt')
|
|
|
+ expect(link.href).toEqual(
|
|
|
+ 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
|
|
+ )
|
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
|
})
|
|
|
|
|
@@ -122,7 +131,9 @@ describe('Download action execute tests', () => {
|
|
|
// Silent action
|
|
|
expect(exec).toStrictEqual([null])
|
|
|
expect(link.download).toEqual('')
|
|
|
- expect(link.href).toEqual('https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt')
|
|
|
+ expect(link.href).toEqual(
|
|
|
+ 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
|
|
+ )
|
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
|
})
|
|
|
|
|
@@ -139,7 +150,11 @@ describe('Download action execute tests', () => {
|
|
|
// Silent action
|
|
|
expect(exec).toBe(null)
|
|
|
expect(link.download).toEqual('')
|
|
|
- expect(link.href.startsWith('/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22FooBar%22%5D&downloadStartSecret=')).toBe(true)
|
|
|
+ expect(
|
|
|
+ link.href.startsWith(
|
|
|
+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22FooBar%22%5D&downloadStartSecret=',
|
|
|
+ ),
|
|
|
+ ).toBe(true)
|
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
|
})
|
|
|
|
|
@@ -164,7 +179,76 @@ describe('Download action execute tests', () => {
|
|
|
// Silent action
|
|
|
expect(exec).toStrictEqual([null, null])
|
|
|
expect(link.download).toEqual('')
|
|
|
- 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)
|
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
|
+
|
|
|
+ expect(link.href).toMatch(
|
|
|
+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22foo.txt%22%2C%22bar.txt%22%5D&downloadStartSecret=',
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ test('Download multiple nodes from different sources', async () => {
|
|
|
+ const files = [
|
|
|
+ new File({
|
|
|
+ id: 1,
|
|
|
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 1/foo.txt',
|
|
|
+ owner: 'admin',
|
|
|
+ mime: 'text/plain',
|
|
|
+ permissions: Permission.READ,
|
|
|
+ }),
|
|
|
+ new File({
|
|
|
+ id: 2,
|
|
|
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 2/bar.txt',
|
|
|
+ owner: 'admin',
|
|
|
+ mime: 'text/plain',
|
|
|
+ permissions: Permission.READ,
|
|
|
+ }),
|
|
|
+ new File({
|
|
|
+ id: 3,
|
|
|
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 2/baz.txt',
|
|
|
+ owner: 'admin',
|
|
|
+ mime: 'text/plain',
|
|
|
+ permissions: Permission.READ,
|
|
|
+ }),
|
|
|
+ ]
|
|
|
+
|
|
|
+ const exec = await action.execBatch!(files, view, '/Dir')
|
|
|
+
|
|
|
+ // Silent action
|
|
|
+ expect(exec).toStrictEqual([null, null, null])
|
|
|
+ expect(link.download).toEqual('')
|
|
|
+ expect(link.click).toHaveBeenCalledTimes(1)
|
|
|
+
|
|
|
+ expect(link.href).toMatch(
|
|
|
+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22foo.txt%22%2C%22bar.txt%22%2C%22baz.txt%22%5D&downloadStartSecret=',
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ test('Download node and parent folder', async () => {
|
|
|
+ const files = [
|
|
|
+ new File({
|
|
|
+ id: 1,
|
|
|
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 1/foo.txt',
|
|
|
+ owner: 'admin',
|
|
|
+ mime: 'text/plain',
|
|
|
+ permissions: Permission.READ,
|
|
|
+ }),
|
|
|
+ new Folder({
|
|
|
+ id: 2,
|
|
|
+ source: 'https://cloud.domain.com/remote.php/dav/files/admin/Folder 1',
|
|
|
+ owner: 'admin',
|
|
|
+ permissions: Permission.READ,
|
|
|
+ }),
|
|
|
+ ]
|
|
|
+
|
|
|
+ const exec = await action.execBatch!(files, view, '/Dir')
|
|
|
+
|
|
|
+ // Silent action
|
|
|
+ expect(exec).toStrictEqual([null, null])
|
|
|
+ expect(link.download).toEqual('')
|
|
|
+ expect(link.click).toHaveBeenCalledTimes(1)
|
|
|
+
|
|
|
+ expect(link.href).toMatch(
|
|
|
+ '/index.php/apps/files/ajax/download.php?dir=%2F&files=%5B%22foo.txt%22%2C%22Folder%201%22%5D&downloadStartSecret=',
|
|
|
+ )
|
|
|
})
|
|
|
})
|