aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-14 00:50:41 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-14 00:50:41 +0800
commit71bd9bc11f2ca6068f7977ff3511b2798f73d0c6 (patch)
treee24404e929db29204fa008546377351d314f9480 /tests
parent0e62bf0b7bdc260e882fd185492939cbaed04d56 (diff)
downloadtime-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.tar.gz
time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.tar.zst
time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.zip
update disabled options
Diffstat (limited to 'tests')
-rw-r--r--tests/Header.spec.jsx70
-rw-r--r--tests/Select.spec.jsx71
2 files changed, 101 insertions, 40 deletions
diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx
index 18d61c5..e992279 100644
--- a/tests/Header.spec.jsx
+++ b/tests/Header.spec.jsx
@@ -123,7 +123,12 @@ describe('Header', () => {
123 123
124 it('carry disabled correctly', (done) => { 124 it('carry disabled correctly', (done) => {
125 const picker = renderPicker({ 125 const picker = renderPicker({
126 disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] 126 disabledMinutes(h) {
127 return [h];
128 },
129 disabledSeconds(h, m) {
130 return [h + m % 60];
131 },
127 }); 132 });
128 expect(picker.state.open).not.to.be.ok(); 133 expect(picker.state.open).not.to.be.ok();
129 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 134 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
@@ -138,22 +143,39 @@ describe('Header', () => {
138 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 143 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
139 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 144 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
140 145
141 ReactDOM.findDOMNode(header).value = '12:15:78'; 146 ReactDOM.findDOMNode(header).value = '10:09:78';
142 Simulate.change(header); 147 Simulate.change(header);
143 setTimeout(next, 100); 148 setTimeout(next, 100);
144 }, (next) => { 149 }, (next) => {
145 expect(picker.state.open).to.be(true); 150 expect(picker.state.open).to.be(true);
146 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); 151 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
147 expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78'); 152 expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78');
148 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 153 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
149 154
150 ReactDOM.findDOMNode(header).value = '12:10:78'; 155 ReactDOM.findDOMNode(header).value = '10:10:78';
156 Simulate.change(header);
157 setTimeout(next, 100);
158 }, (next) => {
159 expect(picker.state.open).to.be(true);
160 expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18');
161 expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18');
162
163 ReactDOM.findDOMNode(header).value = '10:09:19';
164 Simulate.change(header);
165 setTimeout(next, 100);
166 }, (next) => {
167 expect(picker.state.open).to.be(true);
168 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
169 expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19');
170 expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18');
171
172 ReactDOM.findDOMNode(header).value = '10:09:20';
151 Simulate.change(header); 173 Simulate.change(header);
152 setTimeout(next, 100); 174 setTimeout(next, 100);
153 }, (next) => { 175 }, (next) => {
154 expect(picker.state.open).to.be(true); 176 expect(picker.state.open).to.be(true);
155 expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18'); 177 expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20');
156 expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18'); 178 expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20');
157 179
158 next(); 180 next();
159 }], () => { 181 }], () => {
@@ -163,8 +185,13 @@ describe('Header', () => {
163 185
164 it('carry hidden correctly', (done) => { 186 it('carry hidden correctly', (done) => {
165 const picker = renderPicker({ 187 const picker = renderPicker({
166 disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], 188 disabledMinutes(h) {
167 hideDisabledOptions: true 189 return [h];
190 },
191 disabledSeconds(h, m) {
192 return [h + m % 60];
193 },
194 hideDisabledOptions: true,
168 }); 195 });
169 expect(picker.state.open).not.to.be.ok(); 196 expect(picker.state.open).not.to.be.ok();
170 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 197 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
@@ -179,22 +206,39 @@ describe('Header', () => {
179 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 206 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03');
180 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 207 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
181 208
182 ReactDOM.findDOMNode(header).value = '12:15:78'; 209 ReactDOM.findDOMNode(header).value = '10:09:78';
183 Simulate.change(header); 210 Simulate.change(header);
184 setTimeout(next, 100); 211 setTimeout(next, 100);
185 }, (next) => { 212 }, (next) => {
186 expect(picker.state.open).to.be(true); 213 expect(picker.state.open).to.be(true);
187 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); 214 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
188 expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78'); 215 expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78');
189 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 216 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03');
190 217
191 ReactDOM.findDOMNode(header).value = '12:10:78'; 218 ReactDOM.findDOMNode(header).value = '10:10:78';
219 Simulate.change(header);
220 setTimeout(next, 100);
221 }, (next) => {
222 expect(picker.state.open).to.be(true);
223 expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18');
224 expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18');
225
226 ReactDOM.findDOMNode(header).value = '10:09:19';
227 Simulate.change(header);
228 setTimeout(next, 100);
229 }, (next) => {
230 expect(picker.state.open).to.be(true);
231 expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid');
232 expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19');
233 expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18');
234
235 ReactDOM.findDOMNode(header).value = '10:09:20';
192 Simulate.change(header); 236 Simulate.change(header);
193 setTimeout(next, 100); 237 setTimeout(next, 100);
194 }, (next) => { 238 }, (next) => {
195 expect(picker.state.open).to.be(true); 239 expect(picker.state.open).to.be(true);
196 expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18'); 240 expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20');
197 expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18'); 241 expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20');
198 242
199 next(); 243 next();
200 }], () => { 244 }], () => {
diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx
index 6dd7796..f7717c7 100644
--- a/tests/Select.spec.jsx
+++ b/tests/Select.spec.jsx
@@ -29,7 +29,7 @@ describe('Select', () => {
29 formatter={formatter} 29 formatter={formatter}
30 locale={TimePickerLocale} 30 locale={TimePickerLocale}
31 showSecond={showSecond} 31 showSecond={showSecond}
32 defaultValue={formatTime('01:02:03', formatter)} 32 defaultValue={formatTime('01:02:04', formatter)}
33 {...props} 33 {...props}
34 />, container); 34 />, container);
35 } 35 }
@@ -90,8 +90,8 @@ describe('Select', () => {
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 expect(header).to.be.ok(); 92 expect(header).to.be.ok();
93 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 93 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
94 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 94 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
95 95
96 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; 96 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
97 const option = selector.getElementsByTagName('li')[19]; 97 const option = selector.getElementsByTagName('li')[19];
@@ -100,8 +100,8 @@ describe('Select', () => {
100 }, (next) => { 100 }, (next) => {
101 expect(change).to.be.ok(); 101 expect(change).to.be.ok();
102 expect(change.getHourOfDay()).to.be(19); 102 expect(change.getHourOfDay()).to.be(19);
103 expect(ReactDOM.findDOMNode(header).value).to.be('19:02:03'); 103 expect(ReactDOM.findDOMNode(header).value).to.be('19:02:04');
104 expect(ReactDOM.findDOMNode(input).value).to.be('19:02:03'); 104 expect(ReactDOM.findDOMNode(input).value).to.be('19:02:04');
105 expect(picker.state.open).to.be.ok(); 105 expect(picker.state.open).to.be.ok();
106 106
107 next(); 107 next();
@@ -129,8 +129,8 @@ describe('Select', () => {
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 expect(header).to.be.ok(); 131 expect(header).to.be.ok();
132 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 132 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
133 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 133 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
134 134
135 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; 135 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
136 const option = selector.getElementsByTagName('li')[19]; 136 const option = selector.getElementsByTagName('li')[19];
@@ -139,8 +139,8 @@ describe('Select', () => {
139 }, (next) => { 139 }, (next) => {
140 expect(change).to.be.ok(); 140 expect(change).to.be.ok();
141 expect(change.getMinutes()).to.be(19); 141 expect(change.getMinutes()).to.be(19);
142 expect(ReactDOM.findDOMNode(header).value).to.be('01:19:03'); 142 expect(ReactDOM.findDOMNode(header).value).to.be('01:19:04');
143 expect(ReactDOM.findDOMNode(input).value).to.be('01:19:03'); 143 expect(ReactDOM.findDOMNode(input).value).to.be('01:19:04');
144 expect(picker.state.open).to.be.ok(); 144 expect(picker.state.open).to.be.ok();
145 145
146 next(); 146 next();
@@ -168,8 +168,8 @@ describe('Select', () => {
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 expect(header).to.be.ok(); 170 expect(header).to.be.ok();
171 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 171 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
172 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 172 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
173 173
174 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; 174 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
175 const option = selector.getElementsByTagName('li')[19]; 175 const option = selector.getElementsByTagName('li')[19];
@@ -194,7 +194,12 @@ describe('Select', () => {
194 onChange(v) { 194 onChange(v) {
195 change = v; 195 change = v;
196 }, 196 },
197 disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] 197 disabledMinutes(h) {
198 return [h];
199 },
200 disabledSeconds(h, m) {
201 return [h + m % 60];
202 },
198 }); 203 });
199 expect(picker.state.open).not.to.be.ok(); 204 expect(picker.state.open).not.to.be.ok();
200 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 205 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
@@ -208,17 +213,27 @@ describe('Select', () => {
208 expect(picker.state.open).to.be(true); 213 expect(picker.state.open).to.be(true);
209 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 214 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
210 expect(header).to.be.ok(); 215 expect(header).to.be.ok();
211 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 216 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
212 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 217 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
213 218
214 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; 219 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
215 const option = selector.getElementsByTagName('li')[6]; 220 const option = selector.getElementsByTagName('li')[1];
216 Simulate.click(option); 221 Simulate.click(option);
217 setTimeout(next, 100); 222 setTimeout(next, 100);
218 }, (next) => { 223 }, (next) => {
219 expect(change).not.to.be.ok(); 224 expect(change).not.to.be.ok();
220 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 225 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
221 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 226 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
227 expect(picker.state.open).to.be.ok();
228
229 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2];
230 const option = selector.getElementsByTagName('li')[3];
231 Simulate.click(option);
232 setTimeout(next, 100);
233 }, (next) => {
234 expect(change).not.to.be.ok();
235 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
236 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
222 expect(picker.state.open).to.be.ok(); 237 expect(picker.state.open).to.be.ok();
223 238
224 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; 239 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1];
@@ -228,8 +243,8 @@ describe('Select', () => {
228 }, (next) => { 243 }, (next) => {
229 expect(change).to.be.ok(); 244 expect(change).to.be.ok();
230 expect(change.getMinutes()).to.be(7); 245 expect(change.getMinutes()).to.be(7);
231 expect(ReactDOM.findDOMNode(header).value).to.be('01:07:03'); 246 expect(ReactDOM.findDOMNode(header).value).to.be('01:07:04');
232 expect(ReactDOM.findDOMNode(input).value).to.be('01:07:03'); 247 expect(ReactDOM.findDOMNode(input).value).to.be('01:07:04');
233 expect(picker.state.open).to.be.ok(); 248 expect(picker.state.open).to.be.ok();
234 249
235 next(); 250 next();
@@ -244,8 +259,10 @@ describe('Select', () => {
244 onChange(v) { 259 onChange(v) {
245 change = v; 260 change = v;
246 }, 261 },
247 disabledHours: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23], 262 disabledHours() {
248 hideDisabledOptions: true 263 return [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23];
264 },
265 hideDisabledOptions: true,
249 }); 266 });
250 expect(picker.state.open).not.to.be.ok(); 267 expect(picker.state.open).not.to.be.ok();
251 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 268 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
@@ -259,8 +276,8 @@ describe('Select', () => {
259 expect(picker.state.open).to.be(true); 276 expect(picker.state.open).to.be(true);
260 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; 277 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0];
261 expect(header).to.be.ok(); 278 expect(header).to.be.ok();
262 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); 279 expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04');
263 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); 280 expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04');
264 281
265 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; 282 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
266 const option = selector.getElementsByTagName('li')[3]; 283 const option = selector.getElementsByTagName('li')[3];
@@ -269,8 +286,8 @@ describe('Select', () => {
269 }, (next) => { 286 }, (next) => {
270 expect(change).to.be.ok(); 287 expect(change).to.be.ok();
271 expect(change.getHourOfDay()).to.be(6); 288 expect(change.getHourOfDay()).to.be(6);
272 expect(ReactDOM.findDOMNode(header).value).to.be('06:02:03'); 289 expect(ReactDOM.findDOMNode(header).value).to.be('06:02:04');
273 expect(ReactDOM.findDOMNode(input).value).to.be('06:02:03'); 290 expect(ReactDOM.findDOMNode(input).value).to.be('06:02:04');
274 expect(picker.state.open).to.be.ok(); 291 expect(picker.state.open).to.be.ok();
275 292
276 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; 293 const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0];
@@ -280,8 +297,8 @@ describe('Select', () => {
280 }, (next) => { 297 }, (next) => {
281 expect(change).to.be.ok(); 298 expect(change).to.be.ok();
282 expect(change.getHourOfDay()).to.be(8); 299 expect(change.getHourOfDay()).to.be(8);
283 expect(ReactDOM.findDOMNode(header).value).to.be('08:02:03'); 300 expect(ReactDOM.findDOMNode(header).value).to.be('08:02:04');
284 expect(ReactDOM.findDOMNode(input).value).to.be('08:02:03'); 301 expect(ReactDOM.findDOMNode(input).value).to.be('08:02:04');
285 expect(picker.state.open).to.be.ok(); 302 expect(picker.state.open).to.be.ok();
286 303
287 next(); 304 next();