-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix(checkbox): pass disabled prop to input #2800
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -65,36 +65,24 @@ describe('Checkbox', () => { | |
it('can be checked and unchecked', () => { | ||
wrapperShallow(<Checkbox />) | ||
|
||
wrapper | ||
.find('input') | ||
.should.not.be.checked() | ||
wrapper.find('input').should.not.be.checked() | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.be.checked() | ||
wrapper.find('input').should.be.checked() | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.not.be.checked() | ||
wrapper.find('input').should.not.be.checked() | ||
}) | ||
it('can be checked but not unchecked when radio', () => { | ||
wrapperShallow(<Checkbox radio />) | ||
|
||
wrapper | ||
.find('input') | ||
.should.not.be.checked() | ||
wrapper.find('input').should.not.be.checked() | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.be.checked() | ||
wrapper.find('input').should.be.checked() | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.be.checked() | ||
wrapper.find('input').should.be.checked() | ||
}) | ||
}) | ||
|
||
|
@@ -154,17 +142,24 @@ describe('Checkbox', () => { | |
wrapperShallow(<Checkbox disabled />) | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.not.be.checked() | ||
wrapper.find('input').should.not.be.checked() | ||
}) | ||
|
||
it('cannot be unchecked', () => { | ||
wrapperShallow(<Checkbox defaultChecked disabled />) | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
wrapper.find('input').should.be.checked() | ||
}) | ||
|
||
it('is applied to the underlying html input element', () => { | ||
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. These are the tests, better to review in Split mode as GitHub did a diff mess because of the Lint |
||
wrapperShallow(<Checkbox disabled />) | ||
.find('input') | ||
.should.be.checked() | ||
.should.have.prop('disabled', true) | ||
|
||
wrapperShallow(<Checkbox disabled={false} />) | ||
.find('input') | ||
.should.have.prop('disabled', false) | ||
}) | ||
}) | ||
|
||
|
@@ -203,37 +198,35 @@ describe('Checkbox', () => { | |
|
||
describe('label', () => { | ||
it('adds the "fitted" class when not present', () => { | ||
shallow(<Checkbox name='firstName' />) | ||
.should.have.className('fitted') | ||
shallow(<Checkbox name='firstName' />).should.have.className('fitted') | ||
}) | ||
|
||
it('adds the "fitted" class when is null', () => { | ||
shallow(<Checkbox name='firstName' />) | ||
.should.have.className('fitted') | ||
shallow(<Checkbox name='firstName' />).should.have.className('fitted') | ||
}) | ||
|
||
it('does not add the "fitted" class when is not nil', () => { | ||
shallow(<Checkbox name='firstName' label='' />) | ||
.should.not.have.className('fitted') | ||
shallow(<Checkbox name='firstName' label='' />).should.not.have.className('fitted') | ||
|
||
shallow(<Checkbox name='firstName' label={0} />) | ||
.should.not.have.className('fitted') | ||
shallow(<Checkbox name='firstName' label={0} />).should.not.have.className('fitted') | ||
}) | ||
}) | ||
|
||
describe('onChange', () => { | ||
it('is called with (event { name, value, !checked }) on click', () => { | ||
const spy = sandbox.spy() | ||
const expectProps = { name: 'foo', value: 'bar', checked: false, indeterminate: true } | ||
mount(<Checkbox onChange={spy} {...expectProps} />) | ||
.simulate('click') | ||
mount(<Checkbox onChange={spy} {...expectProps} />).simulate('click') | ||
|
||
spy.should.have.been.calledOnce() | ||
spy.should.have.been.calledWithMatch({}, { | ||
...expectProps, | ||
checked: !expectProps.checked, | ||
indeterminate: false, | ||
}) | ||
spy.should.have.been.calledWithMatch( | ||
{}, | ||
{ | ||
...expectProps, | ||
checked: !expectProps.checked, | ||
indeterminate: false, | ||
}, | ||
) | ||
}) | ||
it('is called once on input click when "id" prop is passed', () => { | ||
const onChange = sandbox.spy() | ||
|
@@ -260,15 +253,17 @@ describe('Checkbox', () => { | |
it('is called with (event { name, value, checked }) on label click', () => { | ||
const spy = sandbox.spy() | ||
const expectProps = { name: 'foo', value: 'bar', checked: false, indeterminate: true } | ||
mount(<Checkbox onClick={spy} {...expectProps} />) | ||
.simulate('click') | ||
mount(<Checkbox onClick={spy} {...expectProps} />).simulate('click') | ||
|
||
spy.should.have.been.calledOnce() | ||
spy.should.have.been.calledWithMatch({}, { | ||
...expectProps, | ||
checked: !expectProps.checked, | ||
indeterminate: expectProps.indeterminate, | ||
}) | ||
spy.should.have.been.calledWithMatch( | ||
{}, | ||
{ | ||
...expectProps, | ||
checked: !expectProps.checked, | ||
indeterminate: expectProps.indeterminate, | ||
}, | ||
) | ||
}) | ||
it('is called once on input click when "id" prop is passed', () => { | ||
const onClick = sandbox.spy() | ||
|
@@ -295,15 +290,17 @@ describe('Checkbox', () => { | |
it('is called with (event { name, value, checked }) on label mouse down', () => { | ||
const onMousedDown = sandbox.spy() | ||
const expectProps = { name: 'foo', value: 'bar', checked: false, indeterminate: true } | ||
mount(<Checkbox onMouseDown={onMousedDown} {...expectProps} />) | ||
.simulate('mousedown') | ||
mount(<Checkbox onMouseDown={onMousedDown} {...expectProps} />).simulate('mousedown') | ||
|
||
onMousedDown.should.have.been.calledOnce() | ||
onMousedDown.should.have.been.calledWithMatch({}, { | ||
...expectProps, | ||
checked: expectProps.checked, | ||
indeterminate: expectProps.indeterminate, | ||
}) | ||
onMousedDown.should.have.been.calledWithMatch( | ||
{}, | ||
{ | ||
...expectProps, | ||
checked: expectProps.checked, | ||
indeterminate: expectProps.indeterminate, | ||
}, | ||
) | ||
}) | ||
it('prevents default event', () => { | ||
const preventDefault = sandbox.spy() | ||
|
@@ -326,17 +323,13 @@ describe('Checkbox', () => { | |
wrapperShallow(<Checkbox readOnly />) | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.not.be.checked() | ||
wrapper.find('input').should.not.be.checked() | ||
}) | ||
it('cannot be unchecked', () => { | ||
wrapperShallow(<Checkbox defaultChecked readOnly />) | ||
|
||
wrapper.simulate('click') | ||
wrapper | ||
.find('input') | ||
.should.be.checked() | ||
wrapper.find('input').should.be.checked() | ||
}) | ||
}) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the actual change, passing disabled attribute to the input if set as a prop to Checkbox