-
Notifications
You must be signed in to change notification settings - Fork 842
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
Form tests - Phase 1 #196
Form tests - Phase 1 #196
Changes from 10 commits
e147736
d71fa54
39212ed
1df35cb
bf67fa5
f211fa5
6654bc0
7077992
4beeacc
934cc11
41b26f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,59 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiCheckboxGroup is rendered 1`] = ` | ||
exports[`EuiCheckboxGroupMockedCheckbox disabled is rendered 1`] = ` | ||
<div> | ||
<eui_checkbox | ||
checked="" | ||
class="euiCheckboxGroup__item" | ||
disabled="" | ||
id="1" | ||
label="kibana" | ||
/> | ||
<eui_checkbox | ||
class="euiCheckboxGroup__item" | ||
disabled="" | ||
id="2" | ||
label="elastic" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EuiCheckboxGroupMockedCheckbox idToSelectedMap is rendered 1`] = ` | ||
<div> | ||
<eui_checkbox | ||
checked="" | ||
class="euiCheckboxGroup__item" | ||
id="1" | ||
label="kibana" | ||
/> | ||
<eui_checkbox | ||
class="euiCheckboxGroup__item" | ||
id="2" | ||
label="elastic" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EuiCheckboxGroupMockedCheckbox is rendered 1`] = ` | ||
<div | ||
aria-label="aria-label" | ||
class="testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
id="foobar" | ||
/> | ||
`; | ||
|
||
exports[`EuiCheckboxGroupMockedCheckbox options are rendered 1`] = ` | ||
<div> | ||
<eui_checkbox | ||
class="euiCheckboxGroup__item" | ||
id="1" | ||
label="kibana" | ||
/> | ||
<eui_checkbox | ||
class="euiCheckboxGroup__item" | ||
id="2" | ||
label="elastic" | ||
/> | ||
</div> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,105 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../../test/required_props'; | ||
import { | ||
requiredProps, | ||
startThrowingReactWarnings, | ||
stopThrowingReactWarnings, | ||
} from '../../../test'; | ||
|
||
import { EuiCheckbox } from './checkbox'; | ||
import { | ||
EuiCheckbox, | ||
TYPES, | ||
} from './checkbox'; | ||
|
||
beforeAll(startThrowingReactWarnings); | ||
afterAll(stopThrowingReactWarnings); | ||
|
||
const checkboxRequiredProps = { | ||
id: 'id', | ||
onChange: () => {}, | ||
}; | ||
|
||
describe('EuiCheckbox', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiCheckbox id="id" onChange={() => {}} {...requiredProps} /> | ||
<EuiCheckbox | ||
id="id" | ||
onChange={() => {}} | ||
{...requiredProps} | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
|
||
describe('props', () => { | ||
test('id is required', () => { | ||
expect( | ||
() => <EuiCheckbox checked={true} onChange={() => {}}/> | ||
).toThrow(); | ||
}); | ||
|
||
test('onChange is required', () => { | ||
expect( | ||
() => <EuiCheckbox id="id" checked={true}/> | ||
).toThrow(); | ||
}); | ||
|
||
test('check is rendered', () => { | ||
const component = render( | ||
<EuiCheckbox | ||
{...checkboxRequiredProps} | ||
checked | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
|
||
test('label is rendered', () => { | ||
const component = render( | ||
<EuiCheckbox | ||
{...checkboxRequiredProps} | ||
label={<span>Label</span>} | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
|
||
describe('type', () => { | ||
TYPES.forEach(value => { | ||
test(`${value} is rendered`, () => { | ||
const component = render( | ||
<EuiCheckbox | ||
{...checkboxRequiredProps} | ||
type={value} | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('disabled', () => { | ||
[true, false].forEach(value => { | ||
test(`${value} is rendered`, () => { | ||
const component = render( | ||
<EuiCheckbox | ||
{...checkboxRequiredProps} | ||
disabled={value} | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
|
||
import { EuiCheckboxGroup } from './checkbox_group'; | ||
|
||
// This exists because we need to run the following tests | ||
// without mocking the Checkbox component, such as testing | ||
// an interaction that is handled by the Checkbox component. | ||
describe('EuiCheckboxGroupUnmockedCheckbox', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rephrase this as "EuiCheckboxGroup behavior" to make it a bit more readable and reflect the file name? |
||
test('id is bound to onChange', () => { | ||
const onChangeHandler = sinon.stub(); | ||
const component = mount( | ||
<EuiCheckboxGroup | ||
options={[ | ||
{ id: '1', label: 'kibana', disabled: false }, | ||
]} | ||
idToSelectedMap={{ | ||
'1': true, | ||
}} | ||
onChange={onChangeHandler} | ||
/> | ||
); | ||
|
||
component.find('input[type="checkbox"]').simulate('change'); | ||
sinon.assert.calledWith(onChangeHandler, '1'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,66 @@ import { requiredProps } from '../../../test/required_props'; | |
|
||
import { EuiCheckboxGroup } from './checkbox_group'; | ||
|
||
describe('EuiCheckboxGroup', () => { | ||
jest.mock('./checkbox', () => ({ EuiCheckbox: 'eui_checkbox' })); | ||
|
||
describe('EuiCheckboxGroupMockedCheckbox', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rephrase this as "EuiCheckboxGroup (mocked checkbox)" to make it a bit more readable? |
||
test('is rendered', () => { | ||
const component = render( | ||
<EuiCheckboxGroup onChange={() => {}} {...requiredProps} /> | ||
<EuiCheckboxGroup onChange={() => {}} {...requiredProps} id="foobar" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What were your thoughts on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! |
||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
|
||
test('options are rendered', () => { | ||
const component = render( | ||
<EuiCheckboxGroup | ||
options={[ | ||
{ id: '1', label: 'kibana' }, | ||
{ id: '2', label: 'elastic' }, | ||
]} | ||
onChange={() => {}} | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
|
||
test('idToSelectedMap is rendered', () => { | ||
const component = render( | ||
<EuiCheckboxGroup | ||
options={[ | ||
{ id: '1', label: 'kibana' }, | ||
{ id: '2', label: 'elastic' }, | ||
]} | ||
idToSelectedMap={{ | ||
'1': true, | ||
'2': false, | ||
}} | ||
onChange={() => {}} | ||
/> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
|
||
test('disabled is rendered', () => { | ||
const component = render( | ||
<EuiCheckboxGroup | ||
options={[ | ||
{ id: '1', label: 'kibana' }, | ||
{ id: '2', label: 'elastic' }, | ||
]} | ||
idToSelectedMap={{ | ||
'1': true, | ||
'2': false, | ||
}} | ||
onChange={() => {}} | ||
disabled | ||
/> | ||
); | ||
|
||
expect(component) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get away with just testing
true
?