-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core/presentation): Consolidate Checklist and ChecklistInput…
… components (#7077)
- Loading branch information
1 parent
9bbc002
commit 4e89a39
Showing
7 changed files
with
227 additions
and
245 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
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.