-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
218 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Pull Request | ||
|
||
# Controls when the action will run. Triggers the workflow on push or pull request | ||
# events but only for the master branch | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
lint: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/yarn | ||
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: install dependencies | ||
run: yarn install | ||
- name: lint | ||
run: yarn lint | ||
unit-tests: | ||
name: unit tests | ||
runs-on: ubuntu-latest | ||
env: | ||
CI: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/yarn | ||
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: install dependencies | ||
run: yarn install | ||
- name: unit test | ||
run: | | ||
yarn test | ||
visual-tests: | ||
name: visual regression tests | ||
runs-on: ubuntu-latest | ||
env: | ||
CI: true | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # Required to retrieve git history | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/.cache/yarn | ||
key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: install dependencies | ||
run: yarn install | ||
- uses: chromaui/action@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} | ||
|
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
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
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,116 @@ | ||
import React from 'react'; | ||
import { | ||
render, | ||
fireEvent, | ||
} from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import CheckboxInput from './CheckboxInput'; | ||
|
||
describe('CheckboxInput', () => { | ||
test('not disabled, checked, or invalid by default', () => { | ||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={() => null} | ||
/>, | ||
); | ||
const checkbox = getByLabelText('test checkbox'); | ||
|
||
expect(checkbox.checked).toBe(false); | ||
expect(checkbox.disabled).toBe(false); | ||
expect(checkbox.getAttribute('aria-invalid')).toBe('false'); | ||
}); | ||
|
||
test('it renders the label if provided', () => { | ||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={() => null} | ||
/>, | ||
); | ||
expect(getByLabelText('test checkbox')).toBeDefined(); | ||
}); | ||
|
||
test('input is checked when isChecked is true', () => { | ||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={() => null} | ||
isChecked | ||
/>, | ||
); | ||
const checkbox = getByLabelText('test checkbox'); | ||
expect(checkbox.checked).toEqual(true); | ||
}); | ||
|
||
test('input is not checked when isChecked is false', () => { | ||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={() => null} | ||
isChecked={false} | ||
/>, | ||
); | ||
const checkbox = getByLabelText('test checkbox'); | ||
expect(checkbox.checked).toEqual(false); | ||
}); | ||
|
||
describe('onChange', () => { | ||
test('onChange event fires callback function', () => { | ||
const mockedHandleChange = jest.fn(() => null); | ||
|
||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={mockedHandleChange} | ||
/>, | ||
); | ||
const checkbox = getByLabelText('test checkbox'); | ||
fireEvent.click(checkbox); | ||
expect(mockedHandleChange).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('calls onChange with true when isCheck is false', () => { | ||
const mockedHandleChange = jest.fn(() => null); | ||
|
||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={mockedHandleChange} | ||
/>, | ||
); | ||
const checkbox = getByLabelText('test checkbox'); | ||
fireEvent.click(checkbox); | ||
expect(mockedHandleChange).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
test('calls onChange with false when isChecked when true', () => { | ||
const mockedHandleChange = jest.fn(() => null); | ||
|
||
const { getByLabelText } = render( | ||
<CheckboxInput | ||
id="testCheckbox" | ||
label="test checkbox" | ||
value="hello" | ||
onChange={mockedHandleChange} | ||
isChecked | ||
/>, | ||
); | ||
const checkbox = getByLabelText('test checkbox'); | ||
fireEvent.click(checkbox); | ||
expect(mockedHandleChange).toHaveBeenCalledWith(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.