-
Notifications
You must be signed in to change notification settings - Fork 903
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
refactor(core/presentation): Consolidate Checklist and ChecklistInput components #7077
Merged
christopherthielen
merged 2 commits into
spinnaker:master
from
christopherthielen:checklist-input
Jun 4, 2019
Merged
Changes from all commits
Commits
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
129 changes: 0 additions & 129 deletions
129
app/scripts/modules/core/src/forms/checklist/Checklist.spec.tsx
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
app/scripts/modules/core/src/forms/checklist/Checklist.tsx
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './checklist/Checklist'; | ||
export * from './mapEditor/MapEditor'; |
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
126 changes: 126 additions & 0 deletions
126
app/scripts/modules/core/src/presentation/forms/inputs/ChecklistInput.spec.tsx
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,126 @@ | ||
import * as React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { ChecklistInput } from './ChecklistInput'; | ||
|
||
const noop = () => {}; | ||
|
||
describe('<ChecklistInput />', () => { | ||
it('initializes properly with provided values', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount(<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} />); | ||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(3); | ||
}); | ||
|
||
it('updates items when an item is added externally', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount(<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} />); | ||
|
||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(3); | ||
component.setProps({ stringOptions: options.concat('e') }); | ||
expect(component.find('input[type="checkbox"]').length).toBe(5); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(3); | ||
}); | ||
|
||
it('updates items when an item is removed externally', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount(<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} />); | ||
|
||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(3); | ||
component.setProps({ stringOptions: options.filter(item => item !== 'c') }); | ||
expect(component.find('input[type="checkbox"]').length).toBe(3); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(2); | ||
}); | ||
|
||
it('updates checked items when an item is checked externally', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount(<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} />); | ||
|
||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(3); | ||
component.setProps({ value: checkedOptions.concat('d') }); | ||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(4); | ||
}); | ||
|
||
it('updates checked items when an item is unchecked externally', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount(<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} />); | ||
|
||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(3); | ||
component.setProps({ value: checkedOptions.filter(item => item !== 'c') }); | ||
expect(component.find('input[type="checkbox"]').length).toBe(4); | ||
expect(component.find('input[type="checkbox"][checked=true]').length).toBe(2); | ||
}); | ||
|
||
it('shows the select all button when necessary', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount( | ||
<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} showSelectAll={true} />, | ||
); | ||
expect(component.find('a').length).toBe(1); | ||
}); | ||
|
||
it('does not show the select all button when necessary', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount( | ||
<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} showSelectAll={false} />, | ||
); | ||
expect(component.find('a').length).toBe(0); | ||
}); | ||
|
||
it('shows correct text for the select all button when not all the items are checked', () => { | ||
const checkedOptions = ['a', 'b', 'c']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount( | ||
<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} showSelectAll={true} />, | ||
); | ||
|
||
expect(component.find('a').text()).toBe('Select All'); | ||
}); | ||
|
||
it('shows correct text for the select all button when all the items are checked', () => { | ||
const checkedOptions = ['a', 'b', 'c', 'd']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const component = mount( | ||
<ChecklistInput value={checkedOptions} stringOptions={options} onChange={noop} showSelectAll={true} />, | ||
); | ||
|
||
expect(component.find('a').text()).toBe('Deselect All'); | ||
}); | ||
|
||
it('passes an empty list to the onChange handler when deselect all clicked', () => { | ||
const checkedOptions = ['a', 'b', 'c', 'd']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const onChange = (e: React.ChangeEvent<any>): void => { | ||
expect(e.target.value.length).toBe(0); | ||
}; | ||
const component = mount( | ||
<ChecklistInput value={checkedOptions} stringOptions={options} onChange={onChange} showSelectAll={true} />, | ||
); | ||
component.find('a').simulate('click'); | ||
}); | ||
|
||
it('passes a complete list to the onChange handler when select all clicked', () => { | ||
const checkedOptions = ['a']; | ||
const options = ['a', 'b', 'c', 'd']; | ||
const onChange = (e: React.ChangeEvent<any>): void => { | ||
expect(e.target.value.length).toBe(4); | ||
}; | ||
const component = mount( | ||
<ChecklistInput value={checkedOptions} stringOptions={options} onChange={onChange} showSelectAll={true} />, | ||
); | ||
component.find('a').simulate('click'); | ||
}); | ||
}); |
Oops, something went wrong.
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.
thank Justin for these tests