aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TimePicker.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/TimePicker.spec.jsx
parent38ecfddfa7719dfa88b11a2113b53b6ffc8842d5 (diff)
downloadtime-picker-e9060dda0dd04e99666ff29efe459ebc7d7c65a7.tar.gz
time-picker-e9060dda0dd04e99666ff29efe459ebc7d7c65a7.tar.zst
time-picker-e9060dda0dd04e99666ff29efe459ebc7d7c65a7.zip
lint
Diffstat (limited to 'tests/TimePicker.spec.jsx')
-rw-r--r--tests/TimePicker.spec.jsx101
1 files changed, 47 insertions, 54 deletions
diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx
index 5bd056e..95a1fd1 100644
--- a/tests/TimePicker.spec.jsx
+++ b/tests/TimePicker.spec.jsx
@@ -3,21 +3,27 @@ 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';
9 9
10import DateTimeFormat from 'gregorian-calendar-format'; 10import DateTimeFormat from 'gregorian-calendar-format';
11import GregorianCalendar from 'gregorian-calendar';
12import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; 11import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
13import TimePickerLocale from '../src/locale/zh_CN'; 12import TimePickerLocale from '../src/locale/zh_CN';
14 13
15describe('TimePicker', function () { 14function formatTime(time, formatter) {
16 var container; 15 return formatter.parse(time, {
16 locale: zhCn,
17 obeyCount: true,
18 });
19}
20
21describe('TimePicker', () => {
22 let container;
17 23
18 function renderPicker(props) { 24 function renderPicker(props) {
19 var showSecond = true; 25 const showSecond = true;
20 var formatter = new DateTimeFormat('HH:mm:ss'); 26 const formatter = new DateTimeFormat('HH:mm:ss');
21 27
22 return ReactDOM.render( 28 return ReactDOM.render(
23 <TimePicker 29 <TimePicker
@@ -30,8 +36,8 @@ describe('TimePicker', function () {
30 } 36 }
31 37
32 function renderPickerWithoutSeconds(props) { 38 function renderPickerWithoutSeconds(props) {
33 var showSecond = false; 39 const showSecond = false;
34 var formatter = new DateTimeFormat('HH:mm'); 40 const formatter = new DateTimeFormat('HH:mm');
35 41
36 return ReactDOM.render( 42 return ReactDOM.render(
37 <TimePicker 43 <TimePicker
@@ -43,44 +49,37 @@ describe('TimePicker', function () {
43 />, container); 49 />, container);
44 } 50 }
45 51
46 function formatTime(time, formatter) { 52 beforeEach(() => {
47 return formatter.parse(time, {
48 locale: zhCn,
49 obeyCount: true,
50 });
51 }
52
53 beforeEach(function () {
54 container = document.createElement('div'); 53 container = document.createElement('div');
55 document.body.appendChild(container); 54 document.body.appendChild(container);
56 }); 55 });
57 56
58 afterEach(function () { 57 afterEach(() => {
59 ReactDOM.unmountComponentAtNode(container); 58 ReactDOM.unmountComponentAtNode(container);
60 document.body.removeChild(container); 59 document.body.removeChild(container);
61 }); 60 });
62 61
63 describe('render panel to body', function () { 62 describe('render panel to body', () => {
64 it('popup correctly', function (done) { 63 it('popup correctly', (done) => {
65 var change; 64 let change;
66 var picker = renderPicker({ 65 const picker = renderPicker({
67 onChange: function (v) { 66 onChange(v) {
68 change = v; 67 change = v;
69 } 68 },
70 }); 69 });
71 expect(picker.state.open).not.to.be.ok(); 70 expect(picker.state.open).not.to.be.ok();
72 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 71 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
73 expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58'); 72 expect(ReactDOM.findDOMNode(input).value).to.be('12:57:58');
74 async.series([function (next) { 73 async.series([(next) => {
75 Simulate.click(input); 74 Simulate.click(input);
76 setTimeout(next, 100); 75 setTimeout(next, 100);
77 }, function (next) { 76 }, (next) => {
78 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok(); 77 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
79 expect(picker.state.open).to.be(true); 78 expect(picker.state.open).to.be(true);
80 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; 79 const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
81 Simulate.click(hour); 80 Simulate.click(hour);
82 setTimeout(next, 100); 81 setTimeout(next, 100);
83 }, function (next) { 82 }, (next) => {
84 expect(change).to.be.ok(); 83 expect(change).to.be.ok();
85 expect(change.getHourOfDay()).to.be(1); 84 expect(change.getHourOfDay()).to.be(1);
86 expect(change.getMinutes()).to.be(57); 85 expect(change.getMinutes()).to.be(57);
@@ -88,24 +87,19 @@ describe('TimePicker', function () {
88 expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58'); 87 expect(ReactDOM.findDOMNode(input).value).to.be('01:57:58');
89 expect(picker.state.open).to.be.ok(); 88 expect(picker.state.open).to.be.ok();
90 next(); 89 next();
91 }], function () { 90 }], () => {
92 done(); 91 done();
93 }); 92 });
94 }); 93 });
95 94
96 it('destroy correctly', function (done) { 95 it('destroy correctly', (done) => {
97 var change; 96 const picker = renderPicker();
98 var picker = renderPicker({
99 onChange: function (v) {
100 change = v;
101 }
102 });
103 expect(picker.state.open).not.to.be.ok(); 97 expect(picker.state.open).not.to.be.ok();
104 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 98 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
105 async.series([function (next) { 99 async.series([(next) => {
106 Simulate.click(input); 100 Simulate.click(input);
107 setTimeout(next, 100); 101 setTimeout(next, 100);
108 }, function (next) { 102 }, (next) => {
109 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok(); 103 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-panel-inner')[0]).not.to.be.ok();
110 expect(picker.state.open).to.be(true); 104 expect(picker.state.open).to.be(true);
111 if (document.querySelectorAll) { 105 if (document.querySelectorAll) {
@@ -114,49 +108,48 @@ describe('TimePicker', function () {
114 expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok(); 108 expect(TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[0]).to.be.ok();
115 ReactDOM.unmountComponentAtNode(container); 109 ReactDOM.unmountComponentAtNode(container);
116 setTimeout(next, 100); 110 setTimeout(next, 100);
117 }, function (next) { 111 }, (next) => {
118 if (document.querySelectorAll) { 112 if (document.querySelectorAll) {
119 expect(document.querySelectorAll('.rc-time-picker').length).to.be(0); 113 expect(document.querySelectorAll('.rc-time-picker').length).to.be(0);
120 } 114 }
121 expect(picker.panelInstance).not.to.be.ok(); 115 expect(picker.panelInstance).not.to.be.ok();
122 next(); 116 next();
123 }], function () { 117 }], () => {
124 done(); 118 done();
125 }); 119 });
126 }); 120 });
127 }); 121 });
128 122
129 describe('render panel to body (without seconds)', function () { 123 describe('render panel to body (without seconds)', () => {
130 it('popup correctly', function (done) { 124 it('popup correctly', (done) => {
131 var change; 125 let change;
132 var picker = renderPickerWithoutSeconds({ 126 const picker = renderPickerWithoutSeconds({
133 onChange: function (v) { 127 onChange(v) {
134 change = v; 128 change = v;
135 } 129 },
136 }); 130 });
137 expect(picker.state.open).not.to.be.ok(); 131 expect(picker.state.open).not.to.be.ok();
138 var input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; 132 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0];
139 expect(ReactDOM.findDOMNode(input).value).to.be('08:24'); 133 expect(ReactDOM.findDOMNode(input).value).to.be('08:24');
140 async.series([function (next) { 134 async.series([(next) => {
141 Simulate.click(input); 135 Simulate.click(input);
142 setTimeout(next, 100); 136 setTimeout(next, 100);
143 }, function (next) { 137 }, (next) => {
144 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok(); 138 expect(TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-inner')[0]).to.be.ok();
145 expect(picker.state.open).to.be(true); 139 expect(picker.state.open).to.be(true);
146 var hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1]; 140 const hour = TestUtils.scryRenderedDOMComponentsWithTag(picker.panelInstance, 'li')[1];
147 Simulate.click(hour); 141 Simulate.click(hour);
148 setTimeout(next, 100); 142 setTimeout(next, 100);
149 }, function (next) { 143 }, (next) => {
150 expect(change).to.be.ok(); 144 expect(change).to.be.ok();
151 expect(change.getHourOfDay()).to.be(1); 145 expect(change.getHourOfDay()).to.be(1);
152 expect(change.getMinutes()).to.be(24); 146 expect(change.getMinutes()).to.be(24);
153 expect(ReactDOM.findDOMNode(input).value).to.be('01:24'); 147 expect(ReactDOM.findDOMNode(input).value).to.be('01:24');
154 expect(picker.state.open).to.be.ok(); 148 expect(picker.state.open).to.be.ok();
155 next(); 149 next();
156 }], function () { 150 }], () => {
157 done(); 151 done();
158 }); 152 });
159 }); 153 });
160 }); 154 });
161
162}); 155});