Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests to Checkbox component #1580

Merged
merged 2 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Future Release

- Updated Log in and Sign up form to match current styling
- Added tests to Checkbox component

## [v1.7.0](https://github.com/Automattic/simplenote-electron/releases/tag/v1.7.0) (2019-08-12)

Expand Down
31 changes: 31 additions & 0 deletions lib/components/checkbox/__snapshots__/test.js.snap
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>
`;
4 changes: 2 additions & 2 deletions lib/components/checkbox/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
.checkbox__icon {
display: inline;
position: relative;
top: -.09em;
top: -0.09em;

svg {
width: 1.3em;
height: 1.3em;
width: 1.3em;
}
}
30 changes: 30 additions & 0 deletions lib/components/checkbox/test.js
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();
});