Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / context-menu / context-menu-actions.test.ts
index c566e4ac9146a3b7a9a79b50131c3d170e753689..623c45088cc83922f137896effccf4969e19dc0b 100644 (file)
@@ -2,12 +2,12 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/context-menu';
 import { resourceUuidToContextMenuKind } from './context-menu-actions';
 import configureStore from 'redux-mock-store';
 import thunk from 'redux-thunk';
 import { PROJECT_PANEL_CURRENT_UUID } from '../project-panel/project-panel-action';
-import { GroupClass } from '~/models/group';
+import { GroupClass } from 'models/group';
 
 describe('context-menu-actions', () => {
     describe('resourceUuidToContextMenuKind', () => {
@@ -24,7 +24,7 @@ describe('context-menu-actions', () => {
 
         it('should return the correct menu kind', () => {
             const cases = [
-                // resourceUuid, isAdminUser, isEditable, isTrashed, inFilterGroup, expected
+                // resourceUuid, isAdminUser, isEditable, isTrashed, forceReadonly, expected
                 [headCollectionUuid, false, true, true, false, ContextMenuKind.TRASHED_COLLECTION],
                 [headCollectionUuid, false, true, false, false, ContextMenuKind.COLLECTION],
                 [headCollectionUuid, false, true, false, true, ContextMenuKind.READONLY_COLLECTION],
@@ -87,7 +87,7 @@ describe('context-menu-actions', () => {
                 [containerRequestUuid, true, false, false, true, ContextMenuKind.READONLY_PROCESS_RESOURCE],
             ]
 
-            cases.forEach(([resourceUuid, isAdminUser, isEditable, isTrashed, inFilterGroup, expected]) => {
+            cases.forEach(([resourceUuid, isAdminUser, isEditable, isTrashed, forceReadonly, expected]) => {
                 const initialState = {
                     properties: {
                         [PROJECT_PANEL_CURRENT_UUID]: projectUuid,
@@ -107,13 +107,13 @@ describe('context-menu-actions', () => {
                         [projectUuid]: {
                             uuid: projectUuid,
                             ownerUuid: isEditable ? userUuid : otherUserUuid,
-                            writableBy: isEditable ? [userUuid] : [otherUserUuid],
+                            canWrite: isEditable,
                             groupClass: GroupClass.PROJECT,
                         },
                         [filterGroupUuid]: {
                             uuid: filterGroupUuid,
                             ownerUuid: isEditable ? userUuid : otherUserUuid,
-                            writableBy: isEditable ? [userUuid] : [otherUserUuid],
+                            canWrite: isEditable,
                             groupClass: GroupClass.FILTER,
                         },
                         [linkUuid]: {
@@ -133,23 +133,15 @@ describe('context-menu-actions', () => {
                             isAdmin: isAdminUser,
                         },
                     },
-                    properties: {
-                      projectPanelCurrentUuid: inFilterGroup ? filterGroupUuid : "",
-                    },
-                    router: {
-                        location: {
-                            pathname: inFilterGroup ? "/projects/" + filterGroupUuid : "",
-                        },
-                    },
                 };
                 const store = mockStore(initialState);
 
                 let menuKind: any;
                 try {
-                    menuKind = store.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid as string))
+                    menuKind = store.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid as string, forceReadonly as boolean))
                     expect(menuKind).toBe(expected);
                 } catch (err) {
-                    throw new Error(`menuKind for resource ${JSON.stringify(initialState.resources[resourceUuid as string])} expected to be ${expected} but got ${menuKind}.`);
+                    throw new Error(`menuKind for resource ${JSON.stringify(initialState.resources[resourceUuid as string])} forceReadonly: ${forceReadonly} expected to be ${expected} but got ${menuKind}.`);
                 }
             });
         });