Skip to content

Commit

Permalink
Add noticeType to action args and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed May 25, 2023
1 parent c82111a commit a0e3ee1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/reference-guides/data/data-core-notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,20 @@ export const ExampleComponent = () => {
<Button onClick={ () => removeAllNotices() }>
{ __( 'Clear all notices', 'woo-gutenberg-products-block' ) }
</Button>
<Button onClick={ () => removeAllNotices( 'snackbar' ) }>
{ __(
'Clear all snackbar notices',
'woo-gutenberg-products-block'
) }
</Button>
</>
);
};
```

_Parameters_

- _noticeType_ `string`: The context to remove all notices from.
- _context_ `string`: The context to remove all notices from.

_Returns_
Expand Down
16 changes: 14 additions & 2 deletions packages/notices/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ export function removeNotice( id, context = DEFAULT_CONTEXT ) {
/**
* Removes all notices from a given context. Defaults to the default context.
*
* @param {string} context The context to remove all notices from.
* @param {string} noticeType The context to remove all notices from.
* @param {string} context The context to remove all notices from.
*
* @example
* ```js
Expand Down Expand Up @@ -345,16 +346,27 @@ export function removeNotice( id, context = DEFAULT_CONTEXT ) {
* >
* { __( 'Clear all notices', 'woo-gutenberg-products-block' ) }
* </Button>
* <Button
* onClick={ () =>
* removeAllNotices( 'snackbar' )
* }
* >
* { __( 'Clear all snackbar notices', 'woo-gutenberg-products-block' ) }
* </Button>
* </>
* );
* };
* ```
*
* @return {Object} Action object.
*/
export function removeAllNotices( context = DEFAULT_CONTEXT ) {
export function removeAllNotices(
noticeType = 'default',
context = DEFAULT_CONTEXT
) {
return {
type: 'REMOVE_ALL_NOTICES',
noticeType,
context,
};
}
12 changes: 11 additions & 1 deletion packages/notices/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,27 @@ describe( 'actions', () => {
it( 'should return action', () => {
expect( removeAllNotices() ).toEqual( {
type: 'REMOVE_ALL_NOTICES',
noticeType: 'default',
context: DEFAULT_CONTEXT,
} );
} );

it( 'should return action with custom context', () => {
const context = 'foo';

expect( removeAllNotices( context ) ).toEqual( {
expect( removeAllNotices( 'default', context ) ).toEqual( {
type: 'REMOVE_ALL_NOTICES',
noticeType: 'default',
context,
} );
} );

it( 'should return action with type', () => {
expect( removeAllNotices( 'snackbar' ) ).toEqual( {
type: 'REMOVE_ALL_NOTICES',
noticeType: 'snackbar',
context: DEFAULT_CONTEXT,
} );
} );
} );
} );

0 comments on commit a0e3ee1

Please sign in to comment.