diff --git a/src/app/shared/menu/menu.reducer.spec.ts b/src/app/shared/menu/menu.reducer.spec.ts index 246dec8a414..d4212c28e5f 100644 --- a/src/app/shared/menu/menu.reducer.spec.ts +++ b/src/app/shared/menu/menu.reducer.spec.ts @@ -388,6 +388,13 @@ describe('menusReducer', () => { expect(newState[menuID].sectionToSubsectionIndex[parentID]).not.toContain(childID); }); + it('should not throw an error when trying to remove an already removed section using the REMOVE_SECTION action', () => { + const state = dummyState; + const action = new RemoveMenuSectionAction(menuID, 'non-existing-id'); + const newState = menusReducer(state, action); + expect(newState).toEqual(dummyState); + }); + it('should set active to true for the correct menu section in response to the ACTIVATE_SECTION action', () => { dummyState[menuID].sections[topSectionID].active = false; const state = dummyState; diff --git a/src/app/shared/menu/menu.reducer.ts b/src/app/shared/menu/menu.reducer.ts index 448b417c8fd..a1c388ed320 100644 --- a/src/app/shared/menu/menu.reducer.ts +++ b/src/app/shared/menu/menu.reducer.ts @@ -1,4 +1,7 @@ -import { hasValue } from '@dspace/shared/utils/empty.util'; +import { + hasNoValue, + hasValue, +} from '@dspace/shared/utils/empty.util'; import { initialMenusState } from './initial-menus-state'; import { @@ -149,11 +152,14 @@ function removeSection(state: MenusState, action: RemoveMenuSectionAction) { /** * Remove a section from the index of a certain menu * @param {MenusState} state The initial state - * @param {MenuSection} action The MenuSection of which the ID should be removed from the index - * @param {MenuID} action The Menu ID to which the section belonged + * @param {MenuSection} section The MenuSection of which the ID should be removed from the index + * @param {MenuID} menuID The Menu ID to which the section belonged * @returns {MenusState} The new reduced state */ function removeFromIndex(state: MenusState, section: MenuSection, menuID: MenuID) { + if (hasNoValue(section)) { + return state; + } const sectionID = section.id; const parentID = section.parentID; if (hasValue(parentID)) {