aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Select.spec.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Select.spec.jsx')
-rw-r--r--tests/Select.spec.jsx133
1 files changed, 63 insertions, 70 deletions
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});