aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Header.spec.jsx133
-rw-r--r--tests/Select.spec.jsx133
-rw-r--r--tests/TimePicker.spec.jsx101
3 files changed, 175 insertions, 192 deletions
diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx
index e574d38..cc8f954 100644
--- a/tests/Header.spec.jsx
+++ b/tests/Header.spec.jsx
@@ -3,22 +3,28 @@ import React from 'react';
3import TimePicker from '../src/TimePicker'; 3import TimePicker from '../src/TimePicker';
4 4
5import TestUtils from 'react-addons-test-utils'; 5import TestUtils from 'react-addons-test-utils';
6var Simulate = TestUtils.Simulate; 6const Simulate = TestUtils.Simulate;
7import expect from 'expect.js'; 7import expect from 'expect.js';
8import async from 'async'; 8import async from 'async';
9import {KeyCode} from 'rc-util'; 9import {KeyCode} from 'rc-util';
10 10
11import DateTimeFormat from 'gregorian-calendar-format'; 11import DateTimeFormat from 'gregorian-calendar-format';
12import GregorianCalendar from 'gregorian-calendar';
13import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; 12import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
14import TimePickerLocale from '../src/locale/zh_CN'; 13import TimePickerLocale from '../src/locale/zh_CN';
15 14
16describe('Header', function () { 15function formatTime(time, formatter) {
17 var container; 16 return formatter.parse(time, {
17 locale: zhCn,
18 obeyCount: true,
19 });
20}
21
22describe('Header', () => {
23 let container;
18 24
19 function renderPicker(props) { 25 function renderPicker(props) {
20 var showSecond = true; 26 const showSecond = true;
21 var formatter = new DateTimeFormat('HH:mm:ss'); 27 const formatter = new DateTimeFormat('HH:mm:ss');
22 28
23 return ReactDOM.render( 29 return ReactDOM.render(
24 <TimePicker 30 <TimePicker
@@ -30,33 +36,26 @@ describe('Header', function () {
30 />, container); 36 />, container);
31 } 37 }
32 38
33 function formatTime(time, formatter) { 39 beforeEach(() => {
34 return formatter.parse(time, {
35 locale: zhCn,
36 obeyCount: true,
37 });
38 }
39
40 beforeEach(function () {
41 container = document.createElement('div'); 40 container = document.createElement('div');
42 document.body.appendChild(container); 41 document.body.appendChild(container);
43 }); 42 });
44 43
45 afterEach(function () { 44 afterEach(() => {
46 ReactDOM.unmountComponentAtNode(container); 45 ReactDOM.unmountComponentAtNode(container);
47 document.body.removeChild(container); 46 document.body.removeChild(container);
48 }); 47 });
49 48
50 describe('input to change value', function () { 49 describe('input to change value', () => {
51 it('input correctly', function (done) { 50 it('input correctly', (done) => {
52 var picker = renderPicker(); 51 const picker = renderPicker();
53 expect(picker.state.open).not.to.be.ok(); 52 expect(picker.state.open).not.to.be.ok();
54 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 53 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
55 var header; 54 let header;
56 async.series([function (next) { 55 async.series([(next) => {
57 Simulate.click(input); 56 Simulate.click(input);
58 setTimeout(next, 100); 57 setTimeout(next, 100);
59 }, function (next) { 58 }, (next) => {
60 expect(picker.state.open).to.be(true); 59 expect(picker.state.open).to.be(true);
61 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 60 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
62 expect(header).to.be.ok(); 61 expect(header).to.be.ok();
@@ -66,26 +65,26 @@ describe('Header', function () {
66 ReactDOM.findDOMNode(header).value = '12:34:56'; 65 ReactDOM.findDOMNode(header).value = '12:34:56';
67 Simulate.change(header); 66 Simulate.change(header);
68 setTimeout(next, 100); 67 setTimeout(next, 100);
69 }, function (next) { 68 }, (next) => {
70 expect(picker.state.open).to.be(true); 69 expect(picker.state.open).to.be(true);
71 expect(ReactDOM.findDOMNode(header).value).to.be('12:34:56'); 70 expect(ReactDOM.findDOMNode(header).value).to.be('12:34:56');
72 expect(ReactDOM.findDOMNode(input).value).to.be('12:34:56'); 71 expect(ReactDOM.findDOMNode(input).value).to.be('12:34:56');
73 72
74 next(); 73 next();
75 }], function () { 74 }], () => {
76 done(); 75 done();
77 }); 76 });
78 }); 77 });
79 78
80 it('carry correctly', function (done) { 79 it('carry correctly', (done) => {
81 var picker = renderPicker(); 80 const picker = renderPicker();
82 expect(picker.state.open).not.to.be.ok(); 81 expect(picker.state.open).not.to.be.ok();
83 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 82 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
84 var header; 83 let header;
85 async.series([function (next) { 84 async.series([(next) => {
86 Simulate.click(input); 85 Simulate.click(input);
87 setTimeout(next, 100); 86 setTimeout(next, 100);
88 }, function (next) { 87 }, (next) => {
89 expect(picker.state.open).to.be(true); 88 expect(picker.state.open).to.be(true);
90 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 89 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
91 expect(header).to.be.ok(); 90 expect(header).to.be.ok();
@@ -95,7 +94,7 @@ describe('Header', function () {
95 ReactDOM.findDOMNode(header).value = '33:44:55'; 94 ReactDOM.findDOMNode(header).value = '33:44:55';
96 Simulate.change(header); 95 Simulate.change(header);
97 setTimeout(next, 100); 96 setTimeout(next, 100);
98 }, function (next) { 97 }, (next) => {
99 expect(picker.state.open).to.be(true); 98 expect(picker.state.open).to.be(true);
100 expect(ReactDOM.findDOMNode(header).value).to.be('09:44:55'); 99 expect(ReactDOM.findDOMNode(header).value).to.be('09:44:55');
101 expect(ReactDOM.findDOMNode(input).value).to.be('09:44:55'); 100 expect(ReactDOM.findDOMNode(input).value).to.be('09:44:55');
@@ -103,7 +102,7 @@ describe('Header', function () {
103 ReactDOM.findDOMNode(header).value = '10:90:30'; 102 ReactDOM.findDOMNode(header).value = '10:90:30';
104 Simulate.change(header); 103 Simulate.change(header);
105 setTimeout(next, 100); 104 setTimeout(next, 100);
106 }, function (next) { 105 }, (next) => {
107 expect(picker.state.open).to.be(true); 106 expect(picker.state.open).to.be(true);
108 expect(ReactDOM.findDOMNode(header).value).to.be('11:30:30'); 107 expect(ReactDOM.findDOMNode(header).value).to.be('11:30:30');
109 expect(ReactDOM.findDOMNode(input).value).to.be('11:30:30'); 108 expect(ReactDOM.findDOMNode(input).value).to.be('11:30:30');
@@ -111,26 +110,26 @@ describe('Header', function () {
111 ReactDOM.findDOMNode(header).value = '34:56:78'; 110 ReactDOM.findDOMNode(header).value = '34:56:78';
112 Simulate.change(header); 111 Simulate.change(header);
113 setTimeout(next, 100); 112 setTimeout(next, 100);
114 }, function (next) { 113 }, (next) => {
115 expect(picker.state.open).to.be(true); 114 expect(picker.state.open).to.be(true);
116 expect(ReactDOM.findDOMNode(header).value).to.be('10:57:18'); 115 expect(ReactDOM.findDOMNode(header).value).to.be('10:57:18');
117 expect(ReactDOM.findDOMNode(input).value).to.be('10:57:18'); 116 expect(ReactDOM.findDOMNode(input).value).to.be('10:57:18');
118 117
119 next(); 118 next();
120 }], function () { 119 }], () => {
121 done(); 120 done();
122 }); 121 });
123 }); 122 });
124 123
125 it('check correctly', function (done) { 124 it('check correctly', (done) => {
126 var picker = renderPicker(); 125 const picker = renderPicker();
127 expect(picker.state.open).not.to.be.ok(); 126 expect(picker.state.open).not.to.be.ok();
128 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 127 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
129 var header; 128 let header;
130 async.series([function (next) { 129 async.series([(next) => {
131 Simulate.click(input); 130 Simulate.click(input);
132 setTimeout(next, 100); 131 setTimeout(next, 100);
133 }, function (next) { 132 }, (next) => {
134 expect(picker.state.open).to.be(true); 133 expect(picker.state.open).to.be(true);
135 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 134 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
136 expect(header).to.be.ok(); 135 expect(header).to.be.ok();
@@ -140,7 +139,7 @@ describe('Header', function () {
140 ReactDOM.findDOMNode(header).value = '3:34:56'; 139 ReactDOM.findDOMNode(header).value = '3:34:56';
141 Simulate.change(header); 140 Simulate.change(header);
142 setTimeout(next, 100); 141 setTimeout(next, 100);
143 }, function (next) { 142 }, (next) => {
144 expect(picker.state.open).to.be(true); 143 expect(picker.state.open).to.be(true);
145 expect(ReactDOM.findDOMNode(header).value).to.be('3:34:56'); 144 expect(ReactDOM.findDOMNode(header).value).to.be('3:34:56');
146 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 145 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
@@ -149,7 +148,7 @@ describe('Header', function () {
149 ReactDOM.findDOMNode(header).value = '13:3:56'; 148 ReactDOM.findDOMNode(header).value = '13:3:56';
150 Simulate.change(header); 149 Simulate.change(header);
151 setTimeout(next, 100); 150 setTimeout(next, 100);
152 }, function (next) { 151 }, (next) => {
153 expect(picker.state.open).to.be(true); 152 expect(picker.state.open).to.be(true);
154 expect(ReactDOM.findDOMNode(header).value).to.be('13:3:56'); 153 expect(ReactDOM.findDOMNode(header).value).to.be('13:3:56');
155 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 154 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
@@ -158,39 +157,38 @@ describe('Header', function () {
158 ReactDOM.findDOMNode(header).value = '13:34:5'; 157 ReactDOM.findDOMNode(header).value = '13:34:5';
159 Simulate.change(header); 158 Simulate.change(header);
160 setTimeout(next, 100); 159 setTimeout(next, 100);
161 }, function (next) { 160 }, (next) => {
162 expect(picker.state.open).to.be(true); 161 expect(picker.state.open).to.be(true);
163 expect(ReactDOM.findDOMNode(header).value).to.be('13:34:5'); 162 expect(ReactDOM.findDOMNode(header).value).to.be('13:34:5');
164 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 163 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
165 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); 164 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
166 next(); 165 next();
167 }], function () { 166 }], () => {
168 done(); 167 done();
169 }); 168 });
170 }); 169 });
171
172 }); 170 });
173 171
174 describe('other operations', function () { 172 describe('other operations', () => {
175 it('clear correctly', function (done) { 173 it('clear correctly', (done) => {
176 var change; 174 let change;
177 var picker = renderPicker({ 175 const picker = renderPicker({
178 onChange: function (v) { 176 onChange(v) {
179 change = v; 177 change = v;
180 } 178 },
181 }); 179 });
182 expect(picker.state.open).not.to.be.ok(); 180 expect(picker.state.open).not.to.be.ok();
183 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 181 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
184 var header; 182 let header;
185 async.series([function (next) { 183 async.series([(next) => {
186 expect(picker.state.open).to.be(false); 184 expect(picker.state.open).to.be(false);
187 185
188 Simulate.click(input); 186 Simulate.click(input);
189 setTimeout(next, 100); 187 setTimeout(next, 100);
190 }, function (next) { 188 }, (next) => {
191 expect(picker.state.open).to.be(true); 189 expect(picker.state.open).to.be(true);
192 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 190 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
193 var clearButton = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-clear-btn')[0]; 191 const clearButton = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-clear-btn')[0];
194 expect(header).to.be.ok(); 192 expect(header).to.be.ok();
195 expect(clearButton).to.be.ok(); 193 expect(clearButton).to.be.ok();
196 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 194 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
@@ -198,29 +196,29 @@ describe('Header', function () {
198 196
199 Simulate.mouseDown(clearButton); 197 Simulate.mouseDown(clearButton);
200 setTimeout(next, 100); 198 setTimeout(next, 100);
201 }, function (next) { 199 }, (next) => {
202 expect(picker.state.open).to.be(false); 200 expect(picker.state.open).to.be(false);
203 expect(change).to.be(null); 201 expect(change).to.be(null);
204 expect(ReactDOM.findDOMNode(header).value).to.be(''); 202 expect(ReactDOM.findDOMNode(header).value).to.be('');
205 expect(ReactDOM.findDOMNode(input).value).to.be(''); 203 expect(ReactDOM.findDOMNode(input).value).to.be('');
206 204
207 next(); 205 next();
208 }], function () { 206 }], () => {
209 done(); 207 done();
210 }); 208 });
211 }); 209 });
212 210
213 it('exit correctly', function (done) { 211 it('exit correctly', (done) => {
214 var picker = renderPicker(); 212 const picker = renderPicker();
215 expect(picker.state.open).not.to.be.ok(); 213 expect(picker.state.open).not.to.be.ok();
216 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 214 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
217 var header; 215 let header;
218 async.series([function (next) { 216 async.series([(next) => {
219 expect(picker.state.open).to.be(false); 217 expect(picker.state.open).to.be(false);
220 218
221 Simulate.click(input); 219 Simulate.click(input);
222 setTimeout(next, 100); 220 setTimeout(next, 100);
223 }, function (next) { 221 }, (next) => {
224 expect(picker.state.open).to.be(true); 222 expect(picker.state.open).to.be(true);
225 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 223 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
226 expect(header).to.be.ok(); 224 expect(header).to.be.ok();
@@ -228,19 +226,18 @@ describe('Header', function () {
228 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 226 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
229 227
230 Simulate.keyDown(ReactDOM.findDOMNode(header), { 228 Simulate.keyDown(ReactDOM.findDOMNode(header), {
231 keyCode: KeyCode.ESC 229 keyCode: KeyCode.ESC,
232 }); 230 });
233 setTimeout(next, 100); 231 setTimeout(next, 100);
234 }, function (next) { 232 }, (next) => {
235 expect(picker.state.open).to.be(false); 233 expect(picker.state.open).to.be(false);
236 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 234 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
237 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 235 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
238 236
239 next(); 237 next();
240 }], function () { 238 }], () => {
241 done(); 239 done();
242 }); 240 });
243 }); 241 });
244
245 }); 242 });
246}); 243});
diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx
index 036a0f9..7e53c31 100644
--- a/tests/Select.spec.jsx
+++ b/tests/Select.spec.jsx
@@ -3,22 +3,26 @@ import React from 'react';
3import TimePicker from '../src/TimePicker'; 3import TimePicker from '../src/TimePicker';
4 4
5import TestUtils from 'react-addons-test-utils'; 5import TestUtils from 'react-addons-test-utils';
6var Simulate = TestUtils.Simulate; 6const Simulate = TestUtils.Simulate;
7import expect from 'expect.js'; 7import expect from 'expect.js';
8import async from 'async'; 8import async from 'async';
9import {KeyCode} from 'rc-util';
10
11import DateTimeFormat from 'gregorian-calendar-format'; 9import DateTimeFormat from 'gregorian-calendar-format';
12import GregorianCalendar from 'gregorian-calendar';
13import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; 10import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
14import TimePickerLocale from '../src/locale/zh_CN'; 11import TimePickerLocale from '../src/locale/zh_CN';
15 12
16describe('Select', function () { 13function formatTime(time, formatter) {
17 var container; 14 return formatter.parse(time, {
15 locale: zhCn,
16 obeyCount: true,
17 });
18}
19
20describe('Select', () => {
21 let container;
18 22
19 function renderPicker(props) { 23 function renderPicker(props) {
20 var showSecond = true; 24 const showSecond = true;
21 var formatter = new DateTimeFormat('HH:mm:ss'); 25 const formatter = new DateTimeFormat('HH:mm:ss');
22 26
23 return ReactDOM.render( 27 return ReactDOM.render(
24 <TimePicker 28 <TimePicker
@@ -30,80 +34,70 @@ describe('Select', function () {
30 />, container); 34 />, container);
31 } 35 }
32 36
33 function formatTime(time, formatter) { 37 beforeEach(() => {
34 return formatter.parse(time, {
35 locale: zhCn,
36 obeyCount: true,
37 });
38 }
39
40 beforeEach(function () {
41 container = document.createElement('div'); 38 container = document.createElement('div');
42 document.body.appendChild(container); 39 document.body.appendChild(container);
43 }); 40 });
44 41
45 afterEach(function () { 42 afterEach(() => {
46 ReactDOM.unmountComponentAtNode(container); 43 ReactDOM.unmountComponentAtNode(container);
47 document.body.removeChild(container); 44 document.body.removeChild(container);
48 }); 45 });
49 46
50 describe('select number', function () { 47 describe('select number', () => {
51 48 it('select number correctly', (done) => {
52 it('select number correctly', function (done) { 49 const picker = renderPicker();
53 var picker = renderPicker();
54 expect(picker.state.open).not.to.be.ok(); 50 expect(picker.state.open).not.to.be.ok();
55 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 51 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
56 var selector; 52 let selector;
57 async.series([function (next) { 53 async.series([(next) => {
58 expect(picker.state.open).to.be(false); 54 expect(picker.state.open).to.be(false);
59 55
60 Simulate.click(input); 56 Simulate.click(input);
61 setTimeout(next, 100); 57 setTimeout(next, 100);
62 }, function (next) { 58 }, (next) => {
63 expect(picker.state.open).to.be(true); 59 expect(picker.state.open).to.be(true);
64 selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select'); 60 selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select');
65 61
66 setTimeout(next, 100); 62 setTimeout(next, 100);
67 }, function (next) { 63 }, (next) => {
68 expect(selector.length).to.be(3); 64 expect(selector.length).to.be(3);
69 65
70 next(); 66 next();
71 }], function () { 67 }], () => {
72 done(); 68 done();
73 }); 69 });
74 }); 70 });
75
76 }); 71 });
77 72
78 describe('select to change value', function () { 73 describe('select to change value', () => {
79 74 it('hour correctly', (done) => {
80 it('hour correctly', function (done) { 75 let change;
81 var change; 76 const picker = renderPicker({
82 var picker = renderPicker({ 77 onChange(v) {
83 onChange: function (v) {
84 change = v; 78 change = v;
85 } 79 },
86 }); 80 });
87 expect(picker.state.open).not.to.be.ok(); 81 expect(picker.state.open).not.to.be.ok();
88 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 82 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
89 var header; 83 let header;
90 async.series([function (next) { 84 async.series([(next) => {
91 expect(picker.state.open).to.be(false); 85 expect(picker.state.open).to.be(false);
92 86
93 Simulate.click(input); 87 Simulate.click(input);
94 setTimeout(next, 100); 88 setTimeout(next, 100);
95 }, function (next) { 89 }, (next) => {
96 expect(picker.state.open).to.be(true); 90 expect(picker.state.open).to.be(true);
97 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 91 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
98 var selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; 92 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
99 var option = selector.getElementsByTagName('li')[19]; 93 const option = selector.getElementsByTagName('li')[19];
100 expect(header).to.be.ok(); 94 expect(header).to.be.ok();
101 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 95 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
102 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 96 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
103 97
104 Simulate.click(option); 98 Simulate.click(option);
105 setTimeout(next, 100); 99 setTimeout(next, 100);
106 }, function (next) { 100 }, (next) => {
107 expect(change).to.be.ok(); 101 expect(change).to.be.ok();
108 expect(change.getHourOfDay()).to.be(19); 102 expect(change.getHourOfDay()).to.be(19);
109 expect(ReactDOM.findDOMNode(header).value).to.be('19:02:03'); 103 expect(ReactDOM.findDOMNode(header).value).to.be('19:02:03');
@@ -111,38 +105,38 @@ describe('Select', function () {
111 expect(picker.state.open).to.be.ok(); 105 expect(picker.state.open).to.be.ok();
112 106
113 next(); 107 next();
114 }], function () { 108 }], () => {
115 done(); 109 done();
116 }); 110 });
117 }); 111 });
118 112
119 it('minute correctly', function (done) { 113 it('minute correctly', (done) => {
120 var change; 114 let change;
121 var picker = renderPicker({ 115 const picker = renderPicker({
122 onChange: function (v) { 116 onChange(v) {
123 change = v; 117 change = v;
124 } 118 },
125 }); 119 });
126 expect(picker.state.open).not.to.be.ok(); 120 expect(picker.state.open).not.to.be.ok();
127 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 121 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
128 var header; 122 let header;
129 async.series([function (next) { 123 async.series([(next) => {
130 expect(picker.state.open).to.be(false); 124 expect(picker.state.open).to.be(false);
131 125
132 Simulate.click(input); 126 Simulate.click(input);
133 setTimeout(next, 100); 127 setTimeout(next, 100);
134 }, function (next) { 128 }, (next) => {
135 expect(picker.state.open).to.be(true); 129 expect(picker.state.open).to.be(true);
136 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 130 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
137 var selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; 131 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
138 var option = selector.getElementsByTagName('li')[19]; 132 const option = selector.getElementsByTagName('li')[19];
139 expect(header).to.be.ok(); 133 expect(header).to.be.ok();
140 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 134 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
141 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 135 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
142 136
143 Simulate.click(option); 137 Simulate.click(option);
144 setTimeout(next, 100); 138 setTimeout(next, 100);
145 }, function (next) { 139 }, (next) => {
146 expect(change).to.be.ok(); 140 expect(change).to.be.ok();
147 expect(change.getMinutes()).to.be(19); 141 expect(change.getMinutes()).to.be(19);
148 expect(ReactDOM.findDOMNode(header).value).to.be('01:19:03'); 142 expect(ReactDOM.findDOMNode(header).value).to.be('01:19:03');
@@ -150,38 +144,38 @@ describe('Select', function () {
150 expect(picker.state.open).to.be.ok(); 144 expect(picker.state.open).to.be.ok();
151 145
152 next(); 146 next();
153 }], function () { 147 }], () => {
154 done(); 148 done();
155 }); 149 });
156 }); 150 });
157 151
158 it('second correctly', function (done) { 152 it('second correctly', (done) => {
159 var change; 153 let change;
160 var picker = renderPicker({ 154 const picker = renderPicker({
161 onChange: function (v) { 155 onChange(v) {
162 change = v; 156 change = v;
163 } 157 },
164 }); 158 });
165 expect(picker.state.open).not.to.be.ok(); 159 expect(picker.state.open).not.to.be.ok();
166 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 160 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
167 var header; 161 let header;
168 async.series([function (next) { 162 async.series([(next) => {
169 expect(picker.state.open).to.be(false); 163 expect(picker.state.open).to.be(false);
170 164
171 Simulate.click(input); 165 Simulate.click(input);
172 setTimeout(next, 100); 166 setTimeout(next, 100);
173 }, function (next) { 167 }, (next) => {
174 expect(picker.state.open).to.be(true); 168 expect(picker.state.open).to.be(true);
175 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 169 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
176 var selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; 170 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
177 var option = selector.getElementsByTagName('li')[19]; 171 const option = selector.getElementsByTagName('li')[19];
178 expect(header).to.be.ok(); 172 expect(header).to.be.ok();
179 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 173 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
180 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 174 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
181 175
182 Simulate.click(option); 176 Simulate.click(option);
183 setTimeout(next, 100); 177 setTimeout(next, 100);
184 }, function (next) { 178 }, (next) => {
185 expect(change).to.be.ok(); 179 expect(change).to.be.ok();
186 expect(change.getSeconds()).to.be(19); 180 expect(change.getSeconds()).to.be(19);
187 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:19'); 181 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:19');
@@ -189,10 +183,9 @@ describe('Select', function () {
189 expect(picker.state.open).to.be.ok(); 183 expect(picker.state.open).to.be.ok();
190 184
191 next(); 185 next();
192 }], function () { 186 }], () => {
193 done(); 187 done();
194 }); 188 });
195 }); 189 });
196
197 }); 190 });
198}); 191});
diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx
index 5bd056e..95a1fd1 100644
--- a/tests/TimePicker.spec.jsx
+++ b/tests/TimePicker.spec.jsx
@@ -3,21 +3,27 @@ import React from 'react';
3import TimePicker from '../src/TimePicker'; 3import TimePicker from '../src/TimePicker';
4 4
5import TestUtils from 'react-addons-test-utils'; 5import TestUtils from 'react-addons-test-utils';
6var Simulate = TestUtils.Simulate; 6const Simulate = TestUtils.Simulate;
7import expect from 'expect.js'; 7import expect from 'expect.js';
8import async from 'async'; 8import async from 'async';
9 9
10import DateTimeFormat from 'gregorian-calendar-format'; 10import DateTimeFormat from 'gregorian-calendar-format';
11import GregorianCalendar from 'gregorian-calendar';
12import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; 11import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
13import TimePickerLocale from '../src/locale/zh_CN'; 12import TimePickerLocale from '../src/locale/zh_CN';
14 13
15describe('TimePicker', function () { 14function formatTime(time, formatter) {
16 var container; 15 return formatter.parse(time, {
16 locale: zhCn,
17 obeyCount: true,
18 });
19}
20
21describe('TimePicker', () => {
22 let container;
17 23
18 function renderPicker(props) { 24 function renderPicker(props) {
19 var showSecond = true; 25 const showSecond = true;
20 var formatter = new DateTimeFormat('HH:mm:ss'); 26 const formatter = new DateTimeFormat('HH:mm:ss');
21 27
22 return ReactDOM.render( 28 return ReactDOM.render(
23 <TimePicker 29 <TimePicker
@@ -30,8 +36,8 @@ describe('TimePicker', function () {
30 } 36 }
31 37
32 function renderPickerWithoutSeconds(props) { 38 function renderPickerWithoutSeconds(props) {
33 var showSecond = false; 39 const showSecond = false;
34 var formatter = new DateTimeFormat('HH:mm'); 40 const formatter = new DateTimeFormat('HH:mm');
35 41
36 return ReactDOM.render( 42 return ReactDOM.render(
37 <TimePicker 43 <TimePicker
@@ -43,44 +49,37 @@ describe('TimePicker', function () {
43 />, container); 49 />, container);
44 } 50 }
45 51
46 function formatTime(time, formatter) { 52 beforeEach(() => {
47 return formatter.parse(time, {
48 locale: zhCn,
49 obeyCount: true,
50 });
51 }
52
53 beforeEach(function () {
54 container = document.createElement('div'); 53 container = document.createElement('div');
55 document.body.appendChild(container); 54 document.body.appendChild(container);
56 }); 55 });
57 56
58 afterEach(function () { 57 afterEach(() => {
59 ReactDOM.unmountComponentAtNode(container); 58 ReactDOM.unmountComponentAtNode(container);
60 document.body.removeChild(container); 59 document.body.removeChild(container);
61 }); 60 });
62 61
63 describe('render panel to body', function () { 62 describe('render panel to body', () => {
64 it('popup correctly', function (done) { 63 it('popup correctly', (done) => {
65 var change; 64 let change;
66 var picker = renderPicker({ 65 const picker = renderPicker({
67 onChange: function (v) { 66 onChange(v) {
68 change = v; 67 change = v;
69 } 68 },
70 }); 69 });
71 expect(picker.state.open).not.to.be.ok(); 70 expect(picker.state.open).not.to.be.ok();
72 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 71 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
73 expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58'); 72 expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58');
74 async.series([function (next) { 73 async.series([(next) => {
75 Simulate.click(input); 74 Simulate.click(input);
76 setTimeout(next, 100); 75 setTimeout(next, 100);
77 }, function (next) { 76 }, (next) => {
78 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok(); 77 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
79 expect(picker.state.open).to.be(true); 78 expect(picker.state.open).to.be(true);
80 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; 79 const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
81 Simulate.click(hour); 80 Simulate.click(hour);
82 setTimeout(next, 100); 81 setTimeout(next, 100);
83 }, function (next) { 82 }, (next) => {
84 expect(change).to.be.ok(); 83 expect(change).to.be.ok();
85 expect(change.getHourOfDay()).to.be(1); 84 expect(change.getHourOfDay()).to.be(1);
86 expect(change.getMinutes()).to.be(57); 85 expect(change.getMinutes()).to.be(57);
@@ -88,24 +87,19 @@ describe('TimePicker', function () {
88 expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58'); 87 expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58');
89 expect(picker.state.open).to.be.ok(); 88 expect(picker.state.open).to.be.ok();
90 next(); 89 next();
91 }], function () { 90 }], () => {
92 done(); 91 done();
93 }); 92 });
94 }); 93 });
95 94
96 it('destroy correctly', function (done) { 95 it('destroy correctly', (done) => {
97 var change; 96 const picker = renderPicker();
98 var picker = renderPicker({
99 onChange: function (v) {
100 change = v;
101 }
102 });
103 expect(picker.state.open).not.to.be.ok(); 97 expect(picker.state.open).not.to.be.ok();
104 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 98 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
105 async.series([function (next) { 99 async.series([(next) => {
106 Simulate.click(input); 100 Simulate.click(input);
107 setTimeout(next, 100); 101 setTimeout(next, 100);
108 }, function (next) { 102 }, (next) => {
109 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); 103 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok();
110 expect(picker.state.open).to.be(true); 104 expect(picker.state.open).to.be(true);
111 if (document.querySelectorAll) { 105 if (document.querySelectorAll) {
@@ -114,49 +108,48 @@ describe('TimePicker', function () {
114 expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok(); 108 expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok();
115 ReactDOM.unmountComponentAtNode(container); 109 ReactDOM.unmountComponentAtNode(container);
116 setTimeout(next, 100); 110 setTimeout(next, 100);
117 }, function (next) { 111 }, (next) => {
118 if (document.querySelectorAll) { 112 if (document.querySelectorAll) {
119 expect(document.querySelectorAll('.rc-time-picker').length).to.be(0); 113 expect(document.querySelectorAll('.rc-time-picker').length).to.be(0);
120 } 114 }
121 expect(picker.panelInstance).not.to.be.ok(); 115 expect(picker.panelInstance).not.to.be.ok();
122 next(); 116 next();
123 }], function () { 117 }], () => {
124 done(); 118 done();
125 }); 119 });
126 }); 120 });
127 }); 121 });
128 122
129 describe('render panel to body (without seconds)', function () { 123 describe('render panel to body (without seconds)', () => {
130 it('popup correctly', function (done) { 124 it('popup correctly', (done) => {
131 var change; 125 let change;
132 var picker = renderPickerWithoutSeconds({ 126 const picker = renderPickerWithoutSeconds({
133 onChange: function (v) { 127 onChange(v) {
134 change = v; 128 change = v;
135 } 129 },
136 }); 130 });
137 expect(picker.state.open).not.to.be.ok(); 131 expect(picker.state.open).not.to.be.ok();
138 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 132 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
139 expect(ReactDOM.findDOMNode(input).value).to.be('08:24'); 133 expect(ReactDOM.findDOMNode(input).value).to.be('08:24');
140 async.series([function (next) { 134 async.series([(next) => {
141 Simulate.click(input); 135 Simulate.click(input);
142 setTimeout(next, 100); 136 setTimeout(next, 100);
143 }, function (next) { 137 }, (next) => {
144 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok(); 138 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
145 expect(picker.state.open).to.be(true); 139 expect(picker.state.open).to.be(true);
146 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; 140 const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
147 Simulate.click(hour); 141 Simulate.click(hour);
148 setTimeout(next, 100); 142 setTimeout(next, 100);
149 }, function (next) { 143 }, (next) => {
150 expect(change).to.be.ok(); 144 expect(change).to.be.ok();
151 expect(change.getHourOfDay()).to.be(1); 145 expect(change.getHourOfDay()).to.be(1);
152 expect(change.getMinutes()).to.be(24); 146 expect(change.getMinutes()).to.be(24);
153 expect(ReactDOM.findDOMNode(input).value).to.be('01:24'); 147 expect(ReactDOM.findDOMNode(input).value).to.be('01:24');
154 expect(picker.state.open).to.be.ok(); 148 expect(picker.state.open).to.be.ok();
155 next(); 149 next();
156 }], function () { 150 }], () => {
157 done(); 151 done();
158 }); 152 });
159 }); 153 });
160 }); 154 });
161
162}); 155});