1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
6 import { resourceUuidToContextMenuKind } from './context-menu-actions';
7 import configureStore from 'redux-mock-store';
8 import thunk from 'redux-thunk';
10 describe('context-menu-actions', () => {
11 describe('resourceUuidToContextMenuKind', () => {
12 const middlewares = [thunk];
13 const mockStore = configureStore(middlewares);
14 const userUuid = 'zzzzz-tpzed-bbbbbbbbbbbbbbb';
15 const otherUserUuid = 'zzzzz-tpzed-bbbbbbbbbbbbbbc';
16 const headCollectionUuid = 'zzzzz-4zz18-aaaaaaaaaaaaaaa';
17 const oldCollectionUuid = 'zzzzz-4zz18-aaaaaaaaaaaaaab';
18 const projectUuid = 'zzzzz-j7d0g-ccccccccccccccc';
19 const linkUuid = 'zzzzz-o0j2j-0123456789abcde';
20 const containerRequestUuid = 'zzzzz-xvhdp-0123456789abcde';
22 it('should return the correct menu kind', () => {
24 // resourceUuid, isAdminUser, isEditable, isTrashed, expected
25 [headCollectionUuid, false, true, true, ContextMenuKind.TRASHED_COLLECTION],
26 [headCollectionUuid, false, true, false, ContextMenuKind.COLLECTION],
27 [headCollectionUuid, false, false, true, ContextMenuKind.READONLY_COLLECTION],
28 [headCollectionUuid, false, false, false, ContextMenuKind.READONLY_COLLECTION],
29 [headCollectionUuid, true, true, true, ContextMenuKind.TRASHED_COLLECTION],
30 [headCollectionUuid, true, true, false, ContextMenuKind.COLLECTION_ADMIN],
31 [headCollectionUuid, true, false, true, ContextMenuKind.TRASHED_COLLECTION],
32 [headCollectionUuid, true, false, false, ContextMenuKind.COLLECTION_ADMIN],
34 [oldCollectionUuid, false, true, true, ContextMenuKind.OLD_VERSION_COLLECTION],
35 [oldCollectionUuid, false, true, false, ContextMenuKind.OLD_VERSION_COLLECTION],
36 [oldCollectionUuid, false, false, true, ContextMenuKind.OLD_VERSION_COLLECTION],
37 [oldCollectionUuid, false, false, false, ContextMenuKind.OLD_VERSION_COLLECTION],
38 [oldCollectionUuid, true, true, true, ContextMenuKind.OLD_VERSION_COLLECTION],
39 [oldCollectionUuid, true, true, false, ContextMenuKind.OLD_VERSION_COLLECTION],
40 [oldCollectionUuid, true, false, true, ContextMenuKind.OLD_VERSION_COLLECTION],
41 [oldCollectionUuid, true, false, false, ContextMenuKind.OLD_VERSION_COLLECTION],
43 // FIXME: WB2 doesn't currently have context menu for trashed projects
44 // [projectUuid, false, true, true, ContextMenuKind.TRASHED_PROJECT],
45 [projectUuid, false, true, false, ContextMenuKind.PROJECT],
46 [projectUuid, false, false, true, ContextMenuKind.READONLY_PROJECT],
47 [projectUuid, false, false, false, ContextMenuKind.READONLY_PROJECT],
48 // [projectUuid, true, true, true, ContextMenuKind.TRASHED_PROJECT],
49 [projectUuid, true, true, false, ContextMenuKind.PROJECT_ADMIN],
50 // [projectUuid, true, false, true, ContextMenuKind.TRASHED_PROJECT],
51 [projectUuid, true, false, false, ContextMenuKind.PROJECT_ADMIN],
53 [linkUuid, false, true, true, ContextMenuKind.LINK],
54 [linkUuid, false, true, false, ContextMenuKind.LINK],
55 [linkUuid, false, false, true, ContextMenuKind.LINK],
56 [linkUuid, false, false, false, ContextMenuKind.LINK],
57 [linkUuid, true, true, true, ContextMenuKind.LINK],
58 [linkUuid, true, true, false, ContextMenuKind.LINK],
59 [linkUuid, true, false, true, ContextMenuKind.LINK],
60 [linkUuid, true, false, false, ContextMenuKind.LINK],
62 [userUuid, false, true, true, ContextMenuKind.ROOT_PROJECT],
63 [userUuid, false, true, false, ContextMenuKind.ROOT_PROJECT],
64 [userUuid, false, false, true, ContextMenuKind.ROOT_PROJECT],
65 [userUuid, false, false, false, ContextMenuKind.ROOT_PROJECT],
66 [userUuid, true, true, true, ContextMenuKind.ROOT_PROJECT],
67 [userUuid, true, true, false, ContextMenuKind.ROOT_PROJECT],
68 [userUuid, true, false, true, ContextMenuKind.ROOT_PROJECT],
69 [userUuid, true, false, false, ContextMenuKind.ROOT_PROJECT],
71 [containerRequestUuid, false, true, true, ContextMenuKind.PROCESS_RESOURCE],
72 [containerRequestUuid, false, true, false, ContextMenuKind.PROCESS_RESOURCE],
73 [containerRequestUuid, false, false, true, ContextMenuKind.PROCESS_RESOURCE],
74 [containerRequestUuid, false, false, false, ContextMenuKind.PROCESS_RESOURCE],
75 [containerRequestUuid, true, true, true, ContextMenuKind.PROCESS_ADMIN],
76 [containerRequestUuid, true, true, false, ContextMenuKind.PROCESS_ADMIN],
77 [containerRequestUuid, true, false, true, ContextMenuKind.PROCESS_ADMIN],
78 [containerRequestUuid, true, false, false, ContextMenuKind.PROCESS_ADMIN],
81 cases.forEach(([resourceUuid, isAdminUser, isEditable, isTrashed, expected]) => {
82 const initialState = {
84 [headCollectionUuid]: {
85 uuid: headCollectionUuid,
86 ownerUuid: projectUuid,
87 currentVersionUuid: headCollectionUuid,
90 [oldCollectionUuid]: {
91 uuid: oldCollectionUuid,
92 currentVersionUuid: headCollectionUuid,
98 ownerUuid: isEditable ? userUuid : otherUserUuid,
99 writableBy: isEditable ? [userUuid] : [otherUserUuid],
107 [containerRequestUuid]: {
108 uuid: containerRequestUuid,
109 ownerUuid: projectUuid,
115 isAdmin: isAdminUser,
119 const store = mockStore(initialState);
121 const menuKind = store.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid as string))
123 expect(menuKind).toBe(expected);
125 throw new Error(`menuKind for resource ${JSON.stringify(initialState.resources[resourceUuid as string])} expected to be ${expected} but got ${menuKind}.`);