aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TimePicker.spec.jsx
diff options
context:
space:
mode:
authorMG12 <wuzhao.mail@gmail.com>2015-12-04 15:45:58 +0800
committerMG12 <wuzhao.mail@gmail.com>2015-12-04 15:45:58 +0800
commit02d1b455617089d59a5202135eb43850f42e08a1 (patch)
treed8d67cf4a66ecfb121a544d99e8f703f3f6d7fbf /tests/TimePicker.spec.jsx
parenta6978323930a81d983b0051ad61bcf81fb7a7235 (diff)
downloadtime-picker-02d1b455617089d59a5202135eb43850f42e08a1.tar.gz
time-picker-02d1b455617089d59a5202135eb43850f42e08a1.tar.zst
time-picker-02d1b455617089d59a5202135eb43850f42e08a1.zip
add header and select test case
Diffstat (limited to 'tests/TimePicker.spec.jsx')
-rw-r--r--tests/TimePicker.spec.jsx105
1 files changed, 61 insertions, 44 deletions
diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx
index 5b08a81..5bd056e 100644
--- a/tests/TimePicker.spec.jsx
+++ b/tests/TimePicker.spec.jsx
@@ -13,20 +13,34 @@ import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
13import TimePickerLocale from '../src/locale/zh_CN'; 13import TimePickerLocale from '../src/locale/zh_CN';
14 14
15describe('TimePicker', function () { 15describe('TimePicker', function () {
16 var div; 16 var container;
17 var showSecond = true;
18 var str = showSecond ? 'HH:mm:ss' : 'HH:mm';
19 var formatter = new DateTimeFormat(str);
20 17
21 function renderPicker(props) { 18 function renderPicker(props) {
19 var showSecond = true;
20 var formatter = new DateTimeFormat('HH:mm:ss');
21
22 return ReactDOM.render( 22 return ReactDOM.render(
23 <TimePicker 23 <TimePicker
24 formatter={formatter} 24 formatter={formatter}
25 locale={TimePickerLocale} 25 locale={TimePickerLocale}
26 showSecond={showSecond} 26 showSecond={showSecond}
27 defaultValue={formatTime('27:57:58', formatter)} 27 defaultValue={formatTime('12:57:58', formatter)}
28 {...props} 28 {...props}
29 />, div); 29 />, container);
30 }
31
32 function renderPickerWithoutSeconds(props) {
33 var showSecond = false;
34 var formatter = new DateTimeFormat('HH:mm');
35
36 return ReactDOM.render(
37 <TimePicker
38 formatter={formatter}
39 locale={TimePickerLocale}
40 showSecond={showSecond}
41 defaultValue={formatTime('08:24', formatter)}
42 {...props}
43 />, container);
30 } 44 }
31 45
32 function formatTime(time, formatter) { 46 function formatTime(time, formatter) {
@@ -37,48 +51,17 @@ describe('TimePicker', function () {
37 } 51 }
38 52
39 beforeEach(function () { 53 beforeEach(function () {
40 div = document.createElement('div'); 54 container = document.createElement('div');
41 document.body.appendChild(div); 55 document.body.appendChild(container);
42 }); 56 });
43 57
44 afterEach(function () { 58 afterEach(function () {
45 ReactDOM.unmountComponentAtNode(div); 59 ReactDOM.unmountComponentAtNode(container);
46 document.body.removeChild(div); 60 document.body.removeChild(container);
47 });
48
49 it('popup correctly', function (done) {
50 var change;
51 var picker = renderPicker({
52 onChange: function (v) {
53 change = v;
54 }
55 });
56 expect(picker.state.open).not.to.be.ok();
57 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
58 async.series([function (next) {
59 Simulate.click(input);
60 setTimeout(next, 100);
61 }, function (next) {
62 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
63 expect(picker.state.open).to.be(true);
64 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
65 Simulate.click(hour);
66 setTimeout(next, 100);
67 }, function (next) {
68 expect(change).to.be.ok();
69 expect(change.getHourOfDay()).to.be(1);
70 expect(change.getMinutes()).to.be(57);
71 expect(change.getSeconds()).to.be(58);
72 expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58');
73 expect(picker.state.open).to.be.ok();
74 next();
75 }], function () {
76 done();
77 });
78 }); 61 });
79 62
80 describe('render panel to body', function () { 63 describe('render panel to body', function () {
81 it('support correctly', function (done) { 64 it('popup correctly', function (done) {
82 var change; 65 var change;
83 var picker = renderPicker({ 66 var picker = renderPicker({
84 onChange: function (v) { 67 onChange: function (v) {
@@ -87,11 +70,12 @@ describe('TimePicker', function () {
87 }); 70 });
88 expect(picker.state.open).not.to.be.ok(); 71 expect(picker.state.open).not.to.be.ok();
89 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 72 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
73 expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58');
90 async.series([function (next) { 74 async.series([function (next) {
91 Simulate.click(input); 75 Simulate.click(input);
92 setTimeout(next, 100); 76 setTimeout(next, 100);
93 }, function (next) { 77 }, function (next) {
94 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); 78 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
95 expect(picker.state.open).to.be(true); 79 expect(picker.state.open).to.be(true);
96 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; 80 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
97 Simulate.click(hour); 81 Simulate.click(hour);
@@ -128,7 +112,7 @@ describe('TimePicker', function () {
128 expect(document.querySelectorAll('.rc-time-picker').length).not.to.be(0); 112 expect(document.querySelectorAll('.rc-time-picker').length).not.to.be(0);
129 } 113 }
130 expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok(); 114 expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok();
131 ReactDOM.unmountComponentAtNode(div); 115 ReactDOM.unmountComponentAtNode(container);
132 setTimeout(next, 100); 116 setTimeout(next, 100);
133 }, function (next) { 117 }, function (next) {
134 if (document.querySelectorAll) { 118 if (document.querySelectorAll) {
@@ -142,4 +126,37 @@ describe('TimePicker', function () {
142 }); 126 });
143 }); 127 });
144 128
129 describe('render panel to body (without seconds)', function () {
130 it('popup correctly', function (done) {
131 var change;
132 var picker = renderPickerWithoutSeconds({
133 onChange: function (v) {
134 change = v;
135 }
136 });
137 expect(picker.state.open).not.to.be.ok();
138 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
139 expect(ReactDOM.findDOMNode(input).value).to.be('08:24');
140 async.series([function (next) {
141 Simulate.click(input);
142 setTimeout(next, 100);
143 }, function (next) {
144 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
145 expect(picker.state.open).to.be(true);
146 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
147 Simulate.click(hour);
148 setTimeout(next, 100);
149 }, function (next) {
150 expect(change).to.be.ok();
151 expect(change.getHourOfDay()).to.be(1);
152 expect(change.getMinutes()).to.be(24);
153 expect(ReactDOM.findDOMNode(input).value).to.be('01:24');
154 expect(picker.state.open).to.be.ok();
155 next();
156 }], function () {
157 done();
158 });
159 });
160 });
161
145}); 162});