diff options
Diffstat (limited to 'apps/files/src/actions/downloadAction.spec.ts')
-rw-r--r-- | apps/files/src/actions/downloadAction.spec.ts | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/apps/files/src/actions/downloadAction.spec.ts b/apps/files/src/actions/downloadAction.spec.ts index 8aca20eb4d4..8d5612d982b 100644 --- a/apps/files/src/actions/downloadAction.spec.ts +++ b/apps/files/src/actions/downloadAction.spec.ts @@ -2,9 +2,10 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { File, Folder, Permission, View, FileAction, DefaultType } from '@nextcloud/files' +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest' + import { action } from './downloadAction' -import { expect } from '@jest/globals' -import { File, Folder, Permission, View, FileAction } from '@nextcloud/files' const view = { id: 'files', @@ -22,8 +23,8 @@ describe('Download action conditions tests', () => { expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('download') expect(action.displayName([], view)).toBe('Download') - expect(action.iconSvgInline([], view)).toBe('<svg>SvgMock</svg>') - expect(action.default).toBeUndefined() + expect(action.iconSvgInline([], view)).toMatch(/<svg.+<\/svg>/) + expect(action.default).toBe(DefaultType.DEFAULT) expect(action.order).toBe(30) }) }) @@ -83,11 +84,12 @@ describe('Download action enabled tests', () => { describe('Download action execute tests', () => { const link = { - click: jest.fn(), + click: vi.fn(), } as unknown as HTMLAnchorElement beforeEach(() => { - jest.spyOn(document, 'createElement').mockImplementation(() => link) + vi.resetAllMocks() + vi.spyOn(document, 'createElement').mockImplementation(() => link) }) test('Download single file', async () => { @@ -103,7 +105,7 @@ describe('Download action execute tests', () => { // Silent action expect(exec).toBe(null) - expect(link.download).toEqual('') + expect(link.download).toBe('foobar.txt') expect(link.href).toEqual('https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt') expect(link.click).toHaveBeenCalledTimes(1) }) @@ -121,7 +123,26 @@ describe('Download action execute tests', () => { // Silent action expect(exec).toStrictEqual([null]) - expect(link.download).toEqual('') + expect(link.download).toEqual('foobar.txt') + expect(link.href).toEqual('https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt') + expect(link.click).toHaveBeenCalledTimes(1) + }) + + test('Download single file with displayname set', async () => { + const file = new File({ + id: 1, + source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt', + owner: 'admin', + mime: 'text/plain', + displayname: 'baz.txt', + permissions: Permission.READ, + }) + + const exec = await action.execBatch!([file], view, '/') + + // Silent action + expect(exec).toStrictEqual([null]) + expect(link.download).toEqual('baz.txt') expect(link.href).toEqual('https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt') expect(link.click).toHaveBeenCalledTimes(1) }) @@ -139,7 +160,7 @@ 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).toMatch('https://cloud.domain.com/remote.php/dav/files/admin/FooBar/?accept=zip') expect(link.click).toHaveBeenCalledTimes(1) }) @@ -164,7 +185,7 @@ 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.href).toMatch('https://cloud.domain.com/remote.php/dav/files/admin/Dir/?accept=zip&files=%5B%22foo.txt%22%2C%22bar.txt%22%5D') expect(link.click).toHaveBeenCalledTimes(1) }) }) |