Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Merge 17a62b8 into d00af87
Browse files Browse the repository at this point in the history
  • Loading branch information
knicklabs committed Aug 13, 2020
2 parents d00af87 + 17a62b8 commit 00c7cda
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/components/ChoiceGroup/ChoiceGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ChoiceGroup extends React.Component {
const { multiSelect, onChange } = this.props
const selectedValue = multiSelect
? this.getMultiSelectValue(value, checked)
: [value]
: value
const limitReached = this.getSelectLimitState(this.props, selectedValue)

this.setState({ selectedValue, limitReached })
Expand All @@ -104,7 +104,7 @@ class ChoiceGroup extends React.Component {
const { multiSelect, onEnter } = this.props
const selectedValue = multiSelect
? this.getMultiSelectValue(value, checked)
: [value]
: value
const limitReached = this.getSelectLimitState(this.props, selectedValue)

this.setState({ selectedValue, limitReached })
Expand Down
118 changes: 93 additions & 25 deletions src/components/ChoiceGroup/ChoiceGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ describe('ChoiceGroup', () => {
<Radio />
</ChoiceGroup>
)
const input = wrapper.find('.c-Radio').first().find('input')
const input = wrapper
.find('.c-Radio')
.first()
.find('input')

input.simulate('blur')

Expand All @@ -70,7 +73,10 @@ describe('ChoiceGroup', () => {
<Radio />
</ChoiceGroup>
)
const input = wrapper.find('.c-Radio').first().find('input')
const input = wrapper
.find('.c-Radio')
.first()
.find('input')

input.simulate('focus')

Expand All @@ -86,7 +92,10 @@ describe('ChoiceGroup', () => {
<Radio value="3" />
</ChoiceGroup>
)
const input = wrapper.find('.c-Radio').first().find('input')
const input = wrapper
.find('.c-Radio')
.first()
.find('input')

input.simulate('change', { target: { checked: true } })

Expand All @@ -102,7 +111,10 @@ describe('ChoiceGroup', () => {
<Radio value="3" />
</ChoiceGroup>
)
const input = wrapper.find('.c-Radio').first().find('input')
const input = wrapper
.find('.c-Radio')
.first()
.find('input')

input.simulate('keydown', { key: 'Enter' })

Expand All @@ -118,7 +130,10 @@ describe('ChoiceGroup', () => {
<Radio value="3" />
</ChoiceGroup>
)
const input = wrapper.find('.c-Radio').first().find('input')
const input = wrapper
.find('.c-Radio')
.first()
.find('input')

input.simulate('keyup', { key: ' ' })

Expand Down Expand Up @@ -162,9 +177,18 @@ describe('ChoiceGroup', () => {
<Checkbox value="mugatu" />
</ChoiceGroup>
)
const input = wrapper.find(Checkbox).at(0).find('input')
const input2 = wrapper.find(Checkbox).at(1).find('input')
const input3 = wrapper.find(Checkbox).at(2).find('input')
const input = wrapper
.find(Checkbox)
.at(0)
.find('input')
const input2 = wrapper
.find(Checkbox)
.at(1)
.find('input')
const input3 = wrapper
.find(Checkbox)
.at(2)
.find('input')

input.simulate('change', { target: { checked: true } })
expect(spy).toHaveBeenCalledWith(['derek'])
Expand All @@ -185,18 +209,27 @@ describe('ChoiceGroup', () => {
<Checkbox value="mugatu" />
</ChoiceGroup>
)
const input = wrapper.find(Checkbox).at(0).find('input')
const input2 = wrapper.find(Checkbox).at(1).find('input')
const input3 = wrapper.find(Checkbox).at(2).find('input')
const input = wrapper
.find(Checkbox)
.at(0)
.find('input')
const input2 = wrapper
.find(Checkbox)
.at(1)
.find('input')
const input3 = wrapper
.find(Checkbox)
.at(2)
.find('input')

input.simulate('change', { target: { checked: true } })
expect(spy).toHaveBeenCalledWith(['derek'])
expect(spy).toHaveBeenCalledWith('derek')

input2.simulate('change', { target: { checked: true } })
expect(spy).toHaveBeenCalledWith(['hansel'])
expect(spy).toHaveBeenCalledWith('hansel')

input3.simulate('change', { target: { checked: true } })
expect(spy).toHaveBeenCalledWith(['mugatu'])
expect(spy).toHaveBeenCalledWith('mugatu')
})
})

Expand Down Expand Up @@ -251,32 +284,53 @@ describe('ChoiceGroup', () => {
<Checkbox value="paul" />
</ChoiceGroup>
)
const input = wrapper.find(Checkbox).at(0).find('input')
const input2 = wrapper.find(Checkbox).at(1).find('input')
const input3 = wrapper.find(Checkbox).at(2).find('input')
const input = wrapper
.find(Checkbox)
.at(0)
.find('input')
const input2 = wrapper
.find(Checkbox)
.at(1)
.find('input')
const input3 = wrapper
.find(Checkbox)
.at(2)
.find('input')

input.simulate('change', { target: { checked: true } })
expect(wrapper.state('limitReached')).toBeFalsy()
expect(
wrapper.find('.c-ChoiceGroup').first().hasClass('limit-reached')
wrapper
.find('.c-ChoiceGroup')
.first()
.hasClass('limit-reached')
).toBeFalsy()

input2.simulate('change', { target: { checked: true } })
expect(wrapper.state('limitReached')).toBeFalsy()
expect(
wrapper.find('.c-ChoiceGroup').first().hasClass('limit-reached')
wrapper
.find('.c-ChoiceGroup')
.first()
.hasClass('limit-reached')
).toBeFalsy()

input3.simulate('change', { target: { checked: true } })
expect(wrapper.state('limitReached')).toBeTruthy()
expect(
wrapper.find('.c-ChoiceGroup').first().hasClass('limit-reached')
wrapper
.find('.c-ChoiceGroup')
.first()
.hasClass('limit-reached')
).toBeTruthy()

input2.simulate('change', { target: { checked: false } })
expect(wrapper.state('limitReached')).toBeFalsy()
expect(
wrapper.find('.c-ChoiceGroup').first().hasClass('limit-reached')
wrapper
.find('.c-ChoiceGroup')
.first()
.hasClass('limit-reached')
).toBeFalsy()
})

Expand All @@ -291,9 +345,18 @@ describe('ChoiceGroup', () => {
</ChoiceGroup>
)

const input = wrapper.find(Checkbox).at(0).find('input')
const input2 = wrapper.find(Checkbox).at(1).find('input')
const input3 = wrapper.find(Checkbox).at(2).find('input')
const input = wrapper
.find(Checkbox)
.at(0)
.find('input')
const input2 = wrapper
.find(Checkbox)
.at(1)
.find('input')
const input3 = wrapper
.find(Checkbox)
.at(2)
.find('input')

input.simulate('keyup', { key: ' ' })
expect(wrapper.state('limitReached')).toBeFalsy()
Expand All @@ -319,7 +382,12 @@ describe('ChoiceGroup', () => {
</ChoiceGroup>
)

expect(wrapper.find('input').first().props().name).toBe('MUGATU')
expect(
wrapper
.find('input')
.first()
.props().name
).toBe('MUGATU')
})
})

Expand Down

0 comments on commit 00c7cda

Please sign in to comment.