1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| import type { DmsPermissionResource } from '#/api/x/dms/permission';
|
| import { describe, expect, it } from 'vitest';
|
| import { compareFolders, folderMenuAvailability } from '../folderMenuRules';
|
| function folder(id: string, parentId?: string, sortCode = 0): DmsPermissionResource {
| return {
| createdAt: '2026-08-27T00:00:00Z',
| id,
| name: id,
| parentId,
| resourceType: 'FOLDER',
| revision: 0,
| sortCode,
| sourceId: id,
| sourceType: 'SYSTEM',
| };
| }
|
| describe('folder context menu rules', () => {
| it('enables sibling reorder only when an adjacent sibling exists', () => {
| const siblings = [folder('a', 'root', 1024), folder('b', 'root', 2048), folder('c', 'root', 3072)];
|
| expect(folderMenuAvailability(siblings[0]!, siblings, [siblings[0]!]).canMoveUp).toBe(false);
| expect(folderMenuAvailability(siblings[1]!, siblings, [siblings[1]!])).toMatchObject({ canMoveDown: true, canMoveUp: true });
| expect(folderMenuAvailability(siblings[2]!, siblings, [siblings[2]!]).canMoveDown).toBe(false);
| });
|
| it('protects roots and rejects cyclic or no-op cut paste targets', () => {
| const root = folder('root');
| const source = folder('source', 'root');
| const child = folder('child', 'source');
|
| expect(folderMenuAvailability(root, [root], [root]).canDelete).toBe(false);
| expect(folderMenuAvailability(child, [child], [root, source, child], { mode: 'cut', source }).canPaste).toBe(false);
| expect(folderMenuAvailability(root, [root], [root], { mode: 'cut', source }).canPaste).toBe(false);
| });
|
| it('orders folders by stable sort code and id', () => {
| const values = [folder('c', 'root', 2048), folder('b', 'root', 1024), folder('a', 'root', 1024)];
| expect(values.sort(compareFolders).map((item) => item.id)).toEqual(['a', 'b', 'c']);
| });
| });
|
|