X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FHeader.spec.jsx;h=291f9387962a19c159c73151f5eeed6a78297707;hb=HEAD;hp=5ab0ba004e3a4d68516fe9d913c0bb7bc9de4b4f;hpb=3ab3a128deaf10300b31102b79458528227baa54;p=github%2Ffretlink%2Ftime-picker.git diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx index 5ab0ba0..291f938 100644 --- a/tests/Header.spec.jsx +++ b/tests/Header.spec.jsx @@ -335,8 +335,8 @@ describe('Header', () => { }); }); - it('exit correctly', (done) => { - const picker = renderPicker(); + const closeOnEscSpec = (closeOnEsc) => (done) => { + const picker = renderPicker({ closeOnEsc }); expect(picker.state.open).not.to.be.ok(); const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; @@ -359,7 +359,39 @@ describe('Header', () => { }); setTimeout(next, 100); }, (next) => { + expect(picker.state.open).to.be(!closeOnEsc); + expect((header).value).to.be('01:02:03'); + expect((input).value).to.be('01:02:03'); + + next(); + }], () => { + done(); + }); + }; + + it('exit correctly', closeOnEscSpec(true)); + + it('stays open if `closeOnEsc` is `false`', closeOnEscSpec(false)); + + it('focus on open', (done) => { + const picker = renderPicker({ + focusOnOpen: 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) => { + // this touches the focusOnOpen code, but we cannot verify the input is in focus + expect(picker.state.open).to.be(true); + header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-input')[0]; + expect(header).to.be.ok(); expect((header).value).to.be('01:02:03'); expect((input).value).to.be('01:02:03');