Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -157,6 +169,7 @@ describe('View creation', () => {
emptyTitle: 'Test empty title',
emptyCaption: 'Test empty caption',
getContents: () => Promise.resolve({ folder, contents: [] }),
hidden: true,
icon: '<svg></svg>',
order: 1,
params: {},
Expand All @@ -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('<svg></svg>')
expect(view.order).toBe(1)
expect(view.params).toStrictEqual({})
Expand Down
14 changes: 14 additions & 0 deletions lib/navigation/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ interface ViewData {
* information alongside with its content.
*/
getContents: (path: string) => Promise<ContentsWithRoot>

/**
* 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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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')
}
Expand Down
28 changes: 16 additions & 12 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}