Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tap performance followup, fixes and specs #414

Merged
merged 2 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/utils/isSameDay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ import moment from 'moment';

export default function isSameDay(a, b) {
if (!moment.isMoment(a) || !moment.isMoment(b)) return false;
// Speeding up by comparing most likely to differ unit first
return a.day() === b.day() &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moment's day of month function is .date() 😓

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why are we changing this back completely

a.month() === b.month() &&
a.year() === b.year();
return a.isSame(b, 'day');
}
76 changes: 76 additions & 0 deletions test/components/DayPickerRangeController_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DayPickerRangeController from '../../src/components/DayPickerRangeControl
import DayPicker from '../../src/components/DayPicker';

import isInclusivelyAfterDay from '../../src/utils/isInclusivelyAfterDay';
import * as isTouchDeviceModule from '../../src/utils/isTouchDevice';

import { START_DATE, END_DATE } from '../../constants';

Expand Down Expand Up @@ -776,4 +777,79 @@ describe('DayPickerRangeController', () => {
});
});
});

describe('modifier optimization', () => {
it('includes hover modifiers for non-touch device', () => {
sinon.stub(isTouchDeviceModule, 'default', () => false);

const wrapper = shallow(<DayPickerRangeController />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.include.keys('hovered');
expect(modifiers).to.include.keys('hovered-span');
expect(modifiers).to.include.keys('after-hovered-start');
});

it('excludes hover modifiers for touch device', () => {
sinon.stub(isTouchDeviceModule, 'default', () => true);

const wrapper = shallow(<DayPickerRangeController />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.not.include.keys('hovered');
expect(modifiers).to.not.include.keys('hovered-span');
expect(modifiers).to.not.include.keys('after-hovered-start');
});

it('includes start modifiers when startDate is set', () => {
const wrapper = shallow(<DayPickerRangeController startDate={moment()} />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.include.keys('selected-start');
});

it('excludes start modifiers when startDate is unset', () => {
const wrapper = shallow(<DayPickerRangeController />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.not.include.keys('selected-start');
});

it('includes end modifiers when endDate is set', () => {
const wrapper = shallow(<DayPickerRangeController endDate={moment()} />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.include.keys('selected-end');
expect(modifiers).to.include.keys('blocked-minimum-nights');
});

it('excludes end modifiers when endDate is unset', () => {
const wrapper = shallow(<DayPickerRangeController />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.not.include.keys('selected-end');
expect(modifiers).to.not.include.keys('blocked-minimum-nights');
});

it('includes start/end modifiers when both set', () => {
const wrapper = shallow(
<DayPickerRangeController
startDate={moment()}
endDate={moment().add(1, 'days')}
/>,
);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.include.keys('selected-span');
expect(modifiers).to.include.keys('last-in-range');
});

it('excludes start/end modifiers when both unset', () => {
const wrapper = shallow(<DayPickerRangeController />);

const modifiers = wrapper.find(DayPicker).prop('modifiers');
expect(modifiers).to.not.include.keys('selected-span');
expect(modifiers).to.not.include.keys('last-in-range');
});
});
});