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 '../empty.util' ;
1+ import {
2+ hasNoValue ,
3+ hasValue ,
4+ } from '../empty.util' ;
25import { initialMenusState } from './initial-menus-state' ;
36import {
47 ActivateMenuSectionAction ,
@@ -148,11 +151,14 @@ function removeSection(state: MenusState, action: RemoveMenuSectionAction) {
148151/**
149152 * Remove a section from the index of a certain menu
150153 * @param {MenusState } state The initial state
151- * @param {MenuSection } action The MenuSection of which the ID should be removed from the index
152- * @param {MenuID } action The Menu ID to which the section belonged
154+ * @param {MenuSection } section The MenuSection of which the ID should be removed from the index
155+ * @param {MenuID } menuID The Menu ID to which the section belonged
153156 * @returns {MenusState } The new reduced state
154157 */
155158function removeFromIndex ( state : MenusState , section : MenuSection , menuID : MenuID ) {
159+ if ( hasNoValue ( section ) ) {
160+ return state ;
161+ }
156162 const sectionID = section . id ;
157163 const parentID = section . parentID ;
158164 if ( hasValue ( parentID ) ) {
You can’t perform that action at this time.
0 commit comments