-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(select): forward refs to select dom element
- Loading branch information
Showing
8 changed files
with
117 additions
and
63 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
__tests__/renderer/shared/components/Forms/LabeledSelect/LabeledSelect.test.js
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,32 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import LabeledSelect from 'shared/components/Forms/LabeledSelect'; | ||
import Label from 'shared/components/Forms/Label'; | ||
import Select from 'shared/components/Forms/Select'; | ||
|
||
const mountContainer = (props = {}) => { | ||
return mount(<LabeledSelect {...props} />); | ||
}; | ||
|
||
describe('<LabeledSelect />', () => { | ||
it('renders a label', () => { | ||
const wrapper = mountContainer({ id: 'currency', label: 'Currency' }); | ||
const label = wrapper.find(Label); | ||
expect(label.exists()).toBe(true); | ||
expect(label.props()).toEqual(expect.objectContaining({ label: 'Currency', htmlFor: 'currency' })); | ||
}); | ||
|
||
it('renders a select', () => { | ||
const children = ( | ||
<React.Fragment> | ||
<option value="USD">United States Dollar</option> | ||
<option value="EUR">Euro</option> | ||
</React.Fragment> | ||
); | ||
const wrapper = mountContainer({ id: 'currency', label: 'Currency', children }); | ||
const select = wrapper.find(Select); | ||
expect(select.exists()).toBe(true); | ||
expect(select.props()).toEqual(expect.objectContaining({ id: 'currency', children })); | ||
}); | ||
}); |
32 changes: 10 additions & 22 deletions
32
__tests__/renderer/shared/components/Forms/LabeledSelect/index.test.js
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,32 +1,20 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import LabeledSelect from 'shared/components/Forms/LabeledSelect'; | ||
import Label from 'shared/components/Forms/Label'; | ||
import Select from 'shared/components/Forms/Select'; | ||
import LabeledSelectContainer from 'shared/components/Forms/LabeledSelect'; | ||
import LabeledSelect from 'shared/components/Forms/LabeledSelect/LabeledSelect'; | ||
|
||
const mountContainer = (props = {}) => { | ||
return mount(<LabeledSelect {...props} />); | ||
return mount(<LabeledSelectContainer {...props} />); | ||
}; | ||
|
||
describe('<LabeledSelect />', () => { | ||
it('renders a label', () => { | ||
const wrapper = mountContainer({ id: 'currency', label: 'Currency' }); | ||
const label = wrapper.find(Label); | ||
expect(label.exists()).toBe(true); | ||
expect(label.props()).toEqual(expect.objectContaining({ label: 'Currency', htmlFor: 'currency' })); | ||
}); | ||
|
||
it('renders a select', () => { | ||
const children = ( | ||
<React.Fragment> | ||
<option value="USD">United States Dollar</option> | ||
<option value="EUR">Euro</option> | ||
</React.Fragment> | ||
); | ||
const wrapper = mountContainer({ id: 'currency', label: 'Currency', children }); | ||
const select = wrapper.find(Select); | ||
expect(select.exists()).toBe(true); | ||
expect(select.props()).toEqual(expect.objectContaining({ id: 'currency', children })); | ||
it('forwards the ref to the component', () => { | ||
const ref = React.createRef(); | ||
const wrapper = mountContainer({ ref }); | ||
console.log(wrapper.debug()); | ||
console.log(wrapper.find(LabeledSelect).props()); | ||
// expect(wrapper.find(LabeledSelect).prop('forwardedRef')).toBe(ref.current); | ||
// expect(wrapper.find(LabeledSelect).find('input').prop('forwardedRef')).toBe(ref.current); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
__tests__/renderer/shared/components/Forms/Select/Select.test.js
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,28 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Select from 'shared/components/Forms/Select/Select'; | ||
|
||
const mountContainer = (props = {}) => { | ||
return shallow(<Select {...props} />); | ||
}; | ||
|
||
describe('<Select />', () => { | ||
it('renders a select', () => { | ||
const children = ( | ||
<React.Fragment> | ||
<option value="foo">Foo</option> | ||
<option value="bar">Bar</option> | ||
</React.Fragment> | ||
); | ||
const props = { id: 'name', defaultValue: 'foo', children }; | ||
const wrapper = mountContainer(props); | ||
expect(wrapper.type()).toEqual('select'); | ||
expect(wrapper.props()).toEqual(expect.objectContaining(props)); | ||
}); | ||
|
||
it('applies a custom className', () => { | ||
const wrapper = mountContainer({ className: 'currency' }); | ||
expect(wrapper.prop('className').split(' ')).toContain('currency'); | ||
}); | ||
}); |
30 changes: 11 additions & 19 deletions
30
__tests__/renderer/shared/components/Forms/Select/index.test.js
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,28 +1,20 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { mount } from 'enzyme'; | ||
|
||
import Select from 'shared/components/Forms/Select'; | ||
import SelectContainer from 'shared/components/Forms/Select'; | ||
import Select from 'shared/components/Forms/Select/Select'; | ||
|
||
const mountContainer = (props = {}) => { | ||
return shallow(<Select {...props} />); | ||
return mount(<SelectContainer {...props} />); | ||
}; | ||
|
||
describe('<Select />', () => { | ||
it('renders a select', () => { | ||
const children = ( | ||
<React.Fragment> | ||
<option value="foo">Foo</option> | ||
<option value="bar">Bar</option> | ||
</React.Fragment> | ||
); | ||
const props = { id: 'name', defaultValue: 'foo', children }; | ||
const wrapper = mountContainer(props); | ||
expect(wrapper.type()).toEqual('select'); | ||
expect(wrapper.props()).toEqual(expect.objectContaining(props)); | ||
}); | ||
|
||
it('applies a custom className', () => { | ||
const wrapper = mountContainer({ className: 'currency' }); | ||
expect(wrapper.prop('className').split(' ')).toContain('currency'); | ||
it('forwards the ref to the component', () => { | ||
const ref = React.createRef(); | ||
const wrapper = mountContainer({ ref }); | ||
console.log(wrapper.debug()); | ||
console.log(wrapper.find(Select).props()); | ||
// expect(wrapper.find(Select).prop('forwardedRef')).toBe(ref.current); | ||
// expect(wrapper.find(Select).find('input').prop('forwardedRef')).toBe(ref.current); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export { default } from './LabeledSelect'; | ||
import withForwardedRef from 'shared/hocs/withForwardedRef'; | ||
|
||
import LabeledSelect from './LabeledSelect'; | ||
|
||
export default withForwardedRef()(LabeledSelect); |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export { default } from './Select'; | ||
import withForwardedRef from 'shared/hocs/withForwardedRef'; | ||
|
||
import Select from './Select'; | ||
|
||
export default withForwardedRef()(Select); |