Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 9ae2e26

Browse files
committed
test: #389 tests
1 parent a7b7bb0 commit 9ae2e26

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/components/InputRangeField/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InputRangeField extends Component {
5151

5252
InputRangeField.propTypes = {
5353
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
54-
label: PropTypes.oneOfType([PropTypes.element, PropTypes.node]).isRequired,
54+
label: PropTypes.oneOfType([PropTypes.element, PropTypes.node]).isRequired,
5555
placeholder: PropTypes.string,
5656
styles: PropTypes.shape({
5757
inputRange: PropTypes.string,

src/components/InputRangeField/index.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,40 @@ describe('InputRangeField tests', () => {
7272
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('placeholder')).toEqual('-');
7373
expect(wrapper.find(`.${styles.inputRangeLabel}`).text()).toEqual('Label');
7474
});
75+
76+
test('Should render the label as a Component', () => {
77+
const Label = () => <span className="input-range-field-label">Input label</span>;
78+
const wrapper = mount(
79+
<InputRangeField
80+
value={12}
81+
placeholder="Placeholder"
82+
label={<Label />}
83+
styles={styles}
84+
onChange={jest.fn()}
85+
onFocus={jest.fn()}
86+
onBlur={jest.fn()}
87+
/>
88+
);
89+
90+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('value')).toEqual(12);
91+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('placeholder')).toEqual('Placeholder');
92+
expect(wrapper.find(`.${styles.inputRangeLabel}`).text()).toEqual('Input label');
93+
expect(wrapper.find(`.${styles.inputRangeLabel}`).text()).toEqual('Input label');
94+
expect(wrapper.find(`.input-range-field-label`).text()).toEqual('Input label');
95+
96+
wrapper.setProps({ value: '32' });
97+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('value')).toEqual('32');
98+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('placeholder')).toEqual('Placeholder');
99+
expect(wrapper.find(`.${styles.inputRangeLabel}`).text()).toEqual('Input label');
100+
101+
wrapper.setProps({ placeholder: '-' });
102+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('value')).toEqual('32');
103+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('placeholder')).toEqual('-');
104+
expect(wrapper.find(`.${styles.inputRangeLabel}`).text()).toEqual('Input label');
105+
106+
wrapper.setProps({ label: 'Label' });
107+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('value')).toEqual('32');
108+
expect(wrapper.find(`.${styles.inputRangeInput}`).prop('placeholder')).toEqual('-');
109+
expect(wrapper.find(`.${styles.inputRangeLabel}`).text()).toEqual('Label');
110+
});
75111
});

0 commit comments

Comments
 (0)