diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Header.spec.jsx | 208 | ||||
-rw-r--r-- | tests/Select.spec.jsx | 140 | ||||
-rw-r--r-- | tests/TimePicker.spec.jsx | 65 | ||||
-rw-r--r-- | tests/index.js (renamed from tests/index.spec.js) | 1 | ||||
-rw-r--r-- | tests/runner.html | 1 |
5 files changed, 211 insertions, 204 deletions
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'; | |||
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 | import {KeyCode} from 'rc-util'; | 9 | import { KeyCode } from 'rc-util'; |
10 | 10 | import moment from 'moment'; | |
11 | import DateTimeFormat from 'gregorian-calendar-format'; | ||
12 | import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; | ||
13 | import TimePickerLocale from '../src/locale/zh_CN'; | ||
14 | |||
15 | function formatTime(time, formatter) { | ||
16 | return formatter.parse(time, { | ||
17 | locale: zhCn, | ||
18 | obeyCount: true, | ||
19 | }); | ||
20 | } | ||
21 | 11 | ||
22 | describe('Header', () => { | 12 | describe('Header', () => { |
23 | let container; | 13 | let container; |
24 | 14 | ||
25 | function renderPicker(props) { | 15 | function renderPicker(props) { |
26 | const showSecond = true; | 16 | const showSecond = true; |
27 | const formatter = new DateTimeFormat('HH:mm:ss'); | 17 | const format = 'HH:mm:ss'; |
28 | 18 | ||
29 | return ReactDOM.render( | 19 | return ReactDOM.render( |
30 | <TimePicker | 20 | <TimePicker |
31 | formatter={formatter} | 21 | format={format} |
32 | locale={TimePickerLocale} | ||
33 | showSecond={showSecond} | 22 | showSecond={showSecond} |
34 | defaultValue={formatTime('01:02:03', formatter)} | 23 | defaultValue={moment('01:02:03', format)} |
35 | {...props} | 24 | {...props} |
36 | />, container); | 25 | />, container); |
37 | } | 26 | } |
@@ -50,25 +39,27 @@ describe('Header', () => { | |||
50 | it('input correctly', (done) => { | 39 | it('input correctly', (done) => { |
51 | const picker = renderPicker(); | 40 | const picker = renderPicker(); |
52 | expect(picker.state.open).not.to.be.ok(); | 41 | expect(picker.state.open).not.to.be.ok(); |
53 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 42 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
43 | 'rc-time-picker-input')[0]; | ||
54 | let header; | 44 | let header; |
55 | async.series([(next) => { | 45 | async.series([(next) => { |
56 | Simulate.click(input); | 46 | Simulate.click(input); |
57 | setTimeout(next, 100); | 47 | setTimeout(next, 100); |
58 | }, (next) => { | 48 | }, (next) => { |
59 | expect(picker.state.open).to.be(true); | 49 | expect(picker.state.open).to.be(true); |
60 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 50 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
51 | 'rc-time-picker-panel-input')[0]; | ||
61 | expect(header).to.be.ok(); | 52 | expect(header).to.be.ok(); |
62 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 53 | expect((header).value).to.be('01:02:03'); |
63 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 54 | expect((input).value).to.be('01:02:03'); |
64 | 55 | ||
65 | ReactDOM.findDOMNode(header).value = '12:34:56'; | 56 | (header).value = '12:34:56'; |
66 | Simulate.change(header); | 57 | Simulate.change(header); |
67 | setTimeout(next, 100); | 58 | setTimeout(next, 100); |
68 | }, (next) => { | 59 | }, (next) => { |
69 | expect(picker.state.open).to.be(true); | 60 | expect(picker.state.open).to.be(true); |
70 | expect(ReactDOM.findDOMNode(header).value).to.be('12:34:56'); | 61 | expect((header).value).to.be('12:34:56'); |
71 | expect(ReactDOM.findDOMNode(input).value).to.be('12:34:56'); | 62 | expect((input).value).to.be('12:34:56'); |
72 | 63 | ||
73 | next(); | 64 | next(); |
74 | }], () => { | 65 | }], () => { |
@@ -79,41 +70,43 @@ describe('Header', () => { | |||
79 | it('carry correctly', (done) => { | 70 | it('carry correctly', (done) => { |
80 | const picker = renderPicker(); | 71 | const picker = renderPicker(); |
81 | expect(picker.state.open).not.to.be.ok(); | 72 | expect(picker.state.open).not.to.be.ok(); |
82 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 73 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
74 | 'rc-time-picker-input')[0]; | ||
83 | let header; | 75 | let header; |
84 | async.series([(next) => { | 76 | async.series([(next) => { |
85 | Simulate.click(input); | 77 | Simulate.click(input); |
86 | setTimeout(next, 100); | 78 | setTimeout(next, 100); |
87 | }, (next) => { | 79 | }, (next) => { |
88 | expect(picker.state.open).to.be(true); | 80 | expect(picker.state.open).to.be(true); |
89 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 81 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
82 | 'rc-time-picker-panel-input')[0]; | ||
90 | expect(header).to.be.ok(); | 83 | expect(header).to.be.ok(); |
91 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 84 | expect((header).value).to.be('01:02:03'); |
92 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 85 | expect((input).value).to.be('01:02:03'); |
93 | 86 | ||
94 | ReactDOM.findDOMNode(header).value = '33:44:55'; | 87 | (header).value = '33:44:55'; |
95 | Simulate.change(header); | 88 | Simulate.change(header); |
96 | setTimeout(next, 100); | 89 | setTimeout(next, 100); |
97 | }, (next) => { | 90 | }, (next) => { |
98 | expect(picker.state.open).to.be(true); | 91 | expect(picker.state.open).to.be(true); |
99 | expect(ReactDOM.findDOMNode(header).value).to.be('09:44:55'); | 92 | expect((header).value).to.be('33:44:55'); |
100 | expect(ReactDOM.findDOMNode(input).value).to.be('09:44:55'); | 93 | expect((input).value).to.be('01:02:03'); |
101 | 94 | ||
102 | ReactDOM.findDOMNode(header).value = '10:90:30'; | 95 | (header).value = '10:90:30'; |
103 | Simulate.change(header); | 96 | Simulate.change(header); |
104 | setTimeout(next, 100); | 97 | setTimeout(next, 100); |
105 | }, (next) => { | 98 | }, (next) => { |
106 | expect(picker.state.open).to.be(true); | 99 | expect(picker.state.open).to.be(true); |
107 | expect(ReactDOM.findDOMNode(header).value).to.be('11:30:30'); | 100 | expect((header).value).to.be('10:90:30'); |
108 | expect(ReactDOM.findDOMNode(input).value).to.be('11:30:30'); | 101 | expect((input).value).to.be('01:02:03'); |
109 | 102 | ||
110 | ReactDOM.findDOMNode(header).value = '34:56:78'; | 103 | (header).value = '34:56:78'; |
111 | Simulate.change(header); | 104 | Simulate.change(header); |
112 | setTimeout(next, 100); | 105 | setTimeout(next, 100); |
113 | }, (next) => { | 106 | }, (next) => { |
114 | expect(picker.state.open).to.be(true); | 107 | expect(picker.state.open).to.be(true); |
115 | expect(ReactDOM.findDOMNode(header).value).to.be('10:57:18'); | 108 | expect((header).value).to.be('34:56:78'); |
116 | expect(ReactDOM.findDOMNode(input).value).to.be('10:57:18'); | 109 | expect((input).value).to.be('01:02:03'); |
117 | 110 | ||
118 | next(); | 111 | next(); |
119 | }], () => { | 112 | }], () => { |
@@ -131,51 +124,53 @@ describe('Header', () => { | |||
131 | }, | 124 | }, |
132 | }); | 125 | }); |
133 | expect(picker.state.open).not.to.be.ok(); | 126 | expect(picker.state.open).not.to.be.ok(); |
134 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 127 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
128 | 'rc-time-picker-input')[0]; | ||
135 | let header; | 129 | let header; |
136 | async.series([(next) => { | 130 | async.series([(next) => { |
137 | Simulate.click(input); | 131 | Simulate.click(input); |
138 | setTimeout(next, 100); | 132 | setTimeout(next, 100); |
139 | }, (next) => { | 133 | }, (next) => { |
140 | expect(picker.state.open).to.be(true); | 134 | expect(picker.state.open).to.be(true); |
141 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 135 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
136 | 'rc-time-picker-panel-input')[0]; | ||
142 | expect(header).to.be.ok(); | 137 | expect(header).to.be.ok(); |
143 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 138 | expect((header).value).to.be('01:02:03'); |
144 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 139 | expect((input).value).to.be('01:02:03'); |
145 | 140 | ||
146 | ReactDOM.findDOMNode(header).value = '10:09:78'; | 141 | (header).value = '10:09:78'; |
147 | Simulate.change(header); | 142 | Simulate.change(header); |
148 | setTimeout(next, 100); | 143 | setTimeout(next, 100); |
149 | }, (next) => { | 144 | }, (next) => { |
150 | expect(picker.state.open).to.be(true); | 145 | expect(picker.state.open).to.be(true); |
151 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 146 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
152 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); | 147 | expect((header).value).to.be('10:09:78'); |
153 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 148 | expect((input).value).to.be('01:02:03'); |
154 | 149 | ||
155 | ReactDOM.findDOMNode(header).value = '10:10:78'; | 150 | (header).value = '10:10:78'; |
156 | Simulate.change(header); | 151 | Simulate.change(header); |
157 | setTimeout(next, 100); | 152 | setTimeout(next, 100); |
158 | }, (next) => { | 153 | }, (next) => { |
159 | expect(picker.state.open).to.be(true); | 154 | expect(picker.state.open).to.be(true); |
160 | expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); | 155 | expect((header).value).to.be('10:10:78'); |
161 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | 156 | expect((input).value).to.be('01:02:03'); |
162 | 157 | ||
163 | ReactDOM.findDOMNode(header).value = '10:09:19'; | 158 | (header).value = '10:09:19'; |
164 | Simulate.change(header); | 159 | Simulate.change(header); |
165 | setTimeout(next, 100); | 160 | setTimeout(next, 100); |
166 | }, (next) => { | 161 | }, (next) => { |
167 | expect(picker.state.open).to.be(true); | 162 | expect(picker.state.open).to.be(true); |
168 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 163 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
169 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); | 164 | expect((header).value).to.be('10:09:19'); |
170 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | 165 | expect((input).value).to.be('01:02:03'); |
171 | 166 | ||
172 | ReactDOM.findDOMNode(header).value = '10:09:20'; | 167 | (header).value = '10:09:20'; |
173 | Simulate.change(header); | 168 | Simulate.change(header); |
174 | setTimeout(next, 100); | 169 | setTimeout(next, 100); |
175 | }, (next) => { | 170 | }, (next) => { |
176 | expect(picker.state.open).to.be(true); | 171 | expect(picker.state.open).to.be(true); |
177 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); | 172 | expect((header).value).to.be('10:09:20'); |
178 | expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); | 173 | expect((input).value).to.be('10:09:20'); |
179 | 174 | ||
180 | next(); | 175 | next(); |
181 | }], () => { | 176 | }], () => { |
@@ -194,51 +189,53 @@ describe('Header', () => { | |||
194 | hideDisabledOptions: true, | 189 | hideDisabledOptions: true, |
195 | }); | 190 | }); |
196 | expect(picker.state.open).not.to.be.ok(); | 191 | expect(picker.state.open).not.to.be.ok(); |
197 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 192 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
193 | 'rc-time-picker-input')[0]; | ||
198 | let header; | 194 | let header; |
199 | async.series([(next) => { | 195 | async.series([(next) => { |
200 | Simulate.click(input); | 196 | Simulate.click(input); |
201 | setTimeout(next, 100); | 197 | setTimeout(next, 100); |
202 | }, (next) => { | 198 | }, (next) => { |
203 | expect(picker.state.open).to.be(true); | 199 | expect(picker.state.open).to.be(true); |
204 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 200 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
201 | 'rc-time-picker-panel-input')[0]; | ||
205 | expect(header).to.be.ok(); | 202 | expect(header).to.be.ok(); |
206 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 203 | expect((header).value).to.be('01:02:03'); |
207 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 204 | expect((input).value).to.be('01:02:03'); |
208 | 205 | ||
209 | ReactDOM.findDOMNode(header).value = '10:09:78'; | 206 | (header).value = '10:09:78'; |
210 | Simulate.change(header); | 207 | Simulate.change(header); |
211 | setTimeout(next, 100); | 208 | setTimeout(next, 100); |
212 | }, (next) => { | 209 | }, (next) => { |
213 | expect(picker.state.open).to.be(true); | 210 | expect(picker.state.open).to.be(true); |
214 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 211 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
215 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); | 212 | expect((header).value).to.be('10:09:78'); |
216 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 213 | expect((input).value).to.be('01:02:03'); |
217 | 214 | ||
218 | ReactDOM.findDOMNode(header).value = '10:10:78'; | 215 | (header).value = '10:10:78'; |
219 | Simulate.change(header); | 216 | Simulate.change(header); |
220 | setTimeout(next, 100); | 217 | setTimeout(next, 100); |
221 | }, (next) => { | 218 | }, (next) => { |
222 | expect(picker.state.open).to.be(true); | 219 | expect(picker.state.open).to.be(true); |
223 | expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); | 220 | expect((header).value).to.be('10:10:78'); |
224 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | 221 | expect((input).value).to.be('01:02:03'); |
225 | 222 | ||
226 | ReactDOM.findDOMNode(header).value = '10:09:19'; | 223 | (header).value = '10:09:19'; |
227 | Simulate.change(header); | 224 | Simulate.change(header); |
228 | setTimeout(next, 100); | 225 | setTimeout(next, 100); |
229 | }, (next) => { | 226 | }, (next) => { |
230 | expect(picker.state.open).to.be(true); | 227 | expect(picker.state.open).to.be(true); |
231 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 228 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
232 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); | 229 | expect((header).value).to.be('10:09:19'); |
233 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | 230 | expect((input).value).to.be('01:02:03'); |
234 | 231 | ||
235 | ReactDOM.findDOMNode(header).value = '10:09:20'; | 232 | (header).value = '10:09:20'; |
236 | Simulate.change(header); | 233 | Simulate.change(header); |
237 | setTimeout(next, 100); | 234 | setTimeout(next, 100); |
238 | }, (next) => { | 235 | }, (next) => { |
239 | expect(picker.state.open).to.be(true); | 236 | expect(picker.state.open).to.be(true); |
240 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); | 237 | expect((header).value).to.be('10:09:20'); |
241 | expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); | 238 | expect((input).value).to.be('10:09:20'); |
242 | 239 | ||
243 | next(); | 240 | next(); |
244 | }], () => { | 241 | }], () => { |
@@ -249,44 +246,46 @@ describe('Header', () => { | |||
249 | it('check correctly', (done) => { | 246 | it('check correctly', (done) => { |
250 | const picker = renderPicker(); | 247 | const picker = renderPicker(); |
251 | expect(picker.state.open).not.to.be.ok(); | 248 | expect(picker.state.open).not.to.be.ok(); |
252 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 249 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
250 | 'rc-time-picker-input')[0]; | ||
253 | let header; | 251 | let header; |
254 | async.series([(next) => { | 252 | async.series([(next) => { |
255 | Simulate.click(input); | 253 | Simulate.click(input); |
256 | setTimeout(next, 100); | 254 | setTimeout(next, 100); |
257 | }, (next) => { | 255 | }, (next) => { |
258 | expect(picker.state.open).to.be(true); | 256 | expect(picker.state.open).to.be(true); |
259 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 257 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
258 | 'rc-time-picker-panel-input')[0]; | ||
260 | expect(header).to.be.ok(); | 259 | expect(header).to.be.ok(); |
261 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 260 | expect((header).value).to.be('01:02:03'); |
262 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 261 | expect((input).value).to.be('01:02:03'); |
263 | 262 | ||
264 | ReactDOM.findDOMNode(header).value = '3:34:56'; | 263 | (header).value = '3:34:56'; |
265 | Simulate.change(header); | 264 | Simulate.change(header); |
266 | setTimeout(next, 100); | 265 | setTimeout(next, 100); |
267 | }, (next) => { | 266 | }, (next) => { |
268 | expect(picker.state.open).to.be(true); | 267 | expect(picker.state.open).to.be(true); |
269 | expect(ReactDOM.findDOMNode(header).value).to.be('3:34:56'); | 268 | expect((header).value).to.be('3:34:56'); |
270 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 269 | expect((input).value).to.be('01:02:03'); |
271 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 270 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
272 | 271 | ||
273 | ReactDOM.findDOMNode(header).value = '13:3:56'; | 272 | (header).value = '13:3:56'; |
274 | Simulate.change(header); | 273 | Simulate.change(header); |
275 | setTimeout(next, 100); | 274 | setTimeout(next, 100); |
276 | }, (next) => { | 275 | }, (next) => { |
277 | expect(picker.state.open).to.be(true); | 276 | expect(picker.state.open).to.be(true); |
278 | expect(ReactDOM.findDOMNode(header).value).to.be('13:3:56'); | 277 | expect((header).value).to.be('13:3:56'); |
279 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 278 | expect((input).value).to.be('01:02:03'); |
280 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 279 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
281 | 280 | ||
282 | ReactDOM.findDOMNode(header).value = '13:34:5'; | 281 | (header).value = '13:34:5'; |
283 | Simulate.change(header); | 282 | Simulate.change(header); |
284 | setTimeout(next, 100); | 283 | setTimeout(next, 100); |
285 | }, (next) => { | 284 | }, (next) => { |
286 | expect(picker.state.open).to.be(true); | 285 | expect(picker.state.open).to.be(true); |
287 | expect(ReactDOM.findDOMNode(header).value).to.be('13:34:5'); | 286 | expect((header).value).to.be('13:34:5'); |
288 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 287 | expect((input).value).to.be('01:02:03'); |
289 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 288 | expect((header).className).to.contain('rc-time-picker-panel-input-invalid'); |
290 | next(); | 289 | next(); |
291 | }], () => { | 290 | }], () => { |
292 | done(); | 291 | done(); |
@@ -303,7 +302,8 @@ describe('Header', () => { | |||
303 | }, | 302 | }, |
304 | }); | 303 | }); |
305 | expect(picker.state.open).not.to.be.ok(); | 304 | expect(picker.state.open).not.to.be.ok(); |
306 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 305 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
306 | 'rc-time-picker-input')[0]; | ||
307 | let header; | 307 | let header; |
308 | async.series([(next) => { | 308 | async.series([(next) => { |
309 | expect(picker.state.open).to.be(false); | 309 | expect(picker.state.open).to.be(false); |
@@ -312,20 +312,22 @@ describe('Header', () => { | |||
312 | setTimeout(next, 100); | 312 | setTimeout(next, 100); |
313 | }, (next) => { | 313 | }, (next) => { |
314 | expect(picker.state.open).to.be(true); | 314 | expect(picker.state.open).to.be(true); |
315 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 315 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
316 | const clearButton = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-clear-btn')[0]; | 316 | 'rc-time-picker-panel-input')[0]; |
317 | const clearButton = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, | ||
318 | 'rc-time-picker-panel-clear-btn')[0]; | ||
317 | expect(header).to.be.ok(); | 319 | expect(header).to.be.ok(); |
318 | expect(clearButton).to.be.ok(); | 320 | expect(clearButton).to.be.ok(); |
319 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 321 | expect((header).value).to.be('01:02:03'); |
320 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 322 | expect((input).value).to.be('01:02:03'); |
321 | 323 | ||
322 | Simulate.mouseDown(clearButton); | 324 | Simulate.mouseDown(clearButton); |
323 | setTimeout(next, 100); | 325 | setTimeout(next, 100); |
324 | }, (next) => { | 326 | }, (next) => { |
325 | expect(picker.state.open).to.be(false); | 327 | expect(picker.state.open).to.be(false); |
326 | expect(change).to.be(null); | 328 | expect(change).to.be(null); |
327 | expect(ReactDOM.findDOMNode(header).value).to.be(''); | 329 | expect((header).value).to.be(''); |
328 | expect(ReactDOM.findDOMNode(input).value).to.be(''); | 330 | expect((input).value).to.be(''); |
329 | 331 | ||
330 | next(); | 332 | next(); |
331 | }], () => { | 333 | }], () => { |
@@ -336,7 +338,8 @@ describe('Header', () => { | |||
336 | it('exit correctly', (done) => { | 338 | it('exit correctly', (done) => { |
337 | const picker = renderPicker(); | 339 | const picker = renderPicker(); |
338 | expect(picker.state.open).not.to.be.ok(); | 340 | expect(picker.state.open).not.to.be.ok(); |
339 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 341 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
342 | 'rc-time-picker-input')[0]; | ||
340 | let header; | 343 | let header; |
341 | async.series([(next) => { | 344 | async.series([(next) => { |
342 | expect(picker.state.open).to.be(false); | 345 | expect(picker.state.open).to.be(false); |
@@ -345,19 +348,20 @@ describe('Header', () => { | |||
345 | setTimeout(next, 100); | 348 | setTimeout(next, 100); |
346 | }, (next) => { | 349 | }, (next) => { |
347 | expect(picker.state.open).to.be(true); | 350 | expect(picker.state.open).to.be(true); |
348 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 351 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
352 | 'rc-time-picker-panel-input')[0]; | ||
349 | expect(header).to.be.ok(); | 353 | expect(header).to.be.ok(); |
350 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 354 | expect((header).value).to.be('01:02:03'); |
351 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 355 | expect((input).value).to.be('01:02:03'); |
352 | 356 | ||
353 | Simulate.keyDown(ReactDOM.findDOMNode(header), { | 357 | Simulate.keyDown((header), { |
354 | keyCode: KeyCode.ESC, | 358 | keyCode: KeyCode.ESC, |
355 | }); | 359 | }); |
356 | setTimeout(next, 100); | 360 | setTimeout(next, 100); |
357 | }, (next) => { | 361 | }, (next) => { |
358 | expect(picker.state.open).to.be(false); | 362 | expect(picker.state.open).to.be(false); |
359 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 363 | expect((header).value).to.be('01:02:03'); |
360 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 364 | expect((input).value).to.be('01:02:03'); |
361 | 365 | ||
362 | next(); | 366 | next(); |
363 | }], () => { | 367 | }], () => { |
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 @@ | |||
1 | import ReactDOM from 'react-dom'; | 1 | import ReactDOM from 'react-dom'; |
2 | import React from 'react'; | 2 | import React from 'react'; |
3 | import TimePicker from '../src/TimePicker'; | 3 | import TimePicker from '../src/TimePicker'; |
4 | |||
5 | import TestUtils from 'react-addons-test-utils'; | 4 | import TestUtils from 'react-addons-test-utils'; |
6 | const Simulate = TestUtils.Simulate; | 5 | const Simulate = TestUtils.Simulate; |
7 | import expect from 'expect.js'; | 6 | import expect from 'expect.js'; |
8 | import async from 'async'; | 7 | import async from 'async'; |
9 | import DateTimeFormat from 'gregorian-calendar-format'; | 8 | import moment from 'moment'; |
10 | import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; | ||
11 | import TimePickerLocale from '../src/locale/zh_CN'; | ||
12 | |||
13 | function formatTime(time, formatter) { | ||
14 | return formatter.parse(time, { | ||
15 | locale: zhCn, | ||
16 | obeyCount: true, | ||
17 | }); | ||
18 | } | ||
19 | 9 | ||
20 | describe('Select', () => { | 10 | describe('Select', () => { |
21 | let container; | 11 | let container; |
22 | 12 | ||
23 | function renderPicker(props) { | 13 | function renderPicker(props) { |
24 | const showSecond = true; | 14 | const showSecond = true; |
25 | const formatter = new DateTimeFormat('HH:mm:ss'); | 15 | const format = 'HH:mm:ss'; |
26 | 16 | ||
27 | return ReactDOM.render( | 17 | return ReactDOM.render( |
28 | <TimePicker | 18 | <TimePicker |
29 | formatter={formatter} | 19 | format={format} |
30 | locale={TimePickerLocale} | ||
31 | showSecond={showSecond} | 20 | showSecond={showSecond} |
32 | defaultValue={formatTime('01:02:04', formatter)} | 21 | defaultValue={moment('01:02:04', format)} |
33 | {...props} | 22 | {...props} |
34 | />, container); | 23 | />, container); |
35 | } | 24 | } |
@@ -48,7 +37,8 @@ describe('Select', () => { | |||
48 | it('select number correctly', (done) => { | 37 | it('select number correctly', (done) => { |
49 | const picker = renderPicker(); | 38 | const picker = renderPicker(); |
50 | expect(picker.state.open).not.to.be.ok(); | 39 | expect(picker.state.open).not.to.be.ok(); |
51 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 40 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
41 | 'rc-time-picker-input')[0]; | ||
52 | let selector; | 42 | let selector; |
53 | async.series([(next) => { | 43 | async.series([(next) => { |
54 | expect(picker.state.open).to.be(false); | 44 | expect(picker.state.open).to.be(false); |
@@ -57,7 +47,8 @@ describe('Select', () => { | |||
57 | setTimeout(next, 100); | 47 | setTimeout(next, 100); |
58 | }, (next) => { | 48 | }, (next) => { |
59 | expect(picker.state.open).to.be(true); | 49 | expect(picker.state.open).to.be(true); |
60 | selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select'); | 50 | selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
51 | 'rc-time-picker-panel-select'); | ||
61 | 52 | ||
62 | setTimeout(next, 100); | 53 | setTimeout(next, 100); |
63 | }, (next) => { | 54 | }, (next) => { |
@@ -79,7 +70,8 @@ describe('Select', () => { | |||
79 | }, | 70 | }, |
80 | }); | 71 | }); |
81 | expect(picker.state.open).not.to.be.ok(); | 72 | expect(picker.state.open).not.to.be.ok(); |
82 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 73 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
74 | 'rc-time-picker-input')[0]; | ||
83 | let header; | 75 | let header; |
84 | async.series([(next) => { | 76 | async.series([(next) => { |
85 | expect(picker.state.open).to.be(false); | 77 | expect(picker.state.open).to.be(false); |
@@ -88,20 +80,22 @@ describe('Select', () => { | |||
88 | setTimeout(next, 100); | 80 | setTimeout(next, 100); |
89 | }, (next) => { | 81 | }, (next) => { |
90 | expect(picker.state.open).to.be(true); | 82 | expect(picker.state.open).to.be(true); |
91 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 83 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
84 | 'rc-time-picker-panel-input')[0]; | ||
92 | expect(header).to.be.ok(); | 85 | expect(header).to.be.ok(); |
93 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 86 | expect((header).value).to.be('01:02:04'); |
94 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 87 | expect((input).value).to.be('01:02:04'); |
95 | 88 | ||
96 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; | 89 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
90 | 'rc-time-picker-panel-select')[0]; | ||
97 | const option = selector.getElementsByTagName('li')[19]; | 91 | const option = selector.getElementsByTagName('li')[19]; |
98 | Simulate.click(option); | 92 | Simulate.click(option); |
99 | setTimeout(next, 100); | 93 | setTimeout(next, 100); |
100 | }, (next) => { | 94 | }, (next) => { |
101 | expect(change).to.be.ok(); | 95 | expect(change).to.be.ok(); |
102 | expect(change.getHourOfDay()).to.be(19); | 96 | expect(change.hour()).to.be(19); |
103 | expect(ReactDOM.findDOMNode(header).value).to.be('19:02:04'); | 97 | expect((header).value).to.be('19:02:04'); |
104 | expect(ReactDOM.findDOMNode(input).value).to.be('19:02:04'); | 98 | expect((input).value).to.be('19:02:04'); |
105 | expect(picker.state.open).to.be.ok(); | 99 | expect(picker.state.open).to.be.ok(); |
106 | 100 | ||
107 | next(); | 101 | next(); |
@@ -118,7 +112,8 @@ describe('Select', () => { | |||
118 | }, | 112 | }, |
119 | }); | 113 | }); |
120 | expect(picker.state.open).not.to.be.ok(); | 114 | expect(picker.state.open).not.to.be.ok(); |
121 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 115 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
116 | 'rc-time-picker-input')[0]; | ||
122 | let header; | 117 | let header; |
123 | async.series([(next) => { | 118 | async.series([(next) => { |
124 | expect(picker.state.open).to.be(false); | 119 | expect(picker.state.open).to.be(false); |
@@ -127,20 +122,22 @@ describe('Select', () => { | |||
127 | setTimeout(next, 100); | 122 | setTimeout(next, 100); |
128 | }, (next) => { | 123 | }, (next) => { |
129 | expect(picker.state.open).to.be(true); | 124 | expect(picker.state.open).to.be(true); |
130 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 125 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
126 | 'rc-time-picker-panel-input')[0]; | ||
131 | expect(header).to.be.ok(); | 127 | expect(header).to.be.ok(); |
132 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 128 | expect((header).value).to.be('01:02:04'); |
133 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 129 | expect((input).value).to.be('01:02:04'); |
134 | 130 | ||
135 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; | 131 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
132 | 'rc-time-picker-panel-select')[1]; | ||
136 | const option = selector.getElementsByTagName('li')[19]; | 133 | const option = selector.getElementsByTagName('li')[19]; |
137 | Simulate.click(option); | 134 | Simulate.click(option); |
138 | setTimeout(next, 100); | 135 | setTimeout(next, 100); |
139 | }, (next) => { | 136 | }, (next) => { |
140 | expect(change).to.be.ok(); | 137 | expect(change).to.be.ok(); |
141 | expect(change.getMinutes()).to.be(19); | 138 | expect(change.minute()).to.be(19); |
142 | expect(ReactDOM.findDOMNode(header).value).to.be('01:19:04'); | 139 | expect((header).value).to.be('01:19:04'); |
143 | expect(ReactDOM.findDOMNode(input).value).to.be('01:19:04'); | 140 | expect((input).value).to.be('01:19:04'); |
144 | expect(picker.state.open).to.be.ok(); | 141 | expect(picker.state.open).to.be.ok(); |
145 | 142 | ||
146 | next(); | 143 | next(); |
@@ -157,7 +154,8 @@ describe('Select', () => { | |||
157 | }, | 154 | }, |
158 | }); | 155 | }); |
159 | expect(picker.state.open).not.to.be.ok(); | 156 | expect(picker.state.open).not.to.be.ok(); |
160 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 157 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
158 | 'rc-time-picker-input')[0]; | ||
161 | let header; | 159 | let header; |
162 | async.series([(next) => { | 160 | async.series([(next) => { |
163 | expect(picker.state.open).to.be(false); | 161 | expect(picker.state.open).to.be(false); |
@@ -166,20 +164,22 @@ describe('Select', () => { | |||
166 | setTimeout(next, 100); | 164 | setTimeout(next, 100); |
167 | }, (next) => { | 165 | }, (next) => { |
168 | expect(picker.state.open).to.be(true); | 166 | expect(picker.state.open).to.be(true); |
169 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 167 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
168 | 'rc-time-picker-panel-input')[0]; | ||
170 | expect(header).to.be.ok(); | 169 | expect(header).to.be.ok(); |
171 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 170 | expect((header).value).to.be('01:02:04'); |
172 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 171 | expect((input).value).to.be('01:02:04'); |
173 | 172 | ||
174 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; | 173 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
174 | 'rc-time-picker-panel-select')[2]; | ||
175 | const option = selector.getElementsByTagName('li')[19]; | 175 | const option = selector.getElementsByTagName('li')[19]; |
176 | Simulate.click(option); | 176 | Simulate.click(option); |
177 | setTimeout(next, 100); | 177 | setTimeout(next, 100); |
178 | }, (next) => { | 178 | }, (next) => { |
179 | expect(change).to.be.ok(); | 179 | expect(change).to.be.ok(); |
180 | expect(change.getSeconds()).to.be(19); | 180 | expect(change.second()).to.be(19); |
181 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:19'); | 181 | expect((header).value).to.be('01:02:19'); |
182 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:19'); | 182 | expect((input).value).to.be('01:02:19'); |
183 | expect(picker.state.open).to.be.ok(); | 183 | expect(picker.state.open).to.be.ok(); |
184 | 184 | ||
185 | next(); | 185 | next(); |
@@ -202,7 +202,8 @@ describe('Select', () => { | |||
202 | }, | 202 | }, |
203 | }); | 203 | }); |
204 | expect(picker.state.open).not.to.be.ok(); | 204 | expect(picker.state.open).not.to.be.ok(); |
205 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 205 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, |
206 | 'rc-time-picker-input')[0]; | ||
206 | let header; | 207 | let header; |
207 | async.series([(next) => { | 208 | async.series([(next) => { |
208 | expect(picker.state.open).to.be(false); | 209 | expect(picker.state.open).to.be(false); |
@@ -211,40 +212,44 @@ describe('Select', () => { | |||
211 | setTimeout(next, 100); | 212 | setTimeout(next, 100); |
212 | }, (next) => { | 213 | }, (next) => { |
213 | expect(picker.state.open).to.be(true); | 214 | expect(picker.state.open).to.be(true); |
214 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 215 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
216 | 'rc-time-picker-panel-input')[0]; | ||
215 | expect(header).to.be.ok(); | 217 | expect(header).to.be.ok(); |
216 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 218 | expect((header).value).to.be('01:02:04'); |
217 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 219 | expect((input).value).to.be('01:02:04'); |
218 | 220 | ||
219 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; | 221 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
222 | 'rc-time-picker-panel-select')[1]; | ||
220 | const option = selector.getElementsByTagName('li')[1]; | 223 | const option = selector.getElementsByTagName('li')[1]; |
221 | Simulate.click(option); | 224 | Simulate.click(option); |
222 | setTimeout(next, 100); | 225 | setTimeout(next, 100); |
223 | }, (next) => { | 226 | }, (next) => { |
224 | expect(change).not.to.be.ok(); | 227 | expect(change).not.to.be.ok(); |
225 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 228 | expect((header).value).to.be('01:02:04'); |
226 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 229 | expect((input).value).to.be('01:02:04'); |
227 | expect(picker.state.open).to.be.ok(); | 230 | expect(picker.state.open).to.be.ok(); |
228 | 231 | ||
229 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; | 232 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
233 | 'rc-time-picker-panel-select')[2]; | ||
230 | const option = selector.getElementsByTagName('li')[3]; | 234 | const option = selector.getElementsByTagName('li')[3]; |
231 | Simulate.click(option); | 235 | Simulate.click(option); |
232 | setTimeout(next, 100); | 236 | setTimeout(next, 100); |
233 | }, (next) => { | 237 | }, (next) => { |
234 | expect(change).not.to.be.ok(); | 238 | expect(change).not.to.be.ok(); |
235 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 239 | expect((header).value).to.be('01:02:04'); |
236 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 240 | expect((input).value).to.be('01:02:04'); |
237 | expect(picker.state.open).to.be.ok(); | 241 | expect(picker.state.open).to.be.ok(); |
238 | 242 | ||
239 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; | 243 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
244 | 'rc-time-picker-panel-select')[1]; | ||
240 | const option = selector.getElementsByTagName('li')[7]; | 245 | const option = selector.getElementsByTagName('li')[7]; |
241 | Simulate.click(option); | 246 | Simulate.click(option); |
242 | setTimeout(next, 100); | 247 | setTimeout(next, 100); |
243 | }, (next) => { | 248 | }, (next) => { |
244 | expect(change).to.be.ok(); | 249 | expect(change).to.be.ok(); |
245 | expect(change.getMinutes()).to.be(7); | 250 | expect(change.minute()).to.be(7); |
246 | expect(ReactDOM.findDOMNode(header).value).to.be('01:07:04'); | 251 | expect((header).value).to.be('01:07:04'); |
247 | expect(ReactDOM.findDOMNode(input).value).to.be('01:07:04'); | 252 | expect((input).value).to.be('01:07:04'); |
248 | expect(picker.state.open).to.be.ok(); | 253 | expect(picker.state.open).to.be.ok(); |
249 | 254 | ||
250 | next(); | 255 | next(); |
@@ -274,31 +279,34 @@ describe('Select', () => { | |||
274 | setTimeout(next, 100); | 279 | setTimeout(next, 100); |
275 | }, (next) => { | 280 | }, (next) => { |
276 | expect(picker.state.open).to.be(true); | 281 | expect(picker.state.open).to.be(true); |
277 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 282 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
283 | 'rc-time-picker-panel-input')[0]; | ||
278 | expect(header).to.be.ok(); | 284 | expect(header).to.be.ok(); |
279 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | 285 | expect((header).value).to.be('01:02:04'); |
280 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | 286 | expect((input).value).to.be('01:02:04'); |
281 | 287 | ||
282 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; | 288 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
289 | 'rc-time-picker-panel-select')[0]; | ||
283 | const option = selector.getElementsByTagName('li')[3]; | 290 | const option = selector.getElementsByTagName('li')[3]; |
284 | Simulate.click(option); | 291 | Simulate.click(option); |
285 | setTimeout(next, 100); | 292 | setTimeout(next, 100); |
286 | }, (next) => { | 293 | }, (next) => { |
287 | expect(change).to.be.ok(); | 294 | expect(change).to.be.ok(); |
288 | expect(change.getHourOfDay()).to.be(6); | 295 | expect(change.hour()).to.be(6); |
289 | expect(ReactDOM.findDOMNode(header).value).to.be('06:02:04'); | 296 | expect((header).value).to.be('06:02:04'); |
290 | expect(ReactDOM.findDOMNode(input).value).to.be('06:02:04'); | 297 | expect((input).value).to.be('06:02:04'); |
291 | expect(picker.state.open).to.be.ok(); | 298 | expect(picker.state.open).to.be.ok(); |
292 | 299 | ||
293 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; | 300 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, |
301 | 'rc-time-picker-panel-select')[0]; | ||
294 | const option = selector.getElementsByTagName('li')[4]; | 302 | const option = selector.getElementsByTagName('li')[4]; |
295 | Simulate.click(option); | 303 | Simulate.click(option); |
296 | setTimeout(next, 100); | 304 | setTimeout(next, 100); |
297 | }, (next) => { | 305 | }, (next) => { |
298 | expect(change).to.be.ok(); | 306 | expect(change).to.be.ok(); |
299 | expect(change.getHourOfDay()).to.be(8); | 307 | expect(change.hour()).to.be(8); |
300 | expect(ReactDOM.findDOMNode(header).value).to.be('08:02:04'); | 308 | expect((header).value).to.be('08:02:04'); |
301 | expect(ReactDOM.findDOMNode(input).value).to.be('08:02:04'); | 309 | expect((input).value).to.be('08:02:04'); |
302 | expect(picker.state.open).to.be.ok(); | 310 | expect(picker.state.open).to.be.ok(); |
303 | 311 | ||
304 | next(); | 312 | 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'; | |||
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 | }], () => { |
diff --git a/tests/index.spec.js b/tests/index.js index ae3918a..2900845 100644 --- a/tests/index.spec.js +++ b/tests/index.js | |||
@@ -1,3 +1,4 @@ | |||
1 | import '../assets/index.less'; | ||
1 | import './TimePicker.spec'; | 2 | import './TimePicker.spec'; |
2 | import './Header.spec'; | 3 | import './Header.spec'; |
3 | import './Select.spec'; | 4 | 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 @@ | |||
1 | stub | ||