-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#24 tests for input and checkbox components
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/components/ui-elements/checkbox/__snapshots__/checkbox.test.js.snap
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders without error 1`] = `"<div class=\\"form-group\\"><div class=\\"form-check\\"><label class=\\"form-check-label text-dark\\"><input type=\\"checkbox\\" name=\\"the-checkbox\\" class=\\"form-check-input\\"/>the checkbox<span class=\\"form-check-sign\\"><span class=\\"check\\"></span></span></label></div></div>"`; |
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,10 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Checkbox from './checkbox' | ||
|
||
test('renders without error', () => { | ||
const defaultProps = { input: { name: 'the-checkbox' }, label: 'the checkbox', disabled: false } | ||
const wrapper = shallow(<Checkbox {...defaultProps} />) | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) |
3 changes: 3 additions & 0 deletions
3
src/components/ui-elements/input/__snapshots__/input.test.js.snap
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`rendering testing renders without error 1`] = `"<div class=\\"form-group bmd-form-group has-danger\\"><label class=\\"control-label bmd-label-static\\" for=\\"the-input\\">the input</label><input type=\\"text\\" name=\\"the-input\\" id=\\"the-input\\" class=\\"form-control\\"/><span class=\\"form-control-feedback\\"><i class=\\"material-icons \\">clear</i></span><label class=\\"error\\" for=\\"the-input\\" data-test=\\"error-message\\">Bad input</label></div>"`; |
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,62 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Input from './input' | ||
|
||
const validMetaProps = { touched: true, pristine: false, valid: true, invalid: false } | ||
const invalidMetaProps = { touched: true, pristine: false, valid: false, invalid: true, error: 'Bad input' } | ||
|
||
const setup = (props) => { | ||
const defaultProps = { input: { name: 'the-input' }, type: 'text', label: 'the input', disabled: false } | ||
return shallow(<Input {...defaultProps} {...props} />) | ||
} | ||
|
||
describe('rendering testing', () => { | ||
let wrapper | ||
|
||
test('renders without error', () => { | ||
wrapper = setup({ meta: invalidMetaProps }) | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
|
||
describe('valid input data', () => { | ||
beforeEach(() => { | ||
wrapper = setup({ meta: validMetaProps }) | ||
}) | ||
|
||
test('contains valid class', () => { | ||
const validClassNode = wrapper.find('.has-success') | ||
expect(validClassNode.length).toBe(1) | ||
}) | ||
|
||
test('contains success icon', () => { | ||
const iconNode = wrapper.find('.material-icons') | ||
expect(iconNode.text()).toEqual('done') | ||
}) | ||
|
||
test('error message is hidden', () => { | ||
const errorMsg = wrapper.find('[data-test="error-message"]') | ||
expect(errorMsg.length).toBe(0) | ||
}) | ||
}) | ||
|
||
describe('invalid input data', () => { | ||
beforeEach(() => { | ||
wrapper = setup({ meta: invalidMetaProps }) | ||
}) | ||
test('contains invalid class', () => { | ||
const invalidClassNode = wrapper.find('.has-danger') | ||
expect(invalidClassNode.length).toBe(1) | ||
}) | ||
|
||
test('contains error icon', () => { | ||
const iconNode = wrapper.find('.material-icons') | ||
expect(iconNode.text()).toEqual('clear') | ||
}) | ||
|
||
test('shows error message', () => { | ||
const errorMsg = wrapper.find('[data-test="error-message"]') | ||
expect(errorMsg.text()).toEqual(invalidMetaProps.error) | ||
}) | ||
}) | ||
}) |