File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -388,6 +388,13 @@ describe('menusReducer', () => {
388388 expect ( newState [ menuID ] . sectionToSubsectionIndex [ parentID ] ) . not . toContain ( childID ) ;
389389 } ) ;
390390
391+ it ( 'should not throw an error when trying to remove an already removed section using the REMOVE_SECTION action' , ( ) => {
392+ const state = dummyState ;
393+ const action = new RemoveMenuSectionAction ( menuID , 'non-existing-id' ) ;
394+ const newState = menusReducer ( state , action ) ;
395+ expect ( newState ) . toEqual ( dummyState ) ;
396+ } ) ;
397+
391398 it ( 'should set active to true for the correct menu section in response to the ACTIVATE_SECTION action' , ( ) => {
392399 dummyState [ menuID ] . sections [ topSectionID ] . active = false ;
393400 const state = dummyState ;
Original file line number Diff line number Diff line change 1- import { hasValue } from '@dspace/shared/utils/empty.util' ;
1+ import {
2+ hasNoValue ,
3+ hasValue ,
4+ } from '@dspace/shared/utils/empty.util' ;
25
36import { initialMenusState } from './initial-menus-state' ;
47import {
@@ -149,11 +152,14 @@ function removeSection(state: MenusState, action: RemoveMenuSectionAction) {
149152/**
150153 * Remove a section from the index of a certain menu
151154 * @param {MenusState } state The initial state
152- * @param {MenuSection } action The MenuSection of which the ID should be removed from the index
153- * @param {MenuID } action The Menu ID to which the section belonged
155+ * @param {MenuSection } section The MenuSection of which the ID should be removed from the index
156+ * @param {MenuID } menuID The Menu ID to which the section belonged
154157 * @returns {MenusState } The new reduced state
155158 */
156159function removeFromIndex ( state : MenusState , section : MenuSection , menuID : MenuID ) {
160+ if ( hasNoValue ( section ) ) {
161+ return state ;
162+ }
157163 const sectionID = section . id ;
158164 const parentID = section . parentID ;
159165 if ( hasValue ( parentID ) ) {
You can’t perform that action at this time.
0 commit comments