diff options
author | yiminghe <yiminghe@gmail.com> | 2016-08-04 19:53:55 +0800 |
---|---|---|
committer | yiminghe <yiminghe@gmail.com> | 2016-08-04 19:53:55 +0800 |
commit | 4984ed85e54f442998a335db70618d6184fa397e (patch) | |
tree | 6ae348b2cac5f48f3afb6f7b8dd0c2fd02f044fc /tests/TimePicker.spec.jsx | |
parent | deaa6062ea2e274d50d58c70251c1237c0c03c67 (diff) | |
download | time-picker-4984ed85e54f442998a335db70618d6184fa397e.tar.gz time-picker-4984ed85e54f442998a335db70618d6184fa397e.tar.zst time-picker-4984ed85e54f442998a335db70618d6184fa397e.zip |
2.x :boom:2.0.0
Diffstat (limited to 'tests/TimePicker.spec.jsx')
-rw-r--r-- | tests/TimePicker.spec.jsx | 65 |
1 files changed, 30 insertions, 35 deletions
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'; | |||
6 | const Simulate = TestUtils.Simulate; | 6 | const Simulate = TestUtils.Simulate; |
7 | import expect from 'expect.js'; | 7 | import expect from 'expect.js'; |
8 | import async from 'async'; | 8 | import async from 'async'; |
9 | 9 | import moment from 'moment'; | |
10 | import DateTimeFormat from 'gregorian-calendar-format'; | ||
11 | import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; | ||
12 | import TimePickerLocale from '../src/locale/zh_CN'; | ||
13 | |||
14 | function formatTime(time, formatter) { | ||
15 | return formatter.parse(time, { | ||
16 | locale: zhCn, | ||
17 | obeyCount: true, | ||
18 | }); | ||
19 | } | ||
20 | 10 | ||
21 | describe('TimePicker', () => { | 11 | describe('TimePicker', () => { |
22 | let container; | 12 | let container; |
23 | 13 | ||
24 | function renderPicker(props) { | 14 | function renderPicker(props) { |
25 | const showSecond = true; | 15 | const showSecond = true; |
26 | const formatter = new DateTimeFormat('HH:mm:ss'); | 16 | const format = ('HH:mm:ss'); |
27 | 17 | ||
28 | return ReactDOM.render( | 18 | return ReactDOM.render( |
29 | <TimePicker | 19 | <TimePicker |
30 | formatter={formatter} | 20 | format={format} |
31 | locale={TimePickerLocale} | ||
32 | showSecond={showSecond} | 21 | showSecond={showSecond} |
33 | defaultValue={formatTime('12:57:58', formatter)} | 22 | defaultValue={moment('12:57:58', format)} |
34 | {...props} | 23 | {...props} |
35 | />, container); | 24 | />, container); |
36 | } | 25 | } |
37 | 26 | ||
38 | function renderPickerWithoutSeconds(props) { | 27 | function renderPickerWithoutSeconds(props) { |
39 | const showSecond = false; | 28 | const showSecond = false; |
40 | const formatter = new DateTimeFormat('HH:mm'); | 29 | const format = ('HH:mm'); |
41 | 30 | ||
42 | return ReactDOM.render( | 31 | return ReactDOM.render( |
43 | <TimePicker | 32 | <TimePicker |
44 | formatter={formatter} | 33 | format={format} |
45 | locale={TimePickerLocale} | ||
46 | showSecond={showSecond} | 34 | showSecond={showSecond} |
47 | defaultValue={formatTime('08:24', formatter)} | 35 | defaultValue={moment('08:24', format)} |
48 | {...props} | 36 | {...props} |
49 | />, container); | 37 | />, container); |
50 | } | 38 | } |
@@ -68,23 +56,25 @@ describe('TimePicker', () => { | |||
68 | }, | 56 | }, |
69 | }); | 57 | }); |
70 | expect(picker.state.open).not.to.be.ok(); | 58 | expect(picker.state.open).not.to.be.ok(); |
71 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 59 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
72 | expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58'); | 60 | 'rc-time-picker-input')[0]; |
61 | expect((input).value).to.be('12:57:58'); | ||
73 | async.series([(next) => { | 62 | async.series([(next) => { |
74 | Simulate.click(input); | 63 | Simulate.click(input); |
75 | setTimeout(next, 100); | 64 | setTimeout(next, 100); |
76 | }, (next) => { | 65 | }, (next) => { |
77 | expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok(); | 66 | expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
67 | 'rc-time-picker-panel-inner')[0]).to.be.ok(); | ||
78 | expect(picker.state.open).to.be(true); | 68 | expect(picker.state.open).to.be(true); |
79 | const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; | 69 | const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; |
80 | Simulate.click(hour); | 70 | Simulate.click(hour); |
81 | setTimeout(next, 100); | 71 | setTimeout(next, 100); |
82 | }, (next) => { | 72 | }, (next) => { |
83 | expect(change).to.be.ok(); | 73 | expect(change).to.be.ok(); |
84 | expect(change.getHourOfDay()).to.be(1); | 74 | expect(change.hour()).to.be(1); |
85 | expect(change.getMinutes()).to.be(57); | 75 | expect(change.minute()).to.be(57); |
86 | expect(change.getSeconds()).to.be(58); | 76 | expect(change.second()).to.be(58); |
87 | expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58'); | 77 | expect((input).value).to.be('01:57:58'); |
88 | expect(picker.state.open).to.be.ok(); | 78 | expect(picker.state.open).to.be.ok(); |
89 | next(); | 79 | next(); |
90 | }], () => { | 80 | }], () => { |
@@ -95,17 +85,20 @@ describe('TimePicker', () => { | |||
95 | it('destroy correctly', (done) => { | 85 | it('destroy correctly', (done) => { |
96 | const picker = renderPicker(); | 86 | const picker = renderPicker(); |
97 | expect(picker.state.open).not.to.be.ok(); | 87 | expect(picker.state.open).not.to.be.ok(); |
98 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 88 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
89 | 'rc-time-picker-input')[0]; | ||
99 | async.series([(next) => { | 90 | async.series([(next) => { |
100 | Simulate.click(input); | 91 | Simulate.click(input); |
101 | setTimeout(next, 100); | 92 | setTimeout(next, 100); |
102 | }, (next) => { | 93 | }, (next) => { |
103 | expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); | 94 | expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, |
95 | 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); | ||
104 | expect(picker.state.open).to.be(true); | 96 | expect(picker.state.open).to.be(true); |
105 | if (document.querySelectorAll) { | 97 | if (document.querySelectorAll) { |
106 | expect(document.querySelectorAll('.rc-time-picker').length).not.to.be(0); | 98 | expect(document.querySelectorAll('.rc-time-picker').length).not.to.be(0); |
107 | } | 99 | } |
108 | expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok(); | 100 | expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, |
101 | 'li')[0]).to.be.ok(); | ||
109 | ReactDOM.unmountComponentAtNode(container); | 102 | ReactDOM.unmountComponentAtNode(container); |
110 | setTimeout(next, 100); | 103 | setTimeout(next, 100); |
111 | }, (next) => { | 104 | }, (next) => { |
@@ -129,22 +122,24 @@ describe('TimePicker', () => { | |||
129 | }, | 122 | }, |
130 | }); | 123 | }); |
131 | expect(picker.state.open).not.to.be.ok(); | 124 | expect(picker.state.open).not.to.be.ok(); |
132 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 125 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
133 | expect(ReactDOM.findDOMNode(input).value).to.be('08:24'); | 126 | 'rc-time-picker-input')[0]; |
127 | expect((input).value).to.be('08:24'); | ||
134 | async.series([(next) => { | 128 | async.series([(next) => { |
135 | Simulate.click(input); | 129 | Simulate.click(input); |
136 | setTimeout(next, 100); | 130 | setTimeout(next, 100); |
137 | }, (next) => { | 131 | }, (next) => { |
138 | expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok(); | 132 | expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
133 | 'rc-time-picker-panel-inner')[0]).to.be.ok(); | ||
139 | expect(picker.state.open).to.be(true); | 134 | expect(picker.state.open).to.be(true); |
140 | const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; | 135 | const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; |
141 | Simulate.click(hour); | 136 | Simulate.click(hour); |
142 | setTimeout(next, 100); | 137 | setTimeout(next, 100); |
143 | }, (next) => { | 138 | }, (next) => { |
144 | expect(change).to.be.ok(); | 139 | expect(change).to.be.ok(); |
145 | expect(change.getHourOfDay()).to.be(1); | 140 | expect(change.hour()).to.be(1); |
146 | expect(change.getMinutes()).to.be(24); | 141 | expect(change.minute()).to.be(24); |
147 | expect(ReactDOM.findDOMNode(input).value).to.be('01:24'); | 142 | expect((input).value).to.be('01:24'); |
148 | expect(picker.state.open).to.be.ok(); | 143 | expect(picker.state.open).to.be.ok(); |
149 | next(); | 144 | next(); |
150 | }], () => { | 145 | }], () => { |