diff options
Diffstat (limited to 'apps/files/src/actions/sidebarAction.spec.ts')
-rw-r--r-- | apps/files/src/actions/sidebarAction.spec.ts | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/apps/files/src/actions/sidebarAction.spec.ts b/apps/files/src/actions/sidebarAction.spec.ts index 9e1415b0b2c..9085bf595ad 100644 --- a/apps/files/src/actions/sidebarAction.spec.ts +++ b/apps/files/src/actions/sidebarAction.spec.ts @@ -2,8 +2,8 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { expect } from '@jest/globals' -import { File, Permission, View, FileAction } from '@nextcloud/files' +import { File, Permission, View, FileAction, Folder } from '@nextcloud/files' +import { describe, expect, test, vi } from 'vitest' import { action } from './sidebarAction' import logger from '../logger' @@ -17,8 +17,8 @@ describe('Open sidebar action conditions tests', () => { test('Default values', () => { expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('details') - expect(action.displayName([], view)).toBe('Open details') - expect(action.iconSvgInline([], view)).toBe('<svg>SvgMock</svg>') + expect(action.displayName([], view)).toBe('Details') + expect(action.iconSvgInline([], view)).toMatch(/<svg.+<\/svg>/) expect(action.default).toBeUndefined() expect(action.order).toBe(-50) }) @@ -107,9 +107,12 @@ describe('Open sidebar action enabled tests', () => { describe('Open sidebar action exec tests', () => { test('Open sidebar', async () => { - const openMock = jest.fn() - window.OCA = { Files: { Sidebar: { open: openMock } } } - const goToRouteMock = jest.fn() + const openMock = vi.fn() + const defaultTabMock = vi.fn() + window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } } + + const goToRouteMock = vi.fn() + // @ts-expect-error We only mock what needed, we do not need Files.Router.goTo or Files.Navigation window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } const file = new File({ @@ -123,18 +126,49 @@ describe('Open sidebar action exec tests', () => { // Silent action expect(exec).toBe(null) expect(openMock).toBeCalledWith('/foobar.txt') + expect(defaultTabMock).toBeCalledWith('sharing') + expect(goToRouteMock).toBeCalledWith( + null, + { view: view.id, fileid: '1' }, + { dir: '/', opendetails: 'true' }, + true, + ) + }) + + test('Open sidebar for folder', async () => { + const openMock = vi.fn() + const defaultTabMock = vi.fn() + window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } } + + const goToRouteMock = vi.fn() + // @ts-expect-error We only mock what needed, we do not need Files.Router.goTo or Files.Navigation + window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } + + const file = new Folder({ + id: 1, + source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar', + owner: 'admin', + mime: 'httpd/unix-directory', + }) + + const exec = await action.exec(file, view, '/') + // Silent action + expect(exec).toBe(null) + expect(openMock).toBeCalledWith('/foobar') + expect(defaultTabMock).toBeCalledWith('sharing') expect(goToRouteMock).toBeCalledWith( null, - { view: view.id, fileid: 1 }, - { dir: '/' }, + { view: view.id, fileid: '1' }, + { dir: '/', opendetails: 'true' }, true, ) }) test('Open sidebar fails', async () => { - const openMock = jest.fn(() => { throw new Error('Mock error') }) - window.OCA = { Files: { Sidebar: { open: openMock } } } - jest.spyOn(logger, 'error').mockImplementation(() => jest.fn()) + const openMock = vi.fn(() => { throw new Error('Mock error') }) + const defaultTabMock = vi.fn() + window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } } + vi.spyOn(logger, 'error').mockImplementation(() => vi.fn()) const file = new File({ id: 1, |