-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1580 from Automattic/update/cleanup-checkbox-comp…
…onent Add Tests to Checkbox component
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 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
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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`hasn't had its output unintentionally altered 1`] = ` | ||
<span | ||
aria-checked={false} | ||
className="checkbox" | ||
role="checkbox" | ||
tabIndex="0" | ||
> | ||
<span | ||
aria-hidden="true" | ||
className="checkbox__icon" | ||
> | ||
<svg | ||
className="icon-circle" | ||
height="24px" | ||
viewBox="0 0 24 24" | ||
width="24px" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g | ||
transform="translate(2 2)" | ||
> | ||
<path | ||
d="m10 0c-5.523 0-10 4.477-10 10s4.477 10 10 10 10-4.477 10-10-4.477-10-10-10zm0 18.5c-4.694 0-8.5-3.806-8.5-8.5s3.806-8.5 8.5-8.5 8.5 3.806 8.5 8.5-3.806 8.5-8.5 8.5z" | ||
/> | ||
</g> | ||
</svg> | ||
</span> | ||
</span> | ||
`; |
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
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,30 @@ | ||
import Checkbox from './'; | ||
import CheckmarkIcon from '../../icons/checkmark'; | ||
import CircleIcon from '../../icons/circle'; | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { shallow } from 'enzyme'; | ||
|
||
it("hasn't had its output unintentionally altered", () => { | ||
const tree = renderer.create(<Checkbox checked={false}></Checkbox>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders the circle icon when unchecked', () => { | ||
const checkbox = shallow(<Checkbox checked={false}></Checkbox>); | ||
expect(checkbox.find(CircleIcon)).toHaveLength(1); | ||
expect(checkbox.find(CheckmarkIcon)).toHaveLength(0); | ||
}); | ||
|
||
it('renders the checkmark icon when checked', () => { | ||
const checkbox = shallow(<Checkbox checked={true}></Checkbox>); | ||
expect(checkbox.find(CircleIcon)).toHaveLength(0); | ||
expect(checkbox.find(CheckmarkIcon)).toHaveLength(1); | ||
}); | ||
|
||
it('should call onChange prop when span is clicked', () => { | ||
const noop = jest.fn(); | ||
const output = renderer.create(<Checkbox onChange={noop}></Checkbox>); | ||
output.root.findByType('span').props.onClick(); | ||
expect(noop).toHaveBeenCalled(); | ||
}); |