aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-13 00:03:19 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-13 00:03:19 +0800
commit0e62bf0b7bdc260e882fd185492939cbaed04d56 (patch)
tree84f678a775ead7577fdcac9089ca918b4febcf39
parent518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 (diff)
downloadtime-picker-0e62bf0b7bdc260e882fd185492939cbaed04d56.tar.gz
time-picker-0e62bf0b7bdc260e882fd185492939cbaed04d56.tar.zst
time-picker-0e62bf0b7bdc260e882fd185492939cbaed04d56.zip
update test case and fix bugs
-rw-r--r--examples/disabled.html1
-rw-r--r--examples/disabled.js36
-rw-r--r--examples/hidden.html1
-rw-r--r--examples/hidden.js37
-rw-r--r--examples/pick-time.js18
-rw-r--r--src/module/Combobox.jsx2
-rw-r--r--src/module/Header.jsx6
-rw-r--r--src/module/Panel.jsx2
-rw-r--r--tests/Header.spec.jsx81
-rw-r--r--tests/Select.spec.jsx114
10 files changed, 270 insertions, 28 deletions
diff --git a/examples/disabled.html b/examples/disabled.html
new file mode 100644
index 0000000..48cdce8
--- /dev/null
+++ b/examples/disabled.html
@@ -0,0 +1 @@
placeholder
diff --git a/examples/disabled.js b/examples/disabled.js
new file mode 100644
index 0000000..24d0068
--- /dev/null
+++ b/examples/disabled.js
@@ -0,0 +1,36 @@
1/* eslint no-console:0 */
2
3import 'rc-time-picker/assets/index.less';
4
5import React from 'react';
6import ReactDom from 'react-dom';
7
8import GregorianCalendar from 'gregorian-calendar';
9import DateTimeFormat from 'gregorian-calendar-format';
10import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
11
12import TimePicker from 'rc-time-picker';
13import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN';
14
15const showSecond = true;
16const str = showSecond ? 'HH:mm:ss' : 'HH:mm';
17
18const formatter = new DateTimeFormat(str);
19
20const now = new GregorianCalendar(zhCn);
21now.setTime(Date.now());
22
23function onChange(value) {
24 console.log(value && formatter.format(value));
25}
26
27ReactDom.render(
28 <TimePicker formatter={formatter} locale={TimePickerLocale}
29 showSecond={showSecond}
30 defaultValue={now}
31 className="xxx"
32 onChange={onChange}
33 disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]}
34 disabledMinutes={[0, 2, 4, 6, 8]} />,
35 document.getElementById('__react-content')
36);
diff --git a/examples/hidden.html b/examples/hidden.html
new file mode 100644
index 0000000..48cdce8
--- /dev/null
+++ b/examples/hidden.html
@@ -0,0 +1 @@
placeholder
diff --git a/examples/hidden.js b/examples/hidden.js
new file mode 100644
index 0000000..1084236
--- /dev/null
+++ b/examples/hidden.js
@@ -0,0 +1,37 @@
1/* eslint no-console:0 */
2
3import 'rc-time-picker/assets/index.less';
4
5import React from 'react';
6import ReactDom from 'react-dom';
7
8import GregorianCalendar from 'gregorian-calendar';
9import DateTimeFormat from 'gregorian-calendar-format';
10import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
11
12import TimePicker from 'rc-time-picker';
13import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN';
14
15const showSecond = true;
16const str = showSecond ? 'HH:mm:ss' : 'HH:mm';
17
18const formatter = new DateTimeFormat(str);
19
20const now = new GregorianCalendar(zhCn);
21now.setTime(Date.now());
22
23function onChange(value) {
24 console.log(value && formatter.format(value));
25}
26
27ReactDom.render(
28 <TimePicker formatter={formatter} locale={TimePickerLocale}
29 showSecond={showSecond}
30 defaultValue={now}
31 className="xxx"
32 onChange={onChange}
33 disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]}
34 disabledMinutes={[0, 2, 4, 6, 8]}
35 hideDisabledOptions={true} />,
36 document.getElementById('__react-content')
37);
diff --git a/examples/pick-time.js b/examples/pick-time.js
index 074e72c..f66e416 100644
--- a/examples/pick-time.js
+++ b/examples/pick-time.js
@@ -24,27 +24,11 @@ function onChange(value) {
24 console.log(value && formatter.format(value)); 24 console.log(value && formatter.format(value));
25} 25}
26 26
27const options = {
28 disabledHours() {
29 return [0, 2, 21];
30 },
31 disabledMinutes(h) {
32 return h === 22 ? [0, 3, 31] : [];
33 },
34 disabledSeconds(h, m) {
35 return [];
36 },
37};
38
39ReactDom.render( 27ReactDom.render(
40 <TimePicker formatter={formatter} locale={TimePickerLocale} 28 <TimePicker formatter={formatter} locale={TimePickerLocale}
41 showSecond={showSecond} 29 showSecond={showSecond}
42 defaultValue={now} 30 defaultValue={now}
43 className="xxx" 31 className="xxx"
44 onChange={onChange} 32 onChange={onChange} />,
45 disabledHours={[0, 2, 21]}
46 disabledMinutes={[0, 2, 21]}
47 disabledSeconds={[]}
48 hideDisabledOptions={true} />,
49 document.getElementById('__react-content') 33 document.getElementById('__react-content')
50); 34);
diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx
index 27a8226..1e172a7 100644
--- a/src/module/Combobox.jsx
+++ b/src/module/Combobox.jsx
@@ -9,7 +9,7 @@ const formatOption = (option, disabledOptions) => {
9 } 9 }
10 10
11 let disabled = false; 11 let disabled = false;
12 if (disabledOptions.indexOf(option) >= 0) { 12 if (disabledOptions && disabledOptions.indexOf(option) >= 0) {
13 disabled = true; 13 disabled = true;
14 } 14 }
15 15
diff --git a/src/module/Header.jsx b/src/module/Header.jsx
index c2f8eef..fec02af 100644
--- a/src/module/Header.jsx
+++ b/src/module/Header.jsx
@@ -88,9 +88,9 @@ const Header = React.createClass({
88 88
89 // if time value is disabled, response warning. 89 // if time value is disabled, response warning.
90 if ( 90 if (
91 disabledHours.indexOf(value.getHourOfDay()) >= 0 || 91 (disabledHours && disabledHours.indexOf(value.getHourOfDay()) >= 0) ||
92 disabledMinutes.indexOf(value.getMinutes()) >= 0 || 92 (disabledMinutes && disabledMinutes.indexOf(value.getMinutes()) >= 0) ||
93 disabledSeconds.indexOf(value.getSeconds()) >= 0 93 (disabledSeconds && disabledSeconds.indexOf(value.getSeconds()) >= 0)
94 ) { 94 ) {
95 this.setState({ 95 this.setState({
96 invalid: true, 96 invalid: true,
diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx
index 72934e5..12d23f7 100644
--- a/src/module/Panel.jsx
+++ b/src/module/Panel.jsx
@@ -9,7 +9,7 @@ function noop() {
9function generateOptions(length, disabledOptions, hideDisabledOptions) { 9function generateOptions(length, disabledOptions, hideDisabledOptions) {
10 const arr = []; 10 const arr = [];
11 for (let value = 0; value < length; value++) { 11 for (let value = 0; value < length; value++) {
12 if ((disabledOptions && disabledOptions.indexOf(value) < 0) || !hideDisabledOptions) { 12 if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) {
13 arr.push(value); 13 arr.push(value);
14 } 14 }
15 } 15 }
diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx
index cc8f954..18d61c5 100644
--- a/tests/Header.spec.jsx
+++ b/tests/Header.spec.jsx
@@ -121,6 +121,87 @@ describe('Header', () => {
121 }); 121 });
122 }); 122 });
123 123
124 it('carry disabled correctly', (done) => {
125 const picker = renderPicker({
126 disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
127 });
128 expect(picker.state.open).not.to.be.ok();
129 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
130 let header;
131 async.series([(next) => {
132 Simulate.click(input);
133 setTimeout(next, 100);
134 }, (next) => {
135 expect(picker.state.open).to.be(true);
136 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
137 expect(header).to.be.ok();
138 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
139 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
140
141 ReactDOM.findDOMNode(header).value = '12:15:78';
142 Simulate.change(header);
143 setTimeout(next, 100);
144 }, (next) => {
145 expect(picker.state.open).to.be(true);
146 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
147 expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78');
148 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
149
150 ReactDOM.findDOMNode(header).value = '12:10:78';
151 Simulate.change(header);
152 setTimeout(next, 100);
153 }, (next) => {
154 expect(picker.state.open).to.be(true);
155 expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18');
156 expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18');
157
158 next();
159 }], () => {
160 done();
161 });
162 });
163
164 it('carry hidden correctly', (done) => {
165 const picker = renderPicker({
166 disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22],
167 hideDisabledOptions: true
168 });
169 expect(picker.state.open).not.to.be.ok();
170 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
171 let header;
172 async.series([(next) => {
173 Simulate.click(input);
174 setTimeout(next, 100);
175 }, (next) => {
176 expect(picker.state.open).to.be(true);
177 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
178 expect(header).to.be.ok();
179 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
180 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
181
182 ReactDOM.findDOMNode(header).value = '12:15:78';
183 Simulate.change(header);
184 setTimeout(next, 100);
185 }, (next) => {
186 expect(picker.state.open).to.be(true);
187 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
188 expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78');
189 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
190
191 ReactDOM.findDOMNode(header).value = '12:10:78';
192 Simulate.change(header);
193 setTimeout(next, 100);
194 }, (next) => {
195 expect(picker.state.open).to.be(true);
196 expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18');
197 expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18');
198
199 next();
200 }], () => {
201 done();
202 });
203 });
204
124 it('check correctly', (done) => { 205 it('check correctly', (done) => {
125 const picker = renderPicker(); 206 const picker = renderPicker();
126 expect(picker.state.open).not.to.be.ok(); 207 expect(picker.state.open).not.to.be.ok();
diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx
index 7e53c31..6dd7796 100644
--- a/tests/Select.spec.jsx
+++ b/tests/Select.spec.jsx
@@ -89,12 +89,12 @@ describe('Select', () => {
89 }, (next) => { 89 }, (next) => {
90 expect(picker.state.open).to.be(true); 90 expect(picker.state.open).to.be(true);
91 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 91 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
92 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
93 const option = selector.getElementsByTagName('li')[19];
94 expect(header).to.be.ok(); 92 expect(header).to.be.ok();
95 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 93 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
96 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 94 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
97 95
96 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
97 const option = selector.getElementsByTagName('li')[19];
98 Simulate.click(option); 98 Simulate.click(option);
99 setTimeout(next, 100); 99 setTimeout(next, 100);
100 }, (next) => { 100 }, (next) => {
@@ -128,12 +128,12 @@ describe('Select', () => {
128 }, (next) => { 128 }, (next) => {
129 expect(picker.state.open).to.be(true); 129 expect(picker.state.open).to.be(true);
130 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 130 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
131 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
132 const option = selector.getElementsByTagName('li')[19];
133 expect(header).to.be.ok(); 131 expect(header).to.be.ok();
134 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 132 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
135 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 133 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
136 134
135 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
136 const option = selector.getElementsByTagName('li')[19];
137 Simulate.click(option); 137 Simulate.click(option);
138 setTimeout(next, 100); 138 setTimeout(next, 100);
139 }, (next) => { 139 }, (next) => {
@@ -167,12 +167,12 @@ describe('Select', () => {
167 }, (next) => { 167 }, (next) => {
168 expect(picker.state.open).to.be(true); 168 expect(picker.state.open).to.be(true);
169 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 169 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
170 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
171 const option = selector.getElementsByTagName('li')[19];
172 expect(header).to.be.ok(); 170 expect(header).to.be.ok();
173 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 171 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
174 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 172 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
175 173
174 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
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) => {
@@ -187,5 +187,107 @@ describe('Select', () => {
187 done(); 187 done();
188 }); 188 });
189 }); 189 });
190
191 it('disabled correctly', (done) => {
192 let change;
193 const picker = renderPicker({
194 onChange(v) {
195 change = v;
196 },
197 disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
198 });
199 expect(picker.state.open).not.to.be.ok();
200 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
201 let header;
202 async.series([(next) => {
203 expect(picker.state.open).to.be(false);
204
205 Simulate.click(input);
206 setTimeout(next, 100);
207 }, (next) => {
208 expect(picker.state.open).to.be(true);
209 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
210 expect(header).to.be.ok();
211 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
212 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
213
214 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
215 const option = selector.getElementsByTagName('li')[6];
216 Simulate.click(option);
217 setTimeout(next, 100);
218 }, (next) => {
219 expect(change).not.to.be.ok();
220 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
221 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
222 expect(picker.state.open).to.be.ok();
223
224 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
225 const option = selector.getElementsByTagName('li')[7];
226 Simulate.click(option);
227 setTimeout(next, 100);
228 }, (next) => {
229 expect(change).to.be.ok();
230 expect(change.getMinutes()).to.be(7);
231 expect(ReactDOM.findDOMNode(header).value).to.be('01:07:03');
232 expect(ReactDOM.findDOMNode(input).value).to.be('01:07:03');
233 expect(picker.state.open).to.be.ok();
234
235 next();
236 }], () => {
237 done();
238 });
239 });
240
241 it('hidden correctly', (done) => {
242 let change;
243 const picker = renderPicker({
244 onChange(v) {
245 change = v;
246 },
247 disabledHours: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],
248 hideDisabledOptions: true
249 });
250 expect(picker.state.open).not.to.be.ok();
251 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
252 let header;
253 async.series([(next) => {
254 expect(picker.state.open).to.be(false);
255
256 Simulate.click(input);
257 setTimeout(next, 100);
258 }, (next) => {
259 expect(picker.state.open).to.be(true);
260 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
261 expect(header).to.be.ok();
262 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
263 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
264
265 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
266 const option = selector.getElementsByTagName('li')[3];
267 Simulate.click(option);
268 setTimeout(next, 100);
269 }, (next) => {
270 expect(change).to.be.ok();
271 expect(change.getHourOfDay()).to.be(6);
272 expect(ReactDOM.findDOMNode(header).value).to.be('06:02:03');
273 expect(ReactDOM.findDOMNode(input).value).to.be('06:02:03');
274 expect(picker.state.open).to.be.ok();
275
276 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
277 const option = selector.getElementsByTagName('li')[4];
278 Simulate.click(option);
279 setTimeout(next, 100);
280 }, (next) => {
281 expect(change).to.be.ok();
282 expect(change.getHourOfDay()).to.be(8);
283 expect(ReactDOM.findDOMNode(header).value).to.be('08:02:03');
284 expect(ReactDOM.findDOMNode(input).value).to.be('08:02:03');
285 expect(picker.state.open).to.be.ok();
286
287 next();
288 }], () => {
289 done();
290 });
291 });
190 }); 292 });
191}); 293});