|
| 1 | +/*! |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { describe, expect, it } from 'vitest' |
| 7 | +import { isActionAllowedInView, restrictViewActions } from './ViewActionsRegistry.ts' |
| 8 | + |
| 9 | +describe('ViewActionsRegistry', () => { |
| 10 | + it('allows any action in views that have not been restricted', () => { |
| 11 | + expect(isActionAllowedInView('unrestricted-view', 'delete')).toBe(true) |
| 12 | + expect(isActionAllowedInView('unrestricted-view', 'download')).toBe(true) |
| 13 | + }) |
| 14 | + |
| 15 | + it('allows any action when no view is active', () => { |
| 16 | + expect(isActionAllowedInView(undefined, 'delete')).toBe(true) |
| 17 | + }) |
| 18 | + |
| 19 | + it('only allows actions in the allowlist for restricted views', () => { |
| 20 | + restrictViewActions('pendingshares', ['accept-share', 'reject-share']) |
| 21 | + |
| 22 | + expect(isActionAllowedInView('pendingshares', 'accept-share')).toBe(true) |
| 23 | + expect(isActionAllowedInView('pendingshares', 'reject-share')).toBe(true) |
| 24 | + expect(isActionAllowedInView('pendingshares', 'delete')).toBe(false) |
| 25 | + expect(isActionAllowedInView('pendingshares', 'download')).toBe(false) |
| 26 | + expect(isActionAllowedInView('pendingshares', 'sharing-status')).toBe(false) |
| 27 | + }) |
| 28 | + |
| 29 | + it('does not affect siblings when one view is restricted', () => { |
| 30 | + restrictViewActions('deletedshares', ['restore-share']) |
| 31 | + |
| 32 | + expect(isActionAllowedInView('deletedshares', 'restore-share')).toBe(true) |
| 33 | + expect(isActionAllowedInView('deletedshares', 'delete')).toBe(false) |
| 34 | + // A sibling view that has not been restricted is still wide open. |
| 35 | + expect(isActionAllowedInView('files', 'delete')).toBe(true) |
| 36 | + }) |
| 37 | + |
| 38 | + it('replaces the allowlist when called twice for the same view', () => { |
| 39 | + restrictViewActions('view-a', ['action-1']) |
| 40 | + restrictViewActions('view-a', ['action-2']) |
| 41 | + |
| 42 | + expect(isActionAllowedInView('view-a', 'action-1')).toBe(false) |
| 43 | + expect(isActionAllowedInView('view-a', 'action-2')).toBe(true) |
| 44 | + }) |
| 45 | +}) |
0 commit comments