From 0e62bf0b7bdc260e882fd185492939cbaed04d56 Mon Sep 17 00:00:00 2001 From: MG12 Date: Sun, 13 Dec 2015 00:03:19 +0800 Subject: update test case and fix bugs --- tests/Header.spec.jsx | 81 +++++++++++++++++++++++++++++++++++ tests/Select.spec.jsx | 114 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 189 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx index cc8f954..18d61c5 100644 --- a/tests/Header.spec.jsx +++ b/tests/Header.spec.jsx @@ -121,6 +121,87 @@ describe('Header', () => { }); }); + it('carry disabled correctly', (done) => { + const picker = renderPicker({ + disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + let header; + async.series([(next) => { + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + 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'); + + ReactDOM.findDOMNode(header).value = '12:15: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(input).value).to.be('01:02:03'); + + ReactDOM.findDOMNode(header).value = '12:10:78'; + 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'); + + next(); + }], () => { + done(); + }); + }); + + it('carry hidden correctly', (done) => { + const picker = renderPicker({ + disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], + hideDisabledOptions: true + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + let header; + async.series([(next) => { + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + 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'); + + ReactDOM.findDOMNode(header).value = '12:15: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(input).value).to.be('01:02:03'); + + ReactDOM.findDOMNode(header).value = '12:10:78'; + 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'); + + next(); + }], () => { + done(); + }); + }); + it('check correctly', (done) => { const picker = renderPicker(); expect(picker.state.open).not.to.be.ok(); diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx index 7e53c31..6dd7796 100644 --- a/tests/Select.spec.jsx +++ b/tests/Select.spec.jsx @@ -89,12 +89,12 @@ describe('Select', () => { }, (next) => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; - const option = selector.getElementsByTagName('li')[19]; 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'); + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; + const option = selector.getElementsByTagName('li')[19]; Simulate.click(option); setTimeout(next, 100); }, (next) => { @@ -128,12 +128,12 @@ describe('Select', () => { }, (next) => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; - const option = selector.getElementsByTagName('li')[19]; 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'); + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; + const option = selector.getElementsByTagName('li')[19]; Simulate.click(option); setTimeout(next, 100); }, (next) => { @@ -167,12 +167,12 @@ describe('Select', () => { }, (next) => { expect(picker.state.open).to.be(true); header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; - const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; - const option = selector.getElementsByTagName('li')[19]; 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'); + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; + const option = selector.getElementsByTagName('li')[19]; Simulate.click(option); setTimeout(next, 100); }, (next) => { @@ -187,5 +187,107 @@ describe('Select', () => { done(); }); }); + + it('disabled correctly', (done) => { + let change; + const picker = renderPicker({ + onChange(v) { + change = v; + }, + disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] + }); + expect(picker.state.open).not.to.be.ok(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; + let header; + async.series([(next) => { + expect(picker.state.open).to.be(false); + + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + 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'); + + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; + const option = selector.getElementsByTagName('li')[6]; + 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(picker.state.open).to.be.ok(); + + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; + const option = selector.getElementsByTagName('li')[7]; + Simulate.click(option); + setTimeout(next, 100); + }, (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(picker.state.open).to.be.ok(); + + next(); + }], () => { + done(); + }); + }); + + it('hidden correctly', (done) => { + let change; + const picker = renderPicker({ + onChange(v) { + change = v; + }, + disabledHours: [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]; + let header; + async.series([(next) => { + expect(picker.state.open).to.be(false); + + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + 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'); + + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; + const option = selector.getElementsByTagName('li')[3]; + Simulate.click(option); + setTimeout(next, 100); + }, (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(picker.state.open).to.be.ok(); + + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; + const option = selector.getElementsByTagName('li')[4]; + Simulate.click(option); + setTimeout(next, 100); + }, (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(picker.state.open).to.be.ok(); + + next(); + }], () => { + done(); + }); + }); }); }); -- cgit v1.2.3