import React from 'react';
import TimePicker from '../src/TimePicker';
-import TestUtils from 'react-addons-test-utils';
+import TestUtils from 'react-dom/test-utils';
const Simulate = TestUtils.Simulate;
import expect from 'expect.js';
import async from 'async';
-import { KeyCode } from 'rc-util';
+import KeyCode from 'rc-util/lib/KeyCode';
import moment from 'moment';
describe('Header', () => {
});
});
- it('exit correctly', (done) => {
- const picker = renderPicker();
+ const closeOnEscSpec = (closeOnEsc) => (done) => {
+ const picker = renderPicker({ closeOnEsc });
expect(picker.state.open).not.to.be.ok();
const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
'rc-time-picker-input')[0];
});
setTimeout(next, 100);
}, (next) => {
+ expect(picker.state.open).to.be(!closeOnEsc);
+ expect((header).value).to.be('01:02:03');
+ expect((input).value).to.be('01:02:03');
+
+ next();
+ }], () => {
+ done();
+ });
+ };
+
+ it('exit correctly', closeOnEscSpec(true));
+
+ it('stays open if `closeOnEsc` is `false`', closeOnEscSpec(false));
+
+ it('focus on open', (done) => {
+ const picker = renderPicker({
+ focusOnOpen: true,
+ });
+ expect(picker.state.open).not.to.be.ok();
+ const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
+ 'rc-time-picker-input')[0];
+ let header;
+ async.series([(next) => {
expect(picker.state.open).to.be(false);
+
+ Simulate.click(input);
+ setTimeout(next, 100);
+ }, (next) => {
+ // this touches the focusOnOpen code, but we cannot verify the input is in focus
+ expect(picker.state.open).to.be(true);
+ header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
+ 'rc-time-picker-panel-input')[0];
+ expect(header).to.be.ok();
expect((header).value).to.be('01:02:03');
expect((input).value).to.be('01:02:03');