Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/shared/menu/menu.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/app/shared/menu/menu.reducer.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down
Loading