From 4984ed85e54f442998a335db70618d6184fa397e Mon Sep 17 00:00:00 2001 From: yiminghe Date: Thu, 4 Aug 2016 19:53:55 +0800 Subject: 2.x :boom: --- tests/Header.spec.jsx | 208 +++++++++++++++++++++++----------------------- tests/Select.spec.jsx | 140 ++++++++++++++++--------------- tests/TimePicker.spec.jsx | 65 +++++++-------- tests/index.js | 4 + tests/index.spec.js | 3 - tests/runner.html | 1 - 6 files changed, 214 insertions(+), 207 deletions(-) create mode 100644 tests/index.js delete mode 100644 tests/index.spec.js delete mode 100644 tests/runner.html (limited to 'tests') diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx index e992279..d5e570d 100644 --- a/tests/Header.spec.jsx +++ b/tests/Header.spec.jsx @@ -6,32 +6,21 @@ import TestUtils from 'react-addons-test-utils'; const Simulate = TestUtils.Simulate; import expect from 'expect.js'; import async from 'async'; -import {KeyCode} from 'rc-util'; - -import DateTimeFormat from 'gregorian-calendar-format'; -import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; -import TimePickerLocale from '../src/locale/zh_CN'; - -function formatTime(time, formatter) { - return formatter.parse(time, { - locale: zhCn, - obeyCount: true, - }); -} +import { KeyCode } from 'rc-util'; +import moment from 'moment'; describe('Header', () => { let container; function renderPicker(props) { const showSecond = true; - const formatter = new DateTimeFormat('HH:mm:ss'); + const format = 'HH:mm:ss'; return ReactDOM.render( , container); } @@ -50,25 +39,27 @@ describe('Header', () => { it('input correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { Simulate.click(input); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '12:34:56'; + (header).value = '12:34:56'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('12:34:56'); - expect(ReactDOM.findDOMNode(input).value).to.be('12:34:56'); + expect((header).value).to.be('12:34:56'); + expect((input).value).to.be('12:34:56'); next(); }], () => { @@ -79,41 +70,43 @@ describe('Header', () => { it('carry correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { Simulate.click(input); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '33:44:55'; + (header).value = '33:44:55'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('09:44:55'); - expect(ReactDOM.findDOMNode(input).value).to.be('09:44:55'); + expect((header).value).to.be('33:44:55'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:90:30'; + (header).value = '10:90:30'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('11:30:30'); - expect(ReactDOM.findDOMNode(input).value).to.be('11:30:30'); + expect((header).value).to.be('10:90:30'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '34:56:78'; + (header).value = '34:56:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('10:57:18'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:57:18'); + expect((header).value).to.be('34:56:78'); + expect((input).value).to.be('01:02:03'); next(); }], () => { @@ -131,51 +124,53 @@ describe('Header', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { Simulate.click(input); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:09:78'; + (header).value = '10:09:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); - expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('10:09:78'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:10:78'; + (header).value = '10:10:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + expect((header).value).to.be('10:10:78'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:09:19'; + (header).value = '10:09:19'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); - expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('10:09:19'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:09:20'; + (header).value = '10:09:20'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); + expect((header).value).to.be('10:09:20'); + expect((input).value).to.be('10:09:20'); next(); }], () => { @@ -194,51 +189,53 @@ describe('Header', () => { hideDisabledOptions: true, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { Simulate.click(input); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:09:78'; + (header).value = '10:09:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); - expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('10:09:78'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:10:78'; + (header).value = '10:10:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + expect((header).value).to.be('10:10:78'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:09:19'; + (header).value = '10:09:19'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); - expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('10:09:19'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '10:09:20'; + (header).value = '10:09:20'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); - expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); + expect((header).value).to.be('10:09:20'); + expect((input).value).to.be('10:09:20'); next(); }], () => { @@ -249,44 +246,46 @@ describe('Header', () => { it('check correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { Simulate.click(input); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '3:34:56'; + (header).value = '3:34:56'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('3:34:56'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('3:34:56'); + expect((input).value).to.be('01:02:03'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); - ReactDOM.findDOMNode(header).value = '13:3:56'; + (header).value = '13:3:56'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('13:3:56'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('13:3:56'); + expect((input).value).to.be('01:02:03'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); - ReactDOM.findDOMNode(header).value = '13:34:5'; + (header).value = '13:34:5'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('13:34:5'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect((header).value).to.be('13:34:5'); + expect((input).value).to.be('01:02:03'); + expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); next(); }], () => { done(); @@ -303,7 +302,8 @@ describe('Header', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -312,20 +312,22 @@ describe('Header', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; - const clearButton = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-clear-btn')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; + const clearButton = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-clear-btn')[0]; expect(header).to.be.ok(); expect(clearButton).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); Simulate.mouseDown(clearButton); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(false); expect(change).to.be(null); - expect(ReactDOM.findDOMNode(header).value).to.be(''); - expect(ReactDOM.findDOMNode(input).value).to.be(''); + expect((header).value).to.be(''); + expect((input).value).to.be(''); next(); }], () => { @@ -336,7 +338,8 @@ describe('Header', () => { it('exit correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -345,19 +348,20 @@ describe('Header', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); - Simulate.keyDown(ReactDOM.findDOMNode(header), { + Simulate.keyDown((header), { keyCode: KeyCode.ESC, }); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(false); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); next(); }], () => { diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx index f7717c7..e6d32dd 100644 --- a/tests/Select.spec.jsx +++ b/tests/Select.spec.jsx @@ -1,35 +1,24 @@ import ReactDOM from 'react-dom'; import React from 'react'; import TimePicker from '../src/TimePicker'; - import TestUtils from 'react-addons-test-utils'; const Simulate = TestUtils.Simulate; import expect from 'expect.js'; import async from 'async'; -import DateTimeFormat from 'gregorian-calendar-format'; -import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; -import TimePickerLocale from '../src/locale/zh_CN'; - -function formatTime(time, formatter) { - return formatter.parse(time, { - locale: zhCn, - obeyCount: true, - }); -} +import moment from 'moment'; describe('Select', () => { let container; function renderPicker(props) { const showSecond = true; - const formatter = new DateTimeFormat('HH:mm:ss'); + const format = 'HH:mm:ss'; return ReactDOM.render( , container); } @@ -48,7 +37,8 @@ describe('Select', () => { it('select number correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let selector; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -57,7 +47,8 @@ describe('Select', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select'); + selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select'); setTimeout(next, 100); }, (next) => { @@ -79,7 +70,8 @@ describe('Select', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -88,20 +80,22 @@ describe('Select', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[0]; const option = selector.getElementsByTagName('li')[19]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).to.be.ok(); - expect(change.getHourOfDay()).to.be(19); - expect(ReactDOM.findDOMNode(header).value).to.be('19:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('19:02:04'); + expect(change.hour()).to.be(19); + expect((header).value).to.be('19:02:04'); + expect((input).value).to.be('19:02:04'); expect(picker.state.open).to.be.ok(); next(); @@ -118,7 +112,8 @@ describe('Select', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -127,20 +122,22 @@ describe('Select', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[1]; const option = selector.getElementsByTagName('li')[19]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).to.be.ok(); - expect(change.getMinutes()).to.be(19); - expect(ReactDOM.findDOMNode(header).value).to.be('01:19:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:19:04'); + expect(change.minute()).to.be(19); + expect((header).value).to.be('01:19:04'); + expect((input).value).to.be('01:19:04'); expect(picker.state.open).to.be.ok(); next(); @@ -157,7 +154,8 @@ describe('Select', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -166,20 +164,22 @@ describe('Select', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[2]; const option = selector.getElementsByTagName('li')[19]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).to.be.ok(); - expect(change.getSeconds()).to.be(19); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:19'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:19'); + expect(change.second()).to.be(19); + expect((header).value).to.be('01:02:19'); + expect((input).value).to.be('01:02:19'); expect(picker.state.open).to.be.ok(); next(); @@ -202,7 +202,8 @@ describe('Select', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; let header; async.series([(next) => { expect(picker.state.open).to.be(false); @@ -211,40 +212,44 @@ describe('Select', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[1]; const option = selector.getElementsByTagName('li')[1]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).not.to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); expect(picker.state.open).to.be.ok(); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[2]; const option = selector.getElementsByTagName('li')[3]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).not.to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); expect(picker.state.open).to.be.ok(); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[1]; const option = selector.getElementsByTagName('li')[7]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).to.be.ok(); - expect(change.getMinutes()).to.be(7); - expect(ReactDOM.findDOMNode(header).value).to.be('01:07:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:07:04'); + expect(change.minute()).to.be(7); + expect((header).value).to.be('01:07:04'); + expect((input).value).to.be('01:07:04'); expect(picker.state.open).to.be.ok(); next(); @@ -274,31 +279,34 @@ describe('Select', () => { setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect((header).value).to.be('01:02:04'); + expect((input).value).to.be('01:02:04'); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[0]; const option = selector.getElementsByTagName('li')[3]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).to.be.ok(); - expect(change.getHourOfDay()).to.be(6); - expect(ReactDOM.findDOMNode(header).value).to.be('06:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('06:02:04'); + expect(change.hour()).to.be(6); + expect((header).value).to.be('06:02:04'); + expect((input).value).to.be('06:02:04'); expect(picker.state.open).to.be.ok(); - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[0]; const option = selector.getElementsByTagName('li')[4]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).to.be.ok(); - expect(change.getHourOfDay()).to.be(8); - expect(ReactDOM.findDOMNode(header).value).to.be('08:02:04'); - expect(ReactDOM.findDOMNode(input).value).to.be('08:02:04'); + expect(change.hour()).to.be(8); + expect((header).value).to.be('08:02:04'); + expect((input).value).to.be('08:02:04'); expect(picker.state.open).to.be.ok(); next(); diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx index 95a1fd1..150f727 100644 --- a/tests/TimePicker.spec.jsx +++ b/tests/TimePicker.spec.jsx @@ -6,45 +6,33 @@ import TestUtils from 'react-addons-test-utils'; const Simulate = TestUtils.Simulate; import expect from 'expect.js'; import async from 'async'; - -import DateTimeFormat from 'gregorian-calendar-format'; -import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; -import TimePickerLocale from '../src/locale/zh_CN'; - -function formatTime(time, formatter) { - return formatter.parse(time, { - locale: zhCn, - obeyCount: true, - }); -} +import moment from 'moment'; describe('TimePicker', () => { let container; function renderPicker(props) { const showSecond = true; - const formatter = new DateTimeFormat('HH:mm:ss'); + const format = ('HH:mm:ss'); return ReactDOM.render( , container); } function renderPickerWithoutSeconds(props) { const showSecond = false; - const formatter = new DateTimeFormat('HH:mm'); + const format = ('HH:mm'); return ReactDOM.render( , container); } @@ -68,23 +56,25 @@ describe('TimePicker', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; - expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58'); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + expect((input).value).to.be('12:57:58'); 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(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(change.getHourOfDay()).to.be(1); - expect(change.getMinutes()).to.be(57); - expect(change.getSeconds()).to.be(58); - expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58'); + expect(change.hour()).to.be(1); + expect(change.minute()).to.be(57); + expect(change.second()).to.be(58); + expect((input).value).to.be('01:57:58'); expect(picker.state.open).to.be.ok(); next(); }], () => { @@ -95,17 +85,20 @@ describe('TimePicker', () => { it('destroy correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; async.series([(next) => { Simulate.click(input); setTimeout(next, 100); }, (next) => { - expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); + expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); expect(picker.state.open).to.be(true); if (document.querySelectorAll) { expect(document.querySelectorAll('.rc-time-picker').length).not.to.be(0); } - expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok(); + expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, + 'li')[0]).to.be.ok(); ReactDOM.unmountComponentAtNode(container); setTimeout(next, 100); }, (next) => { @@ -129,22 +122,24 @@ describe('TimePicker', () => { }, }); expect(picker.state.open).not.to.be.ok(); - const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; - expect(ReactDOM.findDOMNode(input).value).to.be('08:24'); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + expect((input).value).to.be('08:24'); 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(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(change.getHourOfDay()).to.be(1); - expect(change.getMinutes()).to.be(24); - expect(ReactDOM.findDOMNode(input).value).to.be('01:24'); + expect(change.hour()).to.be(1); + expect(change.minute()).to.be(24); + expect((input).value).to.be('01:24'); expect(picker.state.open).to.be.ok(); next(); }], () => { diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..2900845 --- /dev/null +++ b/tests/index.js @@ -0,0 +1,4 @@ +import '../assets/index.less'; +import './TimePicker.spec'; +import './Header.spec'; +import './Select.spec'; diff --git a/tests/index.spec.js b/tests/index.spec.js deleted file mode 100644 index ae3918a..0000000 --- a/tests/index.spec.js +++ /dev/null @@ -1,3 +0,0 @@ -import './TimePicker.spec'; -import './Header.spec'; -import './Select.spec'; diff --git a/tests/runner.html b/tests/runner.html deleted file mode 100644 index 39802f6..0000000 --- a/tests/runner.html +++ /dev/null @@ -1 +0,0 @@ -stub -- cgit v1.2.3