From 5bde787467a2f399fd498a0b63ecfd90e6a9d6d8 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 21 Jan 2021 17:46:08 -0500 Subject: [PATCH] Add a snackbar when the installation succeeds --- packages/block-directory/src/store/actions.js | 15 ++++++++++++++- .../block-directory/src/store/test/actions.js | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/block-directory/src/store/actions.js b/packages/block-directory/src/store/actions.js index 721510e4679a43..e6b4867c930f37 100644 --- a/packages/block-directory/src/store/actions.js +++ b/packages/block-directory/src/store/actions.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { store as blocksStore } from '@wordpress/blocks'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { controls } from '@wordpress/data'; import { apiFetch } from '@wordpress/data-controls'; import { store as noticesStore } from '@wordpress/notices'; @@ -96,6 +96,19 @@ export function* installBlockType( block ) { ); } + yield controls.dispatch( + noticesStore, + 'createInfoNotice', + sprintf( + // translators: %s is the block title. + __( 'Block %s installed and added.' ), + block.title + ), + { + speak: true, + type: 'snackbar', + } + ); success = true; } catch ( error ) { let message = error.message || __( 'An error occurred.' ); diff --git a/packages/block-directory/src/store/test/actions.js b/packages/block-directory/src/store/test/actions.js index b89375f3a85c1f..d076b8752bfa62 100644 --- a/packages/block-directory/src/store/test/actions.js +++ b/packages/block-directory/src/store/test/actions.js @@ -90,7 +90,13 @@ describe( 'actions', () => { type: '@@data/SELECT', } ); - expect( generator.next( [ block ] ).value ).toEqual( { + expect( generator.next( [ block ] ).value ).toMatchObject( { + type: '@@data/DISPATCH', + actionName: 'createInfoNotice', + storeKey: noticesStore, + } ); + + expect( generator.next().value ).toEqual( { type: 'SET_INSTALLING_BLOCK', blockId: block.id, isInstalling: false, @@ -152,7 +158,13 @@ describe( 'actions', () => { type: '@@data/SELECT', } ); - expect( generator.next( [ inactiveBlock ] ).value ).toEqual( { + expect( generator.next( [ inactiveBlock ] ).value ).toMatchObject( { + type: '@@data/DISPATCH', + actionName: 'createInfoNotice', + storeKey: noticesStore, + } ); + + expect( generator.next().value ).toEqual( { type: 'SET_INSTALLING_BLOCK', blockId: inactiveBlock.id, isInstalling: false,