lucid-ui
Version:
A UI component library from AppNexus.
115 lines (114 loc) • 4.88 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import { shallow } from 'enzyme';
import React from 'react';
import TimeSelectHour from './TimeSelectHour';
import TimeSelectInput from './TimeSelectInput';
describe('TimeSelectHour', function () {
var props = {
hour: 5,
time: new Date(2020, 10, 3),
is24HourClock: false,
isAM: false,
isDisabled: false,
onChange: jest.fn()
};
var component;
beforeEach(function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, props));
});
it('should render a TimeSelectInput component with correct props', function () {
expect(component.find(TimeSelectInput).props()).toEqual({
className: 'lucid-TimeSelect-time-hour',
value: props.hour,
name: 'Hour',
onChange: expect.any(Function),
step: 1,
disabled: props.isDisabled
});
});
describe('when onChange is called', function () {
beforeEach(function () {
props.onChange.mockReset();
});
describe('and is24HourClock is true', function () {
describe('and is rolling over', function () {
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
is24HourClock: true
})));
component.find(TimeSelectInput).props().onChange('24');
expect(props.onChange).toBeCalledWith(new Date('2020-11-04T00:00:00'));
});
});
describe('and is rolling under', function () {
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
is24HourClock: true
})));
component.find(TimeSelectInput).props().onChange('-1');
expect(props.onChange).toBeCalledWith(new Date('2020-11-02T23:00:00'));
});
});
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
is24HourClock: true
})));
component.find(TimeSelectInput).props().onChange('18');
expect(props.onChange).toBeCalledWith(new Date('2020-11-03T18:00:00'));
});
});
describe('and is24HourClock is false', function () {
describe('and is am', function () {
describe('and is rolling over', function () {
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
hour: 11,
isAM: true
})));
component.find(TimeSelectInput).props().onChange('12');
expect(props.onChange).toBeCalledWith(new Date('2020-11-03T12:00:00'));
});
});
describe('and is rolling under', function () {
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
hour: 12,
isAM: false
})));
component.find(TimeSelectInput).props().onChange('11');
expect(props.onChange).toBeCalledWith(new Date('2020-11-03T11:00:00'));
});
});
});
describe('and is PM', function () {
describe('and is rolling over', function () {
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
hour: 11,
isAM: false
})));
component.find(TimeSelectInput).props().onChange('12');
expect(props.onChange).toBeCalledWith(new Date('2020-11-04T00:00:00'));
});
});
describe('and is rolling under', function () {
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
hour: 12,
isAM: true
})));
component.find(TimeSelectInput).props().onChange('11');
expect(props.onChange).toBeCalledWith(new Date('2020-11-02T23:00:00'));
});
});
});
it('should set the next hour', function () {
component = shallow( /*#__PURE__*/React.createElement(TimeSelectHour, _extends({}, props, {
hour: 4
})));
component.find(TimeSelectInput).props().onChange('5');
expect(props.onChange).toBeCalledWith(new Date('2020-11-03T17:00:00'));
});
});
});
});