diff --git a/packages/notices/src/store/reducer.js b/packages/notices/src/store/reducer.js index 5cca46fc4a493f..3b49b90f4720a3 100644 --- a/packages/notices/src/store/reducer.js +++ b/packages/notices/src/store/reducer.js @@ -25,7 +25,7 @@ const notices = onSubKey( 'context' )( ( state = [], action ) => { return state.filter( ( { id } ) => id !== action.id ); case 'REMOVE_ALL_NOTICES': - return []; + return state.filter( ( { type } ) => type !== action.noticeType ); } return state; diff --git a/packages/notices/src/store/test/reducer.js b/packages/notices/src/store/test/reducer.js index ad306c97621e93..612cfe6371d40f 100644 --- a/packages/notices/src/store/test/reducer.js +++ b/packages/notices/src/store/test/reducer.js @@ -196,7 +196,7 @@ describe( 'reducer', () => { } ); let state = reducer( original, action ); - state = reducer( state, removeAllNotices( 'bar' ) ); + state = reducer( state, removeAllNotices( 'default', 'bar' ) ); expect( state ).toEqual( { bar: [], @@ -217,4 +217,37 @@ describe( 'reducer', () => { ], } ); } ); + + it( 'should remove all notices of a given type', () => { + let action = createNotice( 'error', 'save error', { + id: 'global-error', + } ); + const original = deepFreeze( reducer( undefined, action ) ); + + action = createNotice( 'success', 'successfully saved', { + type: 'snackbar', + id: 'snackbar-success', + } ); + + let state = reducer( original, action ); + state = reducer( state, removeAllNotices( 'default' ) ); + + expect( state ).toEqual( { + [ DEFAULT_CONTEXT ]: [ + { + id: 'snackbar-success', + content: 'successfully saved', + spokenMessage: 'successfully saved', + __unstableHTML: undefined, + status: 'success', + isDismissible: true, + actions: [], + type: 'snackbar', + icon: null, + explicitDismiss: false, + onDismiss: undefined, + }, + ], + } ); + } ); } );