lucid-ui
Version:
A UI component library from AppNexus.
122 lines • 5.73 kB
JavaScript
import { shallow } from 'enzyme';
import React from 'react';
import { common, mockDate } from '../../util/generic-tests';
import CalendarMonth from './CalendarMonth';
describe('CalendarMonth', function () {
describe('common tests', function () {
beforeEach(function () {
mockDate('2016-02-17T14:25:23-0800');
});
afterEach(function () {
mockDate.restore();
});
common(CalendarMonth);
});
describe('modifierRange', function () {
it('`cursor` date should be in range', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
selectMode: "day",
cursor: new Date('2017-02-14T00:00:00Z')
}));
var calendarMonthInstance = wrapper.instance();
var isInRange = calendarMonthInstance.modifierRange(new Date('2017-02-14T00:00:00Z'));
expect(isInRange).toBe(true);
});
it('dates between `from` and `cursor` should be in range', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
selectMode: "to",
from: new Date('2017-02-12T00:00:00Z'),
cursor: new Date('2017-02-14T00:00:00Z')
}));
var calendarMonthInstance = wrapper.instance();
var isInRange11 = calendarMonthInstance.modifierRange(new Date('2017-02-11T00:00:00Z'));
var isInRange12 = calendarMonthInstance.modifierRange(new Date('2017-02-12T00:00:00Z'));
var isInRange13 = calendarMonthInstance.modifierRange(new Date('2017-02-13T00:00:00Z'));
var isInRange14 = calendarMonthInstance.modifierRange(new Date('2017-02-14T00:00:00Z'));
var isInRange15 = calendarMonthInstance.modifierRange(new Date('2017-02-15T00:00:00Z'));
expect(isInRange11).toBeFalsy();
expect(isInRange12).toBe(true);
expect(isInRange13).toBe(true);
expect(isInRange14).toBe(true);
expect(isInRange15).toBeFalsy();
});
it('`cursor` date should only date in range if `from` or `to` not set', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
selectMode: "from",
from: null,
to: null,
cursor: new Date('2017-02-14T00:00:00Z')
}));
var calendarMonthInstance = wrapper.instance();
var isInRange13 = calendarMonthInstance.modifierRange(new Date('2017-02-13T00:00:00Z'));
var isInRange14 = calendarMonthInstance.modifierRange(new Date('2017-02-14T00:00:00Z'));
var isInRange15 = calendarMonthInstance.modifierRange(new Date('2017-02-15T00:00:00Z'));
expect(isInRange13).toBeFalsy();
expect(isInRange14).toBe(true);
expect(isInRange15).toBeFalsy();
});
it('dates should in range between `from` and `to` without `cursor`', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
selectMode: "to",
from: new Date('2017-02-12T00:00:00Z'),
to: new Date('2017-02-14T00:00:00Z')
}));
var calendarMonthInstance = wrapper.instance();
var isInRange11 = calendarMonthInstance.modifierRange(new Date('2017-02-11T00:00:00Z'));
var isInRange12 = calendarMonthInstance.modifierRange(new Date('2017-02-12T00:00:00Z'));
var isInRange13 = calendarMonthInstance.modifierRange(new Date('2017-02-13T00:00:00Z'));
var isInRange14 = calendarMonthInstance.modifierRange(new Date('2017-02-14T00:00:00Z'));
var isInRange15 = calendarMonthInstance.modifierRange(new Date('2017-02-15T00:00:00Z'));
expect(isInRange11).toBeFalsy();
expect(isInRange12).toBe(true);
expect(isInRange13).toBe(true);
expect(isInRange14).toBe(true);
expect(isInRange15).toBeFalsy();
});
it('should return false if no cursor or range dates', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
cursor: null
}));
var calendarMonthInstance = wrapper.instance();
var isInRange = calendarMonthInstance.modifierRange(new Date('2017-02-14T00:00:00Z'));
expect(isInRange).toBe(false);
});
});
describe('modifierFrom', function () {
it('should mark `from` day', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
from: new Date('2017-02-14T00:00:00Z')
}));
var calendarMonthInstance = wrapper.instance();
var isFromDate = calendarMonthInstance.modifierFrom(new Date('2017-02-14T00:00:00Z'));
expect(isFromDate).toBe(true);
});
});
describe('modifierTo', function () {
it('should mark `to` day', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
initialMonth: new Date('2017-02-01:00:00Z'),
to: new Date('2017-02-14T00:00:00Z')
}));
var calendarMonthInstance = wrapper.instance();
var isToDate = calendarMonthInstance.modifierTo(new Date('2017-02-14T00:00:00Z'));
expect(isToDate).toBe(true);
});
});
describe('shouldComponentUpdate', function () {
it('should determine shouldComponentUpdate by using prop value', function () {
var wrapper = shallow( /*#__PURE__*/React.createElement(CalendarMonth, {
shouldComponentUpdate: true
}));
var calendarMonthInstance = wrapper.instance();
var shouldComponentUpdate = calendarMonthInstance.shouldComponentUpdate();
expect(shouldComponentUpdate).toBe(true);
});
});
});