]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - tests/Header.spec.jsx
Merge branch 'master' into focus-on-open
[github/fretlink/time-picker.git] / tests / Header.spec.jsx
index d5e570d1fcbf6f6d2863847094b6ff9aca61692d..4b27abb85fe0fa55ccb924547f7e0091b37341a3 100644 (file)
@@ -2,11 +2,11 @@ import ReactDOM from 'react-dom';
 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', () => {
@@ -368,5 +368,33 @@ describe('Header', () => {
         done();
       });
     });
+
+    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');
+
+        next();
+      }], () => {
+        done();
+      });
+    });
   });
 });