aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Header.spec.jsx
diff options
context:
space:
mode:
authoryiminghe <yiminghe@gmail.com>2015-12-05 03:26:32 +0800
committeryiminghe <yiminghe@gmail.com>2015-12-05 03:26:32 +0800
commite9060dda0dd04e99666ff29efe459ebc7d7c65a7 (patch)
tree8647b5d9de89cf153aca06d3a6269e87e6813e70 /tests/Header.spec.jsx
parent38ecfddfa7719dfa88b11a2113b53b6ffc8842d5 (diff)
downloadtime-picker-e9060dda0dd04e99666ff29efe459ebc7d7c65a7.tar.gz
time-picker-e9060dda0dd04e99666ff29efe459ebc7d7c65a7.tar.zst
time-picker-e9060dda0dd04e99666ff29efe459ebc7d7c65a7.zip
lint
Diffstat (limited to 'tests/Header.spec.jsx')
-rw-r--r--tests/Header.spec.jsx133
1 files changed, 65 insertions, 68 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});