From 71bd9bc11f2ca6068f7977ff3511b2798f73d0c6 Mon Sep 17 00:00:00 2001 From: MG12 Date: Mon, 14 Dec 2015 00:50:41 +0800 Subject: update disabled options --- tests/Header.spec.jsx | 70 ++++++++++++++++++++++++++++++++++++++++---------- tests/Select.spec.jsx | 71 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 101 insertions(+), 40 deletions(-) (limited to 'tests') 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', () => { it('carry disabled correctly', (done) => { const picker = renderPicker({ - disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] + disabledMinutes(h) { + return [h]; + }, + disabledSeconds(h, m) { + return [h + m % 60]; + }, }); expect(picker.state.open).not.to.be.ok(); const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; @@ -138,22 +143,39 @@ describe('Header', () => { expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '12:15:78'; + ReactDOM.findDOMNode(header).value = '10:09:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); - expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78'); + expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '12:10:78'; + ReactDOM.findDOMNode(header).value = '10:10:78'; + Simulate.change(header); + setTimeout(next, 100); + }, (next) => { + expect(picker.state.open).to.be(true); + expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); + expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + + ReactDOM.findDOMNode(header).value = '10:09:19'; + Simulate.change(header); + setTimeout(next, 100); + }, (next) => { + expect(picker.state.open).to.be(true); + expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); + expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + + ReactDOM.findDOMNode(header).value = '10:09:20'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18'); - expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18'); + expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); + expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); next(); }], () => { @@ -163,8 +185,13 @@ describe('Header', () => { it('carry hidden correctly', (done) => { const picker = renderPicker({ - disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], - hideDisabledOptions: true + disabledMinutes(h) { + return [h]; + }, + disabledSeconds(h, m) { + return [h + m % 60]; + }, + hideDisabledOptions: true, }); expect(picker.state.open).not.to.be.ok(); const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; @@ -179,22 +206,39 @@ describe('Header', () => { expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '12:15:78'; + ReactDOM.findDOMNode(header).value = '10:09:78'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); - expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78'); + expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); - ReactDOM.findDOMNode(header).value = '12:10:78'; + ReactDOM.findDOMNode(header).value = '10:10:78'; + Simulate.change(header); + setTimeout(next, 100); + }, (next) => { + expect(picker.state.open).to.be(true); + expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); + expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + + ReactDOM.findDOMNode(header).value = '10:09:19'; + Simulate.change(header); + setTimeout(next, 100); + }, (next) => { + expect(picker.state.open).to.be(true); + expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); + expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); + expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); + + ReactDOM.findDOMNode(header).value = '10:09:20'; Simulate.change(header); setTimeout(next, 100); }, (next) => { expect(picker.state.open).to.be(true); - expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18'); - expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18'); + expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); + expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); next(); }], () => { 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', () => { formatter={formatter} locale={TimePickerLocale} showSecond={showSecond} - defaultValue={formatTime('01:02:03', formatter)} + defaultValue={formatTime('01:02:04', formatter)} {...props} />, container); } @@ -90,8 +90,8 @@ describe('Select', () => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; const option = selector.getElementsByTagName('li')[19]; @@ -100,8 +100,8 @@ describe('Select', () => { }, (next) => { expect(change).to.be.ok(); expect(change.getHourOfDay()).to.be(19); - expect(ReactDOM.findDOMNode(header).value).to.be('19:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('19:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('19:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('19:02:04'); expect(picker.state.open).to.be.ok(); next(); @@ -129,8 +129,8 @@ describe('Select', () => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; const option = selector.getElementsByTagName('li')[19]; @@ -139,8 +139,8 @@ describe('Select', () => { }, (next) => { expect(change).to.be.ok(); expect(change.getMinutes()).to.be(19); - expect(ReactDOM.findDOMNode(header).value).to.be('01:19:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:19:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:19:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:19:04'); expect(picker.state.open).to.be.ok(); next(); @@ -168,8 +168,8 @@ describe('Select', () => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; const option = selector.getElementsByTagName('li')[19]; @@ -194,7 +194,12 @@ describe('Select', () => { onChange(v) { change = v; }, - disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] + disabledMinutes(h) { + return [h]; + }, + disabledSeconds(h, m) { + return [h + m % 60]; + }, }); expect(picker.state.open).not.to.be.ok(); const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; @@ -208,17 +213,27 @@ describe('Select', () => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; - const option = selector.getElementsByTagName('li')[6]; + const option = selector.getElementsByTagName('li')[1]; Simulate.click(option); setTimeout(next, 100); }, (next) => { expect(change).not.to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); + expect(picker.state.open).to.be.ok(); + + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; + const option = selector.getElementsByTagName('li')[3]; + Simulate.click(option); + setTimeout(next, 100); + }, (next) => { + expect(change).not.to.be.ok(); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); expect(picker.state.open).to.be.ok(); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; @@ -228,8 +243,8 @@ describe('Select', () => { }, (next) => { expect(change).to.be.ok(); expect(change.getMinutes()).to.be(7); - expect(ReactDOM.findDOMNode(header).value).to.be('01:07:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:07:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:07:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:07:04'); expect(picker.state.open).to.be.ok(); next(); @@ -244,8 +259,10 @@ describe('Select', () => { onChange(v) { change = v; }, - disabledHours: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23], - hideDisabledOptions: true + disabledHours() { + return [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]; + }, + hideDisabledOptions: true, }); expect(picker.state.open).not.to.be.ok(); const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; @@ -259,8 +276,8 @@ describe('Select', () => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; expect(header).to.be.ok(); - expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; const option = selector.getElementsByTagName('li')[3]; @@ -269,8 +286,8 @@ describe('Select', () => { }, (next) => { expect(change).to.be.ok(); expect(change.getHourOfDay()).to.be(6); - expect(ReactDOM.findDOMNode(header).value).to.be('06:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('06:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('06:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('06:02:04'); expect(picker.state.open).to.be.ok(); const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; @@ -280,8 +297,8 @@ describe('Select', () => { }, (next) => { expect(change).to.be.ok(); expect(change.getHourOfDay()).to.be(8); - expect(ReactDOM.findDOMNode(header).value).to.be('08:02:03'); - expect(ReactDOM.findDOMNode(input).value).to.be('08:02:03'); + expect(ReactDOM.findDOMNode(header).value).to.be('08:02:04'); + expect(ReactDOM.findDOMNode(input).value).to.be('08:02:04'); expect(picker.state.open).to.be.ok(); next(); -- cgit v1.2.3