Skip to content

Commit 7dac5c7

Browse files
committed
chore: Add AI recommended change (non critical)
1 parent 5ca5b7d commit 7dac5c7

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/components/summit-dropdown/__tests__/summit-dropdown.test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,31 @@ describe('SummitDropdown summitValue state', () => {
4545

4646
test('handleChange does not set summitValue when given a non-object', () => {
4747
const wrapper = render();
48+
const option = { label: 'Summit A', value: 1 };
49+
const invalidOption = 'not-an-object';
4850

49-
wrapper.instance().handleChange('not-an-object');
50-
51+
wrapper.instance().handleChange(invalidOption);
5152
expect(wrapper.instance().state.summitValue).toBeNull();
53+
54+
wrapper.instance().handleChange(option);
55+
expect(wrapper.instance().state.summitValue).toEqual(option);
56+
57+
wrapper.instance().handleChange(invalidOption);
58+
expect(wrapper.instance().state.summitValue).toEqual(option);
5259
});
5360

5461
test('handleChange does not set summitValue when given null', () => {
5562
const wrapper = render();
63+
const option = { label: 'Summit A', value: 1 };
5664

5765
wrapper.instance().handleChange(null);
58-
5966
expect(wrapper.instance().state.summitValue).toBeNull();
67+
68+
wrapper.instance().handleChange(option);
69+
expect(wrapper.instance().state.summitValue).toEqual(option);
70+
71+
wrapper.instance().handleChange(null);
72+
expect(wrapper.instance().state.summitValue).toEqual(option);
6073
});
6174

6275
test('handleClick does not call onClick when summitValue is null', () => {

src/components/summit-dropdown/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@ export default class SummitDropdown extends React.Component {
3131
}
3232

3333
handleChange(summit) {
34-
if (typeof summit === OBJECT_TYPEOF)
35-
this.setState({summitValue: summit});
34+
const summitValue =
35+
summit !== null &&
36+
typeof summit === OBJECT_TYPEOF &&
37+
typeof summit.value !== UNDEFINED_TYPEOF
38+
? summit
39+
: this.state.summitValue;
40+
41+
this.setState({ summitValue });
3642
}
3743

3844
handleClick(ev) {
3945
ev.preventDefault();
4046
if (
41-
typeof this.state.summitValue === OBJECT_TYPEOF &&
42-
typeof this.state.summitValue?.value !== UNDEFINED_TYPEOF
47+
this.state.summitValue !== null &&
48+
typeof this.state.summitValue === OBJECT_TYPEOF &&
49+
typeof this.state.summitValue.value !== UNDEFINED_TYPEOF
4350
)
4451
this.props.onClick(this.state.summitValue.value);
4552
}
@@ -52,7 +59,10 @@ export default class SummitDropdown extends React.Component {
5259
(a, b) => (a.start_date < b.start_date ? 1 : (a.start_date > b.start_date ? -1 : 0))
5360
).map(s => ({label: s.name, value: s.id}));
5461

55-
const isDisabled = typeof this.state.summitValue !== OBJECT_TYPEOF || this.state.summitValue === null;
62+
const isDisabled =
63+
this.state.summitValue === null ||
64+
typeof this.state.summitValue !== OBJECT_TYPEOF ||
65+
typeof this.state.summitValue.value === UNDEFINED_TYPEOF;
5666

5767
return (
5868
<div className={"summit-dropdown btn-group " + bigClass}>

0 commit comments

Comments
 (0)