Skip to content

Commit 0718c79

Browse files
committed
update tests
1 parent 5071e9d commit 0718c79

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/components/DayPickerNavigation.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function DayPickerNavigation({
228228
onNextMonthClick(e)
229229
};
230230
},
231-
onMouseUp: disableNext ? undefined : e => {
231+
onMouseUp: disableNext ? undefined : (e) => {
232232
e.currentTarget.blur();
233233
},
234234
})

test/components/DayPickerRangeController_spec.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,11 +4167,11 @@ describe('DayPickerRangeController', () => {
41674167

41684168
it('return value now has modifier arg for day after getting previous scrollable months', () => {
41694169
const modifierToAdd = 'foo';
4170-
const pastDateAfterMultiply = today.clone().subtract(4, 'months');
4170+
const pastDateAfterMultiply = today.clone().subtract(3, 'months');
41714171
const monthISO = toISOMonthString(pastDateAfterMultiply);
4172-
const todayISO = toISODateString(pastDateAfterMultiply);
4172+
const dayISO = toISODateString(pastDateAfterMultiply);
41734173
const updatedDays = {
4174-
[monthISO]: { [todayISO]: new Set(['bar', 'baz']) },
4174+
[monthISO]: { [dayISO]: new Set(['bar', 'baz']) },
41754175
};
41764176
const wrapper = shallow((
41774177
<DayPickerRangeController
@@ -4182,10 +4182,10 @@ describe('DayPickerRangeController', () => {
41824182
/>
41834183
)).instance();
41844184
let modifiers = wrapper.addModifier(updatedDays, pastDateAfterMultiply, modifierToAdd);
4185-
expect(Array.from(modifiers[monthISO][todayISO])).to.not.contain(modifierToAdd);
4186-
wrapper.onGetPreviousScrollableMonths();
4185+
expect(Array.from(modifiers[monthISO][dayISO])).to.not.contain(modifierToAdd);
4186+
wrapper.onGetPrevScrollableMonths();
41874187
modifiers = wrapper.addModifier(updatedDays, pastDateAfterMultiply, modifierToAdd);
4188-
expect(Array.from(modifiers[monthISO][todayISO])).to.contain(modifierToAdd);
4188+
expect(Array.from(modifiers[monthISO][dayISO])).to.contain(modifierToAdd);
41894189
});
41904190

41914191
describe('#addModifierToRange', () => {

test/components/DayPicker_spec.jsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import sinon from 'sinon-sandbox';
55
import { mount, shallow } from 'enzyme';
66

77
import * as isDayVisible from '../../src/utils/isDayVisible';
8+
import isSameMonth from '../../src/utils/isSameMonth';
89

910
import DayPicker, { PureDayPicker } from '../../src/components/DayPicker';
1011
import CalendarMonthGrid from '../../src/components/CalendarMonthGrid';
@@ -221,17 +222,21 @@ describe('DayPicker', () => {
221222
<DayPicker orientation={VERTICAL_SCROLLABLE} />,
222223
{ disableLifecycleMethods: false },
223224
).dive();
224-
const nav = wrapper.find(DayPickerNavigation)[1];
225-
expect(nav.prop('onNextMonthClick')).to.equal(wrapper.instance().getNextScrollableMonths);
225+
expect(wrapper.find(DayPickerNavigation)).to.have.length(2);
226+
const nav = wrapper.find(DayPickerNavigation).get(1);
227+
console.log(nav);
228+
expect(nav.props.onNextMonthClick).to.equal(wrapper.instance().getNextScrollableMonths);
226229
});
227230

228231
it('uses getPrevScrollableMonths instead of onNextMonthClick', () => {
229232
const wrapper = shallow(
230233
<DayPicker orientation={VERTICAL_SCROLLABLE} />,
231234
{ disableLifecycleMethods: false },
232235
).dive();
233-
const nav = wrapper.find(DayPickerNavigation)[0];
234-
expect(nav.prop('onPrevMonthClick')).to.equal(wrapper.instance().getPrevScrollableMonths);
236+
expect(wrapper.find(DayPickerNavigation)).to.have.length(2);
237+
const nav = wrapper.find(DayPickerNavigation).get(0);
238+
console.log(nav);
239+
expect(nav.props.onPrevMonthClick).to.equal(wrapper.instance().getPrevScrollableMonths);
235240
});
236241
});
237242

@@ -818,26 +823,14 @@ describe('DayPicker', () => {
818823
wrapper.instance().getNextScrollableMonths(event);
819824
expect(wrapper.state().scrollableMonthMultiple).to.equal(2);
820825
});
821-
822-
it('increments scrollableMonthMultiple without an event', () => {
823-
const wrapper = shallow(<DayPicker />).dive();
824-
wrapper.instance().getNextScrollableMonths();
825-
expect(wrapper.state().scrollableMonthMultiple).to.equal(2);
826-
});
827826
});
828827

829828
describe('#getPrevScrollableMonths', () => {
830-
it('increments scrollableMonthMultiple', () => {
831-
const wrapper = shallow(<DayPicker />).dive();
832-
wrapper.instance().getPrevScrollableMonths(event);
833-
expect(wrapper.state().scrollableMonthMultiple).to.equal(2);
834-
});
835-
836-
it('increments scrollableMonthMultiple without an event', () => {
829+
it('increments scrollableMonthMultiple and updates currentMonth', () => {
837830
const wrapper = shallow(<DayPicker />).dive();
838831
wrapper.instance().getPrevScrollableMonths();
839832
expect(wrapper.state().scrollableMonthMultiple).to.equal(2);
840-
expect(wrapper.state().currentMonth).to.equal(moment().subtract(1, 'month'));
833+
expect(isSameMonth(wrapper.state().currentMonth, moment().subtract(2, 'month'))).to.equal(true);
841834
});
842835
});
843836

0 commit comments

Comments
 (0)