|
@@ -21,7 +21,14 @@
|
|
*/
|
|
*/
|
|
import { action } from './downloadAction'
|
|
import { action } from './downloadAction'
|
|
import { expect } from '@jest/globals'
|
|
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 = {
|
|
const view = {
|
|
id: 'files',
|
|
id: 'files',
|
|
@@ -121,7 +128,9 @@ describe('Download action execute tests', () => {
|
|
// Silent action
|
|
// Silent action
|
|
expect(exec).toBe(null)
|
|
expect(exec).toBe(null)
|
|
expect(link.download).toEqual('')
|
|
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)
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
|
|
@@ -139,7 +148,9 @@ describe('Download action execute tests', () => {
|
|
// Silent action
|
|
// Silent action
|
|
expect(exec).toStrictEqual([null])
|
|
expect(exec).toStrictEqual([null])
|
|
expect(link.download).toEqual('')
|
|
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)
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
|
|
@@ -156,7 +167,11 @@ describe('Download action execute tests', () => {
|
|
// Silent action
|
|
// Silent action
|
|
expect(exec).toBe(null)
|
|
expect(exec).toBe(null)
|
|
expect(link.download).toEqual('')
|
|
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)
|
|
expect(link.click).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
|
|
@@ -181,7 +196,76 @@ describe('Download action execute tests', () => {
|
|
// Silent action
|
|
// Silent action
|
|
expect(exec).toStrictEqual([null, null])
|
|
expect(exec).toStrictEqual([null, null])
|
|
expect(link.download).toEqual('')
|
|
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.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=',
|
|
|
|
+ )
|
|
})
|
|
})
|
|
})
|
|
})
|