diff --git a/__tests__/view.spec.ts b/__tests__/view.spec.ts index 3540c6a66..b63483235 100644 --- a/__tests__/view.spec.ts +++ b/__tests__/view.spec.ts @@ -58,6 +58,18 @@ describe('Invalid View creation', () => { } as unknown as View), ).toThrowError('View icon is required and must be a valid svg string') }) + + test('Invalid hidden', () => { + expect(() => new View({ + id: 'test', + name: 'Test', + order: 1, + hidden: 'true', + getContents: () => Promise.reject(new Error()), + } as unknown as View), + ).toThrowError('View hidden must be a boolean') + }) + test('Invalid order', () => { expect(() => new View({ id: 'test', @@ -157,6 +169,7 @@ describe('View creation', () => { emptyTitle: 'Test empty title', emptyCaption: 'Test empty caption', getContents: () => Promise.resolve({ folder, contents: [] }), + hidden: true, icon: '', order: 1, params: {}, @@ -175,6 +188,7 @@ describe('View creation', () => { expect(view.emptyTitle).toBe('Test empty title') expect(view.emptyCaption).toBe('Test empty caption') await expect(view.getContents('/')).resolves.toStrictEqual({ folder, contents: [] }) + expect(view.hidden).toBe(true) expect(view.icon).toBe('') expect(view.order).toBe(1) expect(view.params).toStrictEqual({}) diff --git a/lib/navigation/view.ts b/lib/navigation/view.ts index 603173e53..cbdb1bd5f 100644 --- a/lib/navigation/view.ts +++ b/lib/navigation/view.ts @@ -35,6 +35,12 @@ interface ViewData { * information alongside with its content. */ getContents: (path: string) => Promise + + /** + * If set then the view will be hidden from the navigation unless its the active view. + */ + hidden?: true + /** The view icon as an inline svg */ icon: string @@ -115,6 +121,10 @@ export class View implements ViewData { return this._view.getContents } + get hidden() { + return this._view.hidden + } + get icon() { return this._view.icon } @@ -198,6 +208,10 @@ const isValidView = function(view: ViewData): boolean { throw new Error('View getContents is required and must be a function') } + if ('hidden' in view && typeof view.hidden !== 'boolean') { + throw new Error('View hidden must be a boolean') + } + if (!view.icon || typeof view.icon !== 'string' || !isSvg(view.icon)) { throw new Error('View icon is required and must be a valid svg string') } diff --git a/vitest.config.ts b/vitest.config.ts index aa58e325c..007682b4c 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -2,23 +2,27 @@ * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: CC0-1.0 */ + import config from './vite.config' export default async (env) => { const cfg = await config(env) - // Node externals does not work when testing - cfg.plugins = cfg.plugins!.filter((plugin) => plugin && plugin.name !== 'node-externals') + delete cfg.define - cfg.test = { - environment: 'jsdom', - coverage: { - include: ['lib/**'], - exclude: ['lib/utils/logger.ts'], - provider: 'istanbul', - reporter: ['lcov', 'text'], + return { + ...cfg, + test: { + env: { + LANG: 'en-US', + }, + environment: 'jsdom', + coverage: { + include: ['lib/**'], + exclude: ['lib/utils/logger.ts'], + provider: 'istanbul', + reporter: ['lcov', 'text'], + }, + globalSetup: '__tests__/test-global-setup.ts', }, - globalSetup: '__tests__/test-global-setup.ts', } - delete cfg.define - return cfg }