X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=tests%2FTimePicker.spec.jsx;h=83f506ec024afb711418807099c0369d952938ce;hb=3931819e40ce408d8f7c1a969e160631b376c07e;hp=150f727cb44918cd97f18e166374d388f198e60d;hpb=614f6c90232d890984d0f4f2f13ff41fdb144b27;p=github%2Ffretlink%2Ftime-picker.git diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx index 150f727..83f506e 100644 --- a/tests/TimePicker.spec.jsx +++ b/tests/TimePicker.spec.jsx @@ -2,7 +2,7 @@ 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'; @@ -92,7 +92,7 @@ describe('TimePicker', () => { setTimeout(next, 100); }, (next) => { expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, - 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); + 'rc-time-picker-panel-inner')[0]).to.be.ok(); expect(picker.state.open).to.be(true); if (document.querySelectorAll) { expect(document.querySelectorAll('.rc-time-picker').length).not.to.be(0); @@ -111,6 +111,33 @@ describe('TimePicker', () => { done(); }); }); + + it('support name', () => { + const picker = renderPicker({ + name: 'time-picker-form-name', + }); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + expect(input.name).to.be('time-picker-form-name'); + }); + + it('support focus', () => { + const picker = renderPicker({ + name: 'time-picker-form-name', + }); + expect(picker.focus).to.be.a('function'); + }); + + it('should be controlled by open', () => { + const picker = renderPicker({ + open: false, + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + Simulate.click(input); + expect(picker.state.open).not.to.be.ok(); + }); }); describe('render panel to body (without seconds)', () => { @@ -147,4 +174,74 @@ describe('TimePicker', () => { }); }); }); + + describe('render panel to body 12pm mode', () => { + it('popup correctly', (done) => { + let change; + const picker = renderPickerWithoutSeconds({ + use12Hours: true, + value: null, + onChange(v) { + change = v; + }, + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + expect((input).value).to.be(''); + async.series([(next) => { + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-inner')[0]).to.be.ok(); + expect(picker.state.open).to.be(true); + const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; + Simulate.click(hour); + setTimeout(next, 100); + }, (next) => { + expect(change).to.be.ok(); + expect(picker.state.open).to.be.ok(); + next(); + }], () => { + done(); + }); + }); + }); + + describe('other operations', () => { + it('focus/blur correctly', (done) => { + let focus = false; + let blur = false; + + const picker = renderPicker({ + onFocus: () => { + focus = true; + }, + onBlur: () => { + blur = true; + }, + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + + async.series([(next) => { + Simulate.focus(input); + setTimeout(next, 100); + }, (next) => { + expect(picker.state.open).to.be(false); + + Simulate.blur(input); + setTimeout(next, 100); + }, (next) => { + expect(focus).to.be(true); + expect(blur).to.be(true); + + next(); + }], () => { + done(); + }); + }); + }); });