Skip to content

Commit

Permalink
Add tests for ColorPaletteControl and export HOC'ed version as default
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jul 27, 2018
1 parent 0efb6a1 commit 69971d6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
6 changes: 3 additions & 3 deletions editor/components/color-palette/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getColorName } from '../colors';
// translators: first %s: The type of color (e.g. background color), second %s: the color name or value (e.g. red or #ff0000)
const colorIndicatorAriaLabel = __( '(current %s: %s)' );

const ColorPaletteControl = withColorContext( ( { label, value, onChange, colors } ) => {
export function ColorPaletteControl( { label, value, onChange, colors } ) {
const colorName = getColorName( colors, value );
const ariaLabel = sprintf( colorIndicatorAriaLabel, label.toLowerCase(), colorName || value );

Expand All @@ -43,6 +43,6 @@ const ColorPaletteControl = withColorContext( ( { label, value, onChange, colors
/>
</BaseControl>
);
} );
}

export default ColorPaletteControl;
export default withColorContext( ColorPaletteControl );
22 changes: 22 additions & 0 deletions editor/components/color-palette/test/__snapshots__/control.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ColorPaletteControl matches the snapshot 1`] = `
<BaseControl
className="editor-color-palette-control"
label={
<React.Fragment>
Test Color
<ColorIndicator
aria-label="(current test color: red)"
colorValue="#f00"
/>
</React.Fragment>
}
>
<WithColorContext(ColorPalette)
className="editor-color-palette-control__color-palette"
onChange={[Function]}
value="#f00"
/>
</BaseControl>
`;
25 changes: 25 additions & 0 deletions editor/components/color-palette/test/control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* External dependencies
*/
import { shallow } from 'enzyme';
import { noop } from 'lodash';

/**
* Internal dependencies
*/
import { ColorPaletteControl } from '../control';

describe( 'ColorPaletteControl', () => {
it( 'matches the snapshot', () => {
const wrapper = shallow(
<ColorPaletteControl
label="Test Color"
value="#f00"
colors={ [ { color: '#f00', name: 'red' } ] }
onChange={ noop }
/>
);

expect( wrapper ).toMatchSnapshot();
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ exports[`PanelColorSettings matches the snapshot 1`] = `
</span>
}
>
<WithColorContext(Component)
<WithColorContext(ColorPaletteControl)
key="0"
label="border color"
onChange={[Function]}
value="#000"
/>
<WithColorContext(Component)
<WithColorContext(ColorPaletteControl)
key="1"
label="background color"
onChange={[Function]}
Expand Down

0 comments on commit 69971d6

Please sign in to comment.