-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Directory: Store refactor (#22388)
* Pass along action parameter * Fix up comments * Use shared package `data-controls` * Remove `uninstallBlock`, `removeInstalledBlockType` * Update controls to return promises Includes very basic testing, since I'm having trouble with both promises and document mocking * Update response format from API * Refactor install & download into one single, multi-step action generator This walks through each step, and removes the need for onError & onSuccess * Switch to new action generator for installation * Update Notice reducer to store the notice text This will let us return more descriptive error messages for each kind of error, instead of generic install/download failed messages * Bring `onSelect` functionality back * Fix notice description * Switch to `useDispatch` hook * Update packages/block-directory/src/store/controls.js Co-authored-by: Steven Dufresne <steve.dufresne@automattic.com> * Remove extra export * Remove unnecessary resets * Update variable name to reflect value * Add test to block list item * Remove unused props * Remove behavior test, update to use snapshot testing Behavior is tested in DownloadableBlockListItem tests * Update notice block to use `useSelect` * Update package-lock * Check file extension before trying to load scripts & styles * Fix class name * Bring back `setIsInstalling` * Add i18n & punctuation to error messages * Add a default error message * Return a success/failure indicator for installation This prevents an error where `onSelect` tries to run on a block that fails to install * Remove unused state property, update tests * Add selector tests for `getDownloadableBlocks` * Update mocked API response * Add default message for installation failures Co-authored-by: Steven Dufresne <steve.dufresne@automattic.com>
- Loading branch information
1 parent
3e434cc
commit f717994
Showing
25 changed files
with
678 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ck-directory/src/components/downloadable-block-list-item/test/__snapshots__/index.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DownloadableBlockListItem should render a block item 1`] = ` | ||
<li | ||
className="block-directory-downloadable-block-list-item" | ||
> | ||
<article | ||
className="block-directory-downloadable-block-list-item__panel" | ||
> | ||
<header | ||
className="block-directory-downloadable-block-list-item__header" | ||
> | ||
<WithSelect(DownloadableBlockHeader) | ||
icon="block-default" | ||
onClick={[MockFunction]} | ||
rating={5} | ||
title="Boxer" | ||
/> | ||
</header> | ||
<section | ||
className="block-directory-downloadable-block-list-item__body" | ||
> | ||
<DownloadableBlockNotice | ||
block={ | ||
Object { | ||
"active_installs": 0, | ||
"assets": Array [ | ||
"http://plugins.svn.wordpress.org/boxer-block/trunk/build/index.js", | ||
"http://plugins.svn.wordpress.org/boxer-block/trunk/build/view.js", | ||
], | ||
"author": "CK Lee", | ||
"author_block_count": "1", | ||
"author_block_rating": 5, | ||
"description": "Boxer is a Block that puts your WordPress posts into boxes on a page.", | ||
"humanized_updated": "3 months ago", | ||
"icon": "block-default", | ||
"id": "boxer-block", | ||
"name": "boxer/boxer", | ||
"rating": 5, | ||
"rating_count": 1, | ||
"title": "Boxer", | ||
} | ||
} | ||
onClick={[MockFunction]} | ||
/> | ||
<DownloadableBlockInfo | ||
description="Boxer is a Block that puts your WordPress posts into boxes on a page." | ||
/> | ||
</section> | ||
<footer | ||
className="block-directory-downloadable-block-list-item__footer" | ||
> | ||
<DownloadableBlockAuthorInfo | ||
author="CK Lee" | ||
/> | ||
</footer> | ||
</article> | ||
</li> | ||
`; |
19 changes: 19 additions & 0 deletions
19
packages/block-directory/src/components/downloadable-block-list-item/test/fixtures/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const item = { | ||
name: 'boxer/boxer', | ||
title: 'Boxer', | ||
description: | ||
'Boxer is a Block that puts your WordPress posts into boxes on a page.', | ||
id: 'boxer-block', | ||
icon: 'block-default', | ||
rating: 5, | ||
rating_count: 1, | ||
active_installs: 0, | ||
author_block_rating: 5, | ||
author_block_count: '1', | ||
author: 'CK Lee', | ||
assets: [ | ||
'http://plugins.svn.wordpress.org/boxer-block/trunk/build/index.js', | ||
'http://plugins.svn.wordpress.org/boxer-block/trunk/build/view.js', | ||
], | ||
humanized_updated: '3 months ago', | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/block-directory/src/components/downloadable-block-list-item/test/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DownloadableBlockListItem from '../index'; | ||
import DownloadableBlockHeader from '../../downloadable-block-header'; | ||
import { item } from './fixtures'; | ||
|
||
describe( 'DownloadableBlockListItem', () => { | ||
it( 'should render a block item', () => { | ||
const wrapper = shallow( | ||
<DownloadableBlockListItem onClick={ jest.fn() } item={ item } /> | ||
); | ||
|
||
expect( wrapper ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should try to install the block plugin', () => { | ||
const onClick = jest.fn(); | ||
const wrapper = shallow( | ||
<DownloadableBlockListItem onClick={ onClick } item={ item } /> | ||
); | ||
|
||
wrapper | ||
.find( DownloadableBlockHeader ) | ||
.simulate( 'click', { event: {} } ); | ||
|
||
expect( onClick ).toHaveBeenCalledTimes( 1 ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/block-directory/src/components/downloadable-block-notice/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
.block-directory-downloadable-blocks__notice { | ||
.block-directory-downloadable-block-notice { | ||
margin: 0 0 16px; | ||
} | ||
|
||
.block-directory-downloadable-blocks__notice-content { | ||
.block-directory-downloadable-block-notice__content { | ||
padding-right: 12px; | ||
margin-bottom: 8px; | ||
} |
22 changes: 22 additions & 0 deletions
22
...block-directory/src/components/downloadable-block-notice/test/__snapshots__/index.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DownloadableBlockNotice Rendering should return something when there are error notices 1`] = ` | ||
<Notice | ||
className="block-directory-downloadable-block-notice" | ||
isDismissible={false} | ||
status="error" | ||
> | ||
<div | ||
className="block-directory-downloadable-block-notice__content" | ||
> | ||
Plugin not found. | ||
</div> | ||
<ForwardRef(Button) | ||
isPrimary={true} | ||
isSmall={true} | ||
onClick={[Function]} | ||
> | ||
Retry | ||
</ForwardRef(Button)> | ||
</Notice> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.