Skip to content

Commit

Permalink
Testing: Remove unnecessary Enzyme React 16 workarounds (#14156)
Browse files Browse the repository at this point in the history
* Testing: Bump `enzyme-adapter-react-16` to 1.10.0

* Testing: Avoid unforwarded Button mock

No longer necessary with native support for forwardRef in Enzyme

* Testing: Un-skip BlockControls snapshot test
  • Loading branch information
aduth authored Feb 28, 2019
1 parent 4472b1b commit fe2136d
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 94 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions packages/components/src/button/__mocks__/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ exports[`ColorPalette should allow disabling custom color picker 1`] = `
<div
className="components-color-palette__custom-clear-wrapper"
>
<Button
<ForwardRef(Button)
className="components-color-palette__clear"
isDefault={true}
isSmall={true}
onClick={[Function]}
type="button"
>
Clear
</Button>
</ForwardRef(Button)>
</div>
</div>
`;
Expand Down Expand Up @@ -272,15 +272,15 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
renderContent={[Function]}
renderToggle={[Function]}
/>
<Button
<ForwardRef(Button)
className="components-color-palette__clear"
isDefault={true}
isSmall={true}
onClick={[Function]}
type="button"
>
Clear
</Button>
</ForwardRef(Button)>
</div>
</div>
`;
2 changes: 0 additions & 2 deletions packages/components/src/color-palette/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
*/
import ColorPalette from '../';

jest.mock( '../../button' );

describe( 'ColorPalette', () => {
const colors = [ { name: 'red', color: '#f00' }, { name: 'white', color: '#fff' }, { name: 'blue', color: '#00f' } ];
const currentColor = '#f00';
Expand Down
10 changes: 4 additions & 6 deletions packages/components/src/icon-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
*/
import IconButton from '../';

jest.mock( '../../button' );

describe( 'IconButton', () => {
describe( 'basic rendering', () => {
it( 'should render an top level element with only a class property', () => {
Expand All @@ -30,15 +28,15 @@ describe( 'IconButton', () => {

it( 'should add an aria-label when the label property is used', () => {
const iconButton = shallow( <IconButton label="WordPress">WordPress</IconButton> );
expect( iconButton.name() ).toBe( 'Button' );
expect( iconButton.name() ).toBe( 'ForwardRef(Button)' );
expect( iconButton.prop( 'aria-label' ) ).toBe( 'WordPress' );
} );

it( 'should add an aria-label when the label property is used, with Tooltip wrapper', () => {
const iconButton = shallow( <IconButton label="WordPress" /> );
expect( iconButton.name() ).toBe( 'Tooltip' );
expect( iconButton.prop( 'text' ) ).toBe( 'WordPress' );
expect( iconButton.find( 'Button' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
expect( iconButton.find( 'ForwardRef(Button)' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
} );

it( 'should support explicit aria-label override', () => {
Expand All @@ -60,12 +58,12 @@ describe( 'IconButton', () => {
const iconButton = shallow( <IconButton label="WordPress" tooltip="Custom" /> );
expect( iconButton.name() ).toBe( 'Tooltip' );
expect( iconButton.prop( 'text' ) ).toBe( 'Custom' );
expect( iconButton.find( 'Button' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
expect( iconButton.find( 'ForwardRef(Button)' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
} );

it( 'should allow tooltip disable', () => {
const iconButton = shallow( <IconButton label="WordPress" tooltip={ false } /> );
expect( iconButton.name() ).toBe( 'Button' );
expect( iconButton.name() ).toBe( 'ForwardRef(Button)' );
expect( iconButton.prop( 'aria-label' ) ).toBe( 'WordPress' );
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`MenuItem should match snapshot when all props provided 1`] = `
`;

exports[`MenuItem should match snapshot when info is provided 1`] = `
<Button
<ForwardRef(Button)
aria-describedby="edit-post-feature-toggle__info-1"
className="components-menu-item__button"
role="menuitem"
Expand All @@ -36,7 +36,7 @@ exports[`MenuItem should match snapshot when info is provided 1`] = `
<Shortcut
className="components-menu-item__shortcut"
/>
</Button>
</ForwardRef(Button)>
`;

exports[`MenuItem should match snapshot when isSelected and role are optionally provided 1`] = `
Expand All @@ -55,13 +55,13 @@ exports[`MenuItem should match snapshot when isSelected and role are optionally
`;

exports[`MenuItem should match snapshot when only label provided 1`] = `
<Button
<ForwardRef(Button)
className="components-menu-item__button"
role="menuitem"
>
My item
<Shortcut
className="components-menu-item__shortcut"
/>
</Button>
</ForwardRef(Button)>
`;
2 changes: 0 additions & 2 deletions packages/components/src/menu-item/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { noop } from 'lodash';
*/
import { MenuItem } from '../';

jest.mock( '../../button' );

describe( 'MenuItem', () => {
it( 'should match snapshot when only label provided', () => {
const wrapper = shallow(
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/panel/test/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { shallow, mount } from 'enzyme';
*/
import { PanelBody } from '../body';

jest.mock( '../../button' );

describe( 'PanelBody', () => {
describe( 'basic rendering', () => {
it( 'should render an empty div with the matching className', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports[`MoreMenu should match snapshot 1`] = `
position="bottom"
text="Show more tools & options"
>
<Button
<ForwardRef(Button)
aria-expanded={false}
aria-label="Show more tools & options"
className="components-icon-button"
Expand Down Expand Up @@ -79,7 +79,7 @@ exports[`MoreMenu should match snapshot 1`] = `
</SVG>
</Dashicon>
</button>
</Button>
</ForwardRef(Button)>
</Tooltip>
</IconButton>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { mount } from 'enzyme';
*/
import MoreMenu from '../index';

jest.mock( '../../../../../../components/src/button' );

describe( 'MoreMenu', () => {
it( 'should match snapshot', () => {
const wrapper = mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { render } from '@wordpress/element';
*/
import PluginPostPublishPanel from '../';

jest.mock( '../../../../../../components/src/button' );

describe( 'PluginPostPublishPanel', () => {
test( 'renders fill properly', () => {
const div = document.createElement( 'div' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { render } from '@wordpress/element';
*/
import PluginPrePublishPanel from '../';

jest.mock( '../../../../../../components/src/button' );

describe( 'PluginPrePublishPanel', () => {
test( 'renders fill properly', () => {
const div = document.createElement( 'div' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BlockControls Should render a dynamic toolbar of controls 1`] = `
<Fill
name="Block.Toolbar"
>
<Toolbar
controls={
Array [
Object {
"align": "left",
"icon": "editor-alignleft",
"title": "Align left",
},
Object {
"align": "center",
"icon": "editor-aligncenter",
"title": "Align center",
},
Object {
"align": "right",
"icon": "editor-alignright",
"title": "Align right",
},
]
exports[`BlockControls should render a dynamic toolbar of controls 1`] = `
<ContextProvider
value={
Object {
"clientId": undefined,
"focusedElement": null,
"isSelected": true,
"name": undefined,
"setFocusedElement": [Function],
}
/>
<p>
Child
</p>
</Fill>
}
>
<WithFilters(Edit)
isSelected={true}
>
<IfBlockEditSelected(BlockControlsFill)
controls={
Array [
Object {
"align": "left",
"icon": "editor-alignleft",
"title": "Align left",
},
Object {
"align": "center",
"icon": "editor-aligncenter",
"title": "Align center",
},
Object {
"align": "right",
"icon": "editor-alignright",
"title": "Align right",
},
]
}
>
<p>
Child
</p>
</IfBlockEditSelected(BlockControlsFill)>
</WithFilters(Edit)>
</ContextProvider>
`;
17 changes: 12 additions & 5 deletions packages/editor/src/components/block-controls/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { shallow } from 'enzyme';
/**
* Internal dependencies
*/
import { BlockControls } from '../';
import BlockControls from '../';
import BlockEdit from '../../block-edit';

describe( 'BlockControls', () => {
const controls = [
Expand All @@ -27,9 +28,15 @@ describe( 'BlockControls', () => {
},
];

// Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs.
// eslint-disable-next-line jest/no-disabled-tests
test.skip( 'Should render a dynamic toolbar of controls', () => {
expect( shallow( <BlockControls controls={ controls } children={ <p>Child</p> } /> ) ).toMatchSnapshot();
it( 'should render a dynamic toolbar of controls', () => {
const wrapper = shallow(
<BlockEdit isSelected>
<BlockControls controls={ controls }>
<p>Child</p>
</BlockControls>
</BlockEdit>
);

expect( wrapper ).toMatchSnapshot();
} );
} );
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PostPreviewButton render() should render currentPostLink otherwise 1`] = `
<Button
<ForwardRef(Button)
className="editor-post-preview"
disabled={false}
href="https://wordpress.org/?p=1"
Expand All @@ -20,11 +20,11 @@ exports[`PostPreviewButton render() should render currentPostLink otherwise 1`]
>
Click “Preview” to load a preview of this page, so you can make sure you’re happy with your blocks.
</WithSelect(WithDispatch(DotTip))>
</Button>
</ForwardRef(Button)>
`;

exports[`PostPreviewButton render() should render previewLink if provided 1`] = `
<Button
<ForwardRef(Button)
className="editor-post-preview"
disabled={false}
href="https://wordpress.org/?p=1&preview=true"
Expand All @@ -43,5 +43,5 @@ exports[`PostPreviewButton render() should render previewLink if provided 1`] =
>
Click “Preview” to load a preview of this page, so you can make sure you’re happy with your blocks.
</WithSelect(WithDispatch(DotTip))>
</Button>
</ForwardRef(Button)>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
*/
import { PostPreviewButton } from '../';

jest.mock( '../../../../../components/src/button' );

describe( 'PostPreviewButton', () => {
describe( 'setPreviewWindowLink()', () => {
it( 'should do nothing if there is no preview window', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
*/
import { PostPublishButton } from '../';

jest.mock( '../../../../../components/src/button' );

describe( 'PostPublishButton', () => {
describe( 'aria-disabled', () => {
it( 'should be true if post is currently saving', () => {
Expand Down Expand Up @@ -196,6 +194,6 @@ describe( 'PostPublishButton', () => {
/>
);

expect( wrapper.find( 'Button' ).prop( 'isBusy' ) ).toBe( true );
expect( wrapper.find( 'ForwardRef(Button)' ).prop( 'isBusy' ) ).toBe( true );
} );
} );
1 change: 1 addition & 0 deletions packages/jest-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Internal

- The bundled `enzyme` dependency has been updated from requiring `^3.7.0` to requiring `^3.9.0` ([#13922](https://github.com/WordPress/gutenberg/pull/13922)).
- The bundled `enzyme-adapter-react-16` dependency has been updated from requiring `^1.6.0` to requiring `^1.10.0` ([#13922](https://github.com/WordPress/gutenberg/pull/13922)).

## 3.0.3 (2018-11-20)

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@wordpress/jest-console": "file:../jest-console",
"babel-jest": "^24.1.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.9.1",
"enzyme-adapter-react-16": "^1.10.0",
"enzyme-to-json": "^3.3.5"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit fe2136d

Please sign in to comment.