react-date-time-group
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -5,2 +5,24 @@ 'use strict'; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactTimeSelect = require('react-time-select'); | ||
var _reactTimeSelect2 = _interopRequireDefault(_reactTimeSelect); | ||
var _reactDatepicker = require('react-datepicker'); | ||
var _reactDatepicker2 = _interopRequireDefault(_reactDatepicker); | ||
var _moment = require('moment'); | ||
var _moment2 = _interopRequireDefault(_moment); | ||
var _propTypes = require('prop-types'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -12,8 +34,2 @@ | ||
var React = require('react'); | ||
var TimePicker = require('react-time-select'); | ||
var DatePicker = require('react-datepicker'); | ||
var moment = require('moment'); | ||
var PropTypes = require('prop-types'); | ||
var DateTimeGroup = function (_React$Component) { | ||
@@ -36,3 +52,2 @@ _inherits(DateTimeGroup, _React$Component); | ||
value: function timeChanged(time) { | ||
this.props.time.hours = time.hours; | ||
@@ -70,3 +85,3 @@ this.props.time.minutes = time.minutes; | ||
return this.props.dateExclusions.map(function (date) { | ||
return moment(date); | ||
return (0, _moment2.default)(date); | ||
}); | ||
@@ -77,8 +92,8 @@ } | ||
value: function render() { | ||
var timePickerColumn = React.createElement('span', null); | ||
var timePickerColumn = _react2.default.createElement('span', null); | ||
if (this.props.includeTime) { | ||
timePickerColumn = React.createElement( | ||
timePickerColumn = _react2.default.createElement( | ||
'div', | ||
{ className: this.props.timeContainerClass }, | ||
React.createElement(TimePicker, { | ||
_react2.default.createElement(_reactTimeSelect2.default, { | ||
className: this.props.timeClassName, | ||
@@ -100,9 +115,9 @@ label: this.props.timeLabel, | ||
return React.createElement( | ||
return _react2.default.createElement( | ||
'div', | ||
null, | ||
React.createElement( | ||
_react2.default.createElement( | ||
'div', | ||
{ className: this.props.dateContainerClass }, | ||
this.props.dateLabel ? React.createElement( | ||
this.props.dateLabel ? _react2.default.createElement( | ||
'label', | ||
@@ -113,3 +128,3 @@ { | ||
}, | ||
React.createElement( | ||
_react2.default.createElement( | ||
'span', | ||
@@ -120,3 +135,3 @@ null, | ||
) : '', | ||
React.createElement(DatePicker, { | ||
_react2.default.createElement(_reactDatepicker2.default, { | ||
fixedHeight: true, | ||
@@ -126,6 +141,6 @@ showMonthDropdown: this.props.showMonthDropdown, | ||
name: this.props.dateName, | ||
selected: moment(this.props.value), | ||
selected: (0, _moment2.default)(this.props.value), | ||
onChange: this.dateChanged, | ||
minDate: this.props.dateStart ? moment(this.props.dateStart) : null, | ||
maxDate: this.props.dateEnd ? moment(this.props.dateEnd) : null, | ||
minDate: this.props.dateStart ? (0, _moment2.default)(this.props.dateStart) : null, | ||
maxDate: this.props.dateEnd ? (0, _moment2.default)(this.props.dateEnd) : null, | ||
excludeDates: this.dateExclusions(), | ||
@@ -145,34 +160,34 @@ dateFormat: this.props.dateFormat, | ||
return DateTimeGroup; | ||
}(React.Component); | ||
}(_react2.default.Component); | ||
DateTimeGroup.propTypes = { | ||
includeTime: PropTypes.bool, | ||
timeClassName: PropTypes.string, | ||
timeLabel: PropTypes.string, | ||
timeName: PropTypes.string, | ||
value: PropTypes.instanceOf(Date), | ||
onChange: PropTypes.func, | ||
onTimeChange: PropTypes.func, | ||
timeStart: PropTypes.number, | ||
time: PropTypes.shape({ | ||
hours: PropTypes.string, | ||
minutes: PropTypes.string | ||
includeTime: _propTypes2.default.bool, | ||
timeClassName: _propTypes2.default.string, | ||
timeLabel: _propTypes2.default.string, | ||
timeName: _propTypes2.default.string, | ||
value: _propTypes2.default.instanceOf(Date), | ||
onChange: _propTypes2.default.func, | ||
onTimeChange: _propTypes2.default.func, | ||
timeStart: _propTypes2.default.number, | ||
time: _propTypes2.default.shape({ | ||
hours: _propTypes2.default.string, | ||
minutes: _propTypes2.default.string | ||
}), | ||
timeEnd: PropTypes.number, | ||
timeStep: PropTypes.number, | ||
dateName: PropTypes.string, | ||
dateLabel: PropTypes.string, | ||
dateStart: PropTypes.instanceOf(Date), | ||
dateEnd: PropTypes.instanceOf(Date), | ||
dateFormat: PropTypes.string, | ||
dateExclusions: PropTypes.array, | ||
locale: PropTypes.string, | ||
timeContainerClass: PropTypes.string, | ||
dateContainerClass: PropTypes.string, | ||
readOnly: PropTypes.bool, | ||
dateId: PropTypes.string, | ||
timeId: PropTypes.string, | ||
seperateHourMins: PropTypes.bool, | ||
showMonthDropdown: PropTypes.bool, | ||
showYearDropdown: PropTypes.bool | ||
timeEnd: _propTypes2.default.number, | ||
timeStep: _propTypes2.default.number, | ||
dateName: _propTypes2.default.string, | ||
dateLabel: _propTypes2.default.string, | ||
dateStart: _propTypes2.default.instanceOf(Date), | ||
dateEnd: _propTypes2.default.instanceOf(Date), | ||
dateFormat: _propTypes2.default.string, | ||
dateExclusions: _propTypes2.default.array, | ||
locale: _propTypes2.default.string, | ||
timeContainerClass: _propTypes2.default.string, | ||
dateContainerClass: _propTypes2.default.string, | ||
readOnly: _propTypes2.default.bool, | ||
dateId: _propTypes2.default.string, | ||
timeId: _propTypes2.default.string, | ||
seperateHourMins: _propTypes2.default.bool, | ||
showMonthDropdown: _propTypes2.default.bool, | ||
showYearDropdown: _propTypes2.default.bool | ||
}; | ||
@@ -179,0 +194,0 @@ |
@@ -1,11 +0,11 @@ | ||
'use strict'; | ||
'use strict' | ||
var React = require('react'); | ||
var ReactDOM = require('react-dom'); | ||
var DateTimeGroup = require('../src/DateTimeGroup.jsx'); | ||
var myDate = new Date('2015-05-05T09:00'); | ||
var React = require('react') | ||
var ReactDOM = require('react-dom') | ||
var DateTimeGroup = require('../src/DateTimeGroup.jsx') | ||
var myDate = new Date('2015-05-05T09:00') | ||
var myRestrictedDate = new Date('2015-05-10T09:00'); | ||
var minDate = new Date('2015-05-03T00:00'); | ||
var maxDate = new Date('2015-05-16T00:00'); | ||
var myRestrictedDate = new Date('2015-05-10T09:00') | ||
var minDate = new Date('2015-05-03T00:00') | ||
var maxDate = new Date('2015-05-16T00:00') | ||
var excludedDates = [ | ||
@@ -16,12 +16,12 @@ new Date('2015-05-05T00:00'), | ||
new Date('2015-05-15T00:00') | ||
]; | ||
] | ||
var fns = {}; | ||
var fns = {} | ||
fns.changeDate = function(newDate) { | ||
myDate = newDate; | ||
fns.render(); | ||
}; | ||
fns.changeDate = function (newDate) { | ||
myDate = newDate | ||
fns.render() | ||
} | ||
fns.render = function() { | ||
fns.render = function () { | ||
ReactDOM.render( | ||
@@ -38,15 +38,15 @@ <div> | ||
value={myRestrictedDate} | ||
dateClassName="myClass" | ||
dateLabel="Choose a date" | ||
dateName="TheDate" | ||
dateClassName='myClass' | ||
dateLabel='Choose a date' | ||
dateName='TheDate' | ||
dateStart={minDate} | ||
dateEnd={maxDate} | ||
dateExclusions={excludedDates} | ||
dateFormat="MMMM Do YYYY" | ||
dateContainerClass="col-xs-12 col-md-8" | ||
timeContainerClass="col-xs-12 col-md-4" | ||
dateId="dateWithDateOptions" | ||
timeId="timeWithDateOptions" | ||
showMonthDropdown={true} | ||
showYearDropdown={true} /> | ||
dateFormat='MMMM Do YYYY' | ||
dateContainerClass='col-xs-12 col-md-8' | ||
timeContainerClass='col-xs-12 col-md-4' | ||
dateId='dateWithDateOptions' | ||
timeId='timeWithDateOptions' | ||
showMonthDropdown | ||
showYearDropdown /> | ||
@@ -57,12 +57,12 @@ <h1>Options for time (value shared with "Events")</h1> | ||
onChange={fns.changeDate} | ||
timeClassName="myClass" | ||
timeLabel="Choose a time" | ||
timeName="TheTime" | ||
timeClassName='myClass' | ||
timeLabel='Choose a time' | ||
timeName='TheTime' | ||
timeStart={330} | ||
timeEnd={2130} | ||
timeStep={15} | ||
dateContainerClass="col-xs-12 col-md-8" | ||
timeContainerClass="col-xs-12 col-md-4" | ||
dateId="dateWithTimeOptions" | ||
timeId="timeWithTimeOptions" /> | ||
dateContainerClass='col-xs-12 col-md-8' | ||
timeContainerClass='col-xs-12 col-md-4' | ||
dateId='dateWithTimeOptions' | ||
timeId='timeWithTimeOptions' /> | ||
@@ -73,9 +73,9 @@ <h1>Events (value shared with "Options for time")</h1> | ||
<h1>Localization (Incomplete)</h1> | ||
<DateTimeGroup onChange={fns.changeDate} locales="en-US" /> | ||
<DateTimeGroup onChange={fns.changeDate} locales='en-US' /> | ||
</div> | ||
, | ||
document.getElementById('container') | ||
); | ||
}; | ||
) | ||
} | ||
fns.render(); | ||
fns.render() |
{ | ||
"name": "react-date-time-group", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Datepicker with optional time", | ||
@@ -14,3 +14,3 @@ "main": "dist/DateTimeGroup.js", | ||
"test": "mocha --require react-tests-globals-setup --compilers js:babel-core/register test/test*", | ||
"lint": "make-up src test doc" | ||
"lint": "standard --env mocha" | ||
}, | ||
@@ -50,3 +50,2 @@ "author": "Ollie Buck <ollie.buck@holidayextras.com>", | ||
"less": "2.7.2", | ||
"make-up": "^10.0.0", | ||
"mocha": "^2.3.3", | ||
@@ -58,4 +57,5 @@ "react": "16.7.0", | ||
"sinon": "^1.17.1", | ||
"standard": "^12.0.1", | ||
"watchify": "^3.4.0" | ||
} | ||
} |
@@ -1,54 +0,51 @@ | ||
'use strict'; | ||
import React from 'react' | ||
import TimePicker from 'react-time-select' | ||
import DatePicker from 'react-datepicker' | ||
import moment from 'moment' | ||
import PropTypes from 'prop-types' | ||
var React = require('react'); | ||
var TimePicker = require('react-time-select'); | ||
var DatePicker = require('react-datepicker'); | ||
var moment = require('moment'); | ||
var PropTypes = require('prop-types'); | ||
class DateTimeGroup extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.timeChanged = this.timeChanged.bind(this); | ||
this.dateChanged = this.dateChanged.bind(this); | ||
this.dateExclusions = this.dateExclusions.bind(this); | ||
constructor (props) { | ||
super(props) | ||
this.timeChanged = this.timeChanged.bind(this) | ||
this.dateChanged = this.dateChanged.bind(this) | ||
this.dateExclusions = this.dateExclusions.bind(this) | ||
} | ||
timeChanged(time) { | ||
timeChanged (time) { | ||
this.props.time.hours = time.hours | ||
this.props.time.minutes = time.minutes | ||
this.props.time.hours = time.hours; | ||
this.props.time.minutes = time.minutes; | ||
const newDate = this.props.value | ||
newDate.setHours(time.hours) | ||
newDate.setMinutes(time.minutes) | ||
const newDate = this.props.value; | ||
newDate.setHours(time.hours); | ||
newDate.setMinutes(time.minutes); | ||
if (this.props.onTimeChange) { | ||
this.props.onTimeChange(newDate); | ||
this.props.onTimeChange(newDate) | ||
} | ||
if (this.props.onChange) { | ||
this.props.onChange(newDate); | ||
this.props.onChange(newDate) | ||
} | ||
} | ||
dateChanged(newMoment) { | ||
dateChanged (newMoment) { | ||
if (this.props.onChange) { | ||
var newDate = newMoment.toDate(); | ||
newDate.setHours(this.props.time.hours, this.props.time.minutes, 0, 0); | ||
var newDate = newMoment.toDate() | ||
newDate.setHours(this.props.time.hours, this.props.time.minutes, 0, 0) | ||
this.props.onChange(newDate); | ||
this.props.onChange(newDate) | ||
} | ||
} | ||
dateExclusions() { | ||
dateExclusions () { | ||
if (!this.props.dateExclusions) { | ||
return null; | ||
return null | ||
} | ||
return this.props.dateExclusions.map(function(date) { | ||
return moment(date); | ||
}); | ||
return this.props.dateExclusions.map(function (date) { | ||
return moment(date) | ||
}) | ||
} | ||
render() { | ||
var timePickerColumn = <span />; | ||
render () { | ||
var timePickerColumn = <span /> | ||
if (this.props.includeTime) { | ||
@@ -72,3 +69,3 @@ timePickerColumn = ( | ||
</div> | ||
); | ||
) | ||
} | ||
@@ -79,5 +76,5 @@ | ||
<div className={this.props.dateContainerClass}> | ||
{this.props.dateLabel ? | ||
<label | ||
className="control-label" | ||
{this.props.dateLabel | ||
? <label | ||
className='control-label' | ||
htmlFor={this.props.dateId} | ||
@@ -89,3 +86,3 @@ > | ||
<DatePicker | ||
fixedHeight={true} | ||
fixedHeight | ||
showMonthDropdown={this.props.showMonthDropdown} | ||
@@ -101,3 +98,3 @@ showYearDropdown={this.props.showYearDropdown} | ||
locales={this.props.locale} | ||
className="form-control datepicker__input" | ||
className='form-control datepicker__input' | ||
readOnly={this.props.readOnly} | ||
@@ -109,3 +106,3 @@ id={this.props.dateId} | ||
</div> | ||
); | ||
) | ||
} | ||
@@ -144,6 +141,6 @@ } | ||
showYearDropdown: PropTypes.bool | ||
}; | ||
} | ||
var defaultDate = new Date(); | ||
defaultDate.setHours(12, 0, 0, 0); | ||
var defaultDate = new Date() | ||
defaultDate.setHours(12, 0, 0, 0) | ||
@@ -160,4 +157,4 @@ DateTimeGroup.defaultProps = { | ||
} | ||
}; | ||
} | ||
module.exports = DateTimeGroup; | ||
module.exports = DateTimeGroup |
@@ -1,38 +0,38 @@ | ||
'use strict'; | ||
'use strict' | ||
var React = require('react'); | ||
var TestUtils = require('react-dom/test-utils'); | ||
var TimePicker = require('react-time-select'); | ||
var DatePicker = require('react-datepicker'); | ||
var moment = require('moment'); | ||
var React = require('react') | ||
var TestUtils = require('react-dom/test-utils') | ||
var TimePicker = require('react-time-select') | ||
var DatePicker = require('react-datepicker') | ||
var moment = require('moment') | ||
var expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
var expect = require('chai').expect | ||
var sinon = require('sinon') | ||
var { shallow, configure } = require('enzyme'); | ||
var Adapter = require('enzyme-adapter-react-16'); | ||
configure({ adapter: new Adapter() }); | ||
var { shallow, configure } = require('enzyme') | ||
var Adapter = require('enzyme-adapter-react-16') | ||
configure({ adapter: new Adapter() }) | ||
describe('DateTimeGroup', function() { | ||
var clock, DateTimeGroup; | ||
describe('DateTimeGroup', function () { | ||
var clock, DateTimeGroup | ||
before(function() { | ||
clock = sinon.useFakeTimers(new Date(2015, 5, 6).valueOf()); | ||
before(function () { | ||
clock = sinon.useFakeTimers(new Date(2015, 5, 6).valueOf()) | ||
// getDefaultProps contains a date and is called when the component | ||
// is defined - we need to ensure the current date is faked by then. | ||
DateTimeGroup = require('../src/DateTimeGroup'); | ||
}); | ||
DateTimeGroup = require('../src/DateTimeGroup') | ||
}) | ||
after(function() { | ||
clock.restore(); | ||
}); | ||
after(function () { | ||
clock.restore() | ||
}) | ||
it('is an element', function() { | ||
expect(TestUtils.isElement(<DateTimeGroup />)).to.equal(true); | ||
}); | ||
it('is an element', function () { | ||
expect(TestUtils.isElement(<DateTimeGroup />)).to.equal(true) | ||
}) | ||
describe('props', function() { | ||
it('is populated with some defaults', function() { | ||
var element = <DateTimeGroup />; | ||
describe('props', function () { | ||
it('is populated with some defaults', function () { | ||
var element = <DateTimeGroup /> | ||
@@ -49,18 +49,18 @@ expect(element.props).to.deep.equal({ | ||
} | ||
}); | ||
}); | ||
}); | ||
}) | ||
}) | ||
}) | ||
describe('render', function() { | ||
it('renders the component', function() { | ||
var dateTimeGroup = shallow(<DateTimeGroup />); | ||
expect(dateTimeGroup.type()).to.equal('div'); | ||
}); | ||
describe('render', function () { | ||
it('renders the component', function () { | ||
var dateTimeGroup = shallow(<DateTimeGroup />) | ||
expect(dateTimeGroup.type()).to.equal('div') | ||
}) | ||
describe('time-select child component', function() { | ||
context('when requested', function() { | ||
var props; | ||
var dateTimeGroup; | ||
describe('time-select child component', function () { | ||
context('when requested', function () { | ||
var props | ||
var dateTimeGroup | ||
before(function() { | ||
before(function () { | ||
props = { | ||
@@ -75,75 +75,74 @@ timeClassName: 'the-time-class', | ||
value: new Date(2015, 8, 9, 15, 30, 0, 0) | ||
}; | ||
} | ||
dateTimeGroup = shallow(<DateTimeGroup {...props} />); | ||
}); | ||
dateTimeGroup = shallow(<DateTimeGroup {...props} />) | ||
}) | ||
it('renders a time picker', function() { | ||
expect(dateTimeGroup.find(TimePicker)).to.have.length(1); | ||
}); | ||
it('renders a time picker', function () { | ||
expect(dateTimeGroup.find(TimePicker)).to.have.length(1) | ||
}) | ||
it('passes a className prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().className).to.equal(props.timeClassName); | ||
}); | ||
it('passes a className prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().className).to.equal(props.timeClassName) | ||
}) | ||
it('passes a label prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().label).to.equal(props.timeLabel); | ||
}); | ||
it('passes a label prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().label).to.equal(props.timeLabel) | ||
}) | ||
it('passes a name prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().name).to.equal(props.timeName); | ||
}); | ||
it('passes a name prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().name).to.equal(props.timeName) | ||
}) | ||
it('passes a start prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().start).to.equal(props.timeStart); | ||
}); | ||
it('passes a start prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().start).to.equal(props.timeStart) | ||
}) | ||
it('passes a end prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().end).to.equal(props.timeEnd); | ||
}); | ||
it('passes a end prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().end).to.equal(props.timeEnd) | ||
}) | ||
it('passes a step prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().step).to.equal(props.timeStep); | ||
}); | ||
it('passes a step prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().step).to.equal(props.timeStep) | ||
}) | ||
it('passes a locales prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().locale).to.equal(props.locale); | ||
}); | ||
it('passes a locales prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().locale).to.equal(props.locale) | ||
}) | ||
it('passes a value prop through', function() { | ||
expect(dateTimeGroup.find(TimePicker).props().value).to.equal(props.value); | ||
}); | ||
it('passes a value prop through', function () { | ||
expect(dateTimeGroup.find(TimePicker).props().value).to.equal(props.value) | ||
}) | ||
context('with a timeId prop', function() { | ||
beforeEach(function() { | ||
dateTimeGroup = shallow(<DateTimeGroup {...props} timeId="timeSelect" />); | ||
}); | ||
context('with a timeId prop', function () { | ||
beforeEach(function () { | ||
dateTimeGroup = shallow(<DateTimeGroup {...props} timeId='timeSelect' />) | ||
}) | ||
it('passes an id prop', function() { | ||
expect(dateTimeGroup.find(TimePicker).prop('id')).to.equal('timeSelect'); | ||
}); | ||
}); | ||
}); | ||
it('passes an id prop', function () { | ||
expect(dateTimeGroup.find(TimePicker).prop('id')).to.equal('timeSelect') | ||
}) | ||
}) | ||
}) | ||
context('when not requested', function() { | ||
it('is not rendered', function() { | ||
var dateTimeGroup = shallow(<DateTimeGroup includeTime={false} />); | ||
expect(dateTimeGroup.find(TimePicker)).to.have.length(0); | ||
}); | ||
}); | ||
context('when not requested', function () { | ||
it('is not rendered', function () { | ||
var dateTimeGroup = shallow(<DateTimeGroup includeTime={false} />) | ||
expect(dateTimeGroup.find(TimePicker)).to.have.length(0) | ||
}) | ||
}) | ||
context('by default', function() { | ||
it('is rendered', function() { | ||
var dateTimeGroup = shallow(<DateTimeGroup />); | ||
expect(dateTimeGroup.find(TimePicker)).to.have.length(1); | ||
}); | ||
}); | ||
}); | ||
context('by default', function () { | ||
it('is rendered', function () { | ||
var dateTimeGroup = shallow(<DateTimeGroup />) | ||
expect(dateTimeGroup.find(TimePicker)).to.have.length(1) | ||
}) | ||
}) | ||
}) | ||
describe('date-select child component', function() { | ||
context('with properties', function() { | ||
var props; | ||
var dateTimeGroup; | ||
before(function() { | ||
describe('date-select child component', function () { | ||
context('with properties', function () { | ||
var props | ||
var dateTimeGroup | ||
before(function () { | ||
props = { | ||
@@ -158,3 +157,3 @@ date: new Date(2015, 8, 13, 10, 0, 0), | ||
] | ||
}; | ||
} | ||
@@ -164,74 +163,74 @@ dateTimeGroup = shallow(<DateTimeGroup | ||
dateEnd={props.dateEnd} | ||
dateLabel="the-date-label" | ||
dateFormat="dd/mm/YYYY" | ||
dateLabel='the-date-label' | ||
dateFormat='dd/mm/YYYY' | ||
dateExclusions={props.dateExclusions} | ||
locale="en-US" | ||
value={props.date} />); | ||
}); | ||
locale='en-US' | ||
value={props.date} />) | ||
}) | ||
it('is rendered', function() { | ||
expect(dateTimeGroup.find(DatePicker)).to.have.length(1); | ||
}); | ||
it('is rendered', function () { | ||
expect(dateTimeGroup.find(DatePicker)).to.have.length(1) | ||
}) | ||
it('wraps the dateStart in a moment', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().minDate).to.deep.equal(moment(props.dateStart)); | ||
}); | ||
it('wraps the dateStart in a moment', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().minDate).to.deep.equal(moment(props.dateStart)) | ||
}) | ||
it('wraps the dateEnd in a moment', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().maxDate).to.deep.equal(moment(props.dateEnd)); | ||
}); | ||
it('wraps the dateEnd in a moment', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().maxDate).to.deep.equal(moment(props.dateEnd)) | ||
}) | ||
it('passes the dateFormat through as the field formatter', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().dateFormat).to.equal('dd/mm/YYYY'); | ||
}); | ||
it('passes the dateFormat through as the field formatter', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().dateFormat).to.equal('dd/mm/YYYY') | ||
}) | ||
it('passes the first locale through (only one is expected)', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().locales).to.equal('en-US'); | ||
}); | ||
it('passes the first locale through (only one is expected)', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().locales).to.equal('en-US') | ||
}) | ||
it('wraps the value in a moment', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().selected).to.deep.equal(moment(props.date)); | ||
}); | ||
it('wraps the value in a moment', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().selected).to.deep.equal(moment(props.date)) | ||
}) | ||
it('passes the value through', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().selected.toDate()).to.deep.equal(props.date); | ||
}); | ||
it('passes the value through', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().selected.toDate()).to.deep.equal(props.date) | ||
}) | ||
it('wraps all the excluded dates in moments', function() { | ||
expect(moment.isMoment(dateTimeGroup.find(DatePicker).props().excludeDates[0])).to.equal(true); | ||
expect(moment.isMoment(dateTimeGroup.find(DatePicker).props().excludeDates[1])).to.equal(true); | ||
expect(moment.isMoment(dateTimeGroup.find(DatePicker).props().excludeDates[2])).to.equal(true); | ||
}); | ||
it('wraps all the excluded dates in moments', function () { | ||
expect(moment.isMoment(dateTimeGroup.find(DatePicker).props().excludeDates[0])).to.equal(true) | ||
expect(moment.isMoment(dateTimeGroup.find(DatePicker).props().excludeDates[1])).to.equal(true) | ||
expect(moment.isMoment(dateTimeGroup.find(DatePicker).props().excludeDates[2])).to.equal(true) | ||
}) | ||
it('passes all the excluded dates through', function() { | ||
expect(dateTimeGroup.find(DatePicker).props().excludeDates[0].toDate()).to.deep.equal(props.dateExclusions[0]); | ||
expect(dateTimeGroup.find(DatePicker).props().excludeDates[1].toDate()).to.deep.equal(props.dateExclusions[1]); | ||
expect(dateTimeGroup.find(DatePicker).props().excludeDates[2].toDate()).to.deep.equal(props.dateExclusions[2]); | ||
}); | ||
it('passes all the excluded dates through', function () { | ||
expect(dateTimeGroup.find(DatePicker).props().excludeDates[0].toDate()).to.deep.equal(props.dateExclusions[0]) | ||
expect(dateTimeGroup.find(DatePicker).props().excludeDates[1].toDate()).to.deep.equal(props.dateExclusions[1]) | ||
expect(dateTimeGroup.find(DatePicker).props().excludeDates[2].toDate()).to.deep.equal(props.dateExclusions[2]) | ||
}) | ||
it('renders the date label into a span', function() { | ||
expect(dateTimeGroup.find('span').children().text()).to.equal('the-date-label'); | ||
}); | ||
it('renders the date label into a span', function () { | ||
expect(dateTimeGroup.find('span').children().text()).to.equal('the-date-label') | ||
}) | ||
context('with a dateId prop', function() { | ||
beforeEach(function() { | ||
dateTimeGroup = shallow(<DateTimeGroup {...props} dateId="dateSelect" dateLabel="the-date-label" />); | ||
}); | ||
context('with a dateId prop', function () { | ||
beforeEach(function () { | ||
dateTimeGroup = shallow(<DateTimeGroup {...props} dateId='dateSelect' dateLabel='the-date-label' />) | ||
}) | ||
it('passes an id prop to the datepicker', function() { | ||
expect(dateTimeGroup.find(DatePicker).prop('id')).to.equal('dateSelect'); | ||
}); | ||
it('passes an id prop to the datepicker', function () { | ||
expect(dateTimeGroup.find(DatePicker).prop('id')).to.equal('dateSelect') | ||
}) | ||
it('renders a paired label', function() { | ||
expect(dateTimeGroup.find('label').prop('htmlFor')).to.equal('dateSelect'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('renders a paired label', function () { | ||
expect(dateTimeGroup.find('label').prop('htmlFor')).to.equal('dateSelect') | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('events', function() { | ||
var props; | ||
describe('events', function () { | ||
var props | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
props = { | ||
@@ -242,45 +241,45 @@ time: { | ||
} | ||
}; | ||
}); | ||
} | ||
}) | ||
it('will emit a date up if the date is changed', function() { | ||
var date = new Date(2015, 5, 5); | ||
var handler = sinon.stub(); | ||
it('will emit a date up if the date is changed', function () { | ||
var date = new Date(2015, 5, 5) | ||
var handler = sinon.stub() | ||
var dateTimeGroup = shallow(<DateTimeGroup onChange={handler} {...props} value={date} />); | ||
var input = dateTimeGroup.find('.datepicker__input'); | ||
var dateTimeGroup = shallow(<DateTimeGroup onChange={handler} {...props} value={date} />) | ||
var input = dateTimeGroup.find('.datepicker__input') | ||
input.simulate('change', moment('2015-06-12')); | ||
input.simulate('change', moment('2015-06-12')) | ||
sinon.assert.called(handler); | ||
sinon.assert.calledWith(handler, new Date(2015, 5, 12, 11, 30, 0, 0)); | ||
}); | ||
sinon.assert.called(handler) | ||
sinon.assert.calledWith(handler, new Date(2015, 5, 12, 11, 30, 0, 0)) | ||
}) | ||
it('will emit current time up with date when changed', function() { | ||
props.time.hours = '15'; | ||
props.time.minutes = '30'; | ||
var date = new Date(2015, 5, 5); | ||
var handler = sinon.stub(); | ||
it('will emit current time up with date when changed', function () { | ||
props.time.hours = '15' | ||
props.time.minutes = '30' | ||
var date = new Date(2015, 5, 5) | ||
var handler = sinon.stub() | ||
var dateTimeGroup = shallow(<DateTimeGroup onChange={handler} {...props} value={date} />); | ||
var input = dateTimeGroup.find('.datepicker__input'); | ||
var dateTimeGroup = shallow(<DateTimeGroup onChange={handler} {...props} value={date} />) | ||
var input = dateTimeGroup.find('.datepicker__input') | ||
input.simulate('change', moment('2015-06-12')); | ||
input.simulate('change', moment('2015-06-12')) | ||
sinon.assert.called(handler); | ||
sinon.assert.calledWith(handler, new Date(2015, 5, 12, 15, 30, 0, 0)); | ||
}); | ||
sinon.assert.called(handler) | ||
sinon.assert.calledWith(handler, new Date(2015, 5, 12, 15, 30, 0, 0)) | ||
}) | ||
it('will emit time up when time changed', function() { | ||
props.seperateHourMins = true; | ||
props.includeTime = true; | ||
props.value = new Date(2015, 5, 5); | ||
it('will emit time up when time changed', function () { | ||
props.seperateHourMins = true | ||
props.includeTime = true | ||
props.value = new Date(2015, 5, 5) | ||
const expectedCurrentTime = new Date(2015, 5, 5, 11, 15, 0, 0); | ||
const expectedCurrentTime = new Date(2015, 5, 5, 11, 15, 0, 0) | ||
var timeHandler = sinon.stub(); | ||
var dateHandler = sinon.stub(); | ||
var timeHandler = sinon.stub() | ||
var dateHandler = sinon.stub() | ||
var doc = TestUtils.renderIntoDocument(<DateTimeGroup onTimeChange={timeHandler} onChange={dateHandler} {...props} />); | ||
var timeNode = TestUtils.scryRenderedDOMComponentsWithTag(doc, 'select')[1]; | ||
var doc = TestUtils.renderIntoDocument(<DateTimeGroup onTimeChange={timeHandler} onChange={dateHandler} {...props} />) | ||
var timeNode = TestUtils.scryRenderedDOMComponentsWithTag(doc, 'select')[1] | ||
@@ -291,23 +290,22 @@ TestUtils.Simulate.change(timeNode, { | ||
} | ||
}); | ||
}) | ||
sinon.assert.calledWith(timeHandler, expectedCurrentTime); | ||
sinon.assert.calledWith(dateHandler, expectedCurrentTime); | ||
}); | ||
sinon.assert.calledWith(timeHandler, expectedCurrentTime) | ||
sinon.assert.calledWith(dateHandler, expectedCurrentTime) | ||
}) | ||
it('will not throw errors if no onClick is provided (for date)', function() { | ||
var dateTimeGroup = shallow(<DateTimeGroup />); | ||
var input = dateTimeGroup.find('.datepicker__input'); | ||
it('will not throw errors if no onClick is provided (for date)', function () { | ||
var dateTimeGroup = shallow(<DateTimeGroup />) | ||
var input = dateTimeGroup.find('.datepicker__input') | ||
expect(function() { | ||
input.simulate('change', moment('2015-06-12')); | ||
}).to.not.throw(Error); | ||
}); | ||
expect(function () { | ||
input.simulate('change', moment('2015-06-12')) | ||
}).to.not.throw(Error) | ||
}) | ||
it('will not throw errors if no onClick is provided (for time)', function() { | ||
it('will not throw errors if no onClick is provided (for time)', function () { | ||
var doc = TestUtils.renderIntoDocument(<DateTimeGroup />) | ||
var timeNode = TestUtils.findRenderedDOMComponentWithTag(doc, 'select') | ||
var doc = TestUtils.renderIntoDocument(<DateTimeGroup />); | ||
var timeNode = TestUtils.findRenderedDOMComponentWithTag(doc, 'select'); | ||
expect(function() { | ||
expect(function () { | ||
TestUtils.Simulate.change(timeNode, { | ||
@@ -317,6 +315,6 @@ target: { | ||
} | ||
}); | ||
}).to.not.throw(Error); | ||
}); | ||
}); | ||
}); | ||
}) | ||
}).to.not.throw(Error) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2171914
50744