From f759a809b58e9941d708a1e95c86208dfe951e7c Mon Sep 17 00:00:00 2001 From: Hyunmo Ahn Date: Mon, 21 Jan 2019 16:25:51 +0900 Subject: [PATCH 1/3] add dbclick feature in list of search window. when double click list of search widget, widget will be opened. --- .../components/SearchItem/SearchItem.spec.jsx | 61 +++++++++++++++++++ .../__snapshots__/SearchItem.spec.jsx.snap | 2 + .../search/components/SearchItem/index.jsx | 8 +++ 3 files changed, 71 insertions(+) diff --git a/app/renderer/pages/search/components/SearchItem/SearchItem.spec.jsx b/app/renderer/pages/search/components/SearchItem/SearchItem.spec.jsx index ed91867c..9cc8610e 100644 --- a/app/renderer/pages/search/components/SearchItem/SearchItem.spec.jsx +++ b/app/renderer/pages/search/components/SearchItem/SearchItem.spec.jsx @@ -67,6 +67,67 @@ describe('Test SearchItem Component', () => { }); }); + describe('test handleFocusWidget', () => { + it('when props.item.isOpen === true', () => { + const onShowWidget = jest.fn(); + const mockEvent = { + preventDefault: jest.fn(), + }; + const wrapper = shallow( + , + ); + + wrapper.instance().handleFocusWidget(mockEvent); + + expect(mockEvent.preventDefault).toHaveBeenCalledTimes(1); + expect(onShowWidget).toHaveBeenCalledTimes(1); + expect(onShowWidget).toHaveBeenCalledWith('mock-id'); + }); + + it('when props.item.isOpen === false', () => { + const onShowWidget = jest.fn(); + const mockEvent = { + preventDefault: jest.fn(), + }; + const wrapper = shallow( + , + ); + + wrapper.instance().handleFocusWidget(mockEvent); + expect(mockEvent.preventDefault).toHaveBeenCalledTimes(0); + expect(onShowWidget).toHaveBeenCalledTimes(0); + }); + }); + + it('should call handleOpenWidget', () => { + const onShowWidget = jest.fn(); + const wrapper = shallow( + , + ); + + wrapper.instance().handleOpenWidget(); + + expect(onShowWidget).toHaveBeenCalledTimes(1); + }); + it('should call handleToggleFavorites', () => { const onUpdateInfo = jest.fn(); const wrapper = shallow( diff --git a/app/renderer/pages/search/components/SearchItem/__snapshots__/SearchItem.spec.jsx.snap b/app/renderer/pages/search/components/SearchItem/__snapshots__/SearchItem.spec.jsx.snap index 4fa80d9f..e50b665a 100644 --- a/app/renderer/pages/search/components/SearchItem/__snapshots__/SearchItem.spec.jsx.snap +++ b/app/renderer/pages/search/components/SearchItem/__snapshots__/SearchItem.spec.jsx.snap @@ -29,6 +29,7 @@ exports[`Test SearchItem Component should match to snapshot 1`] = ` `; + +exports[` should match to snapshot when state.isMouseOverInput true 1`] = ` +
+ + + +
+
+ + +
+ +
+ + +
+`; diff --git a/app/renderer/pages/widget/components/AddressBar/index.jsx b/app/renderer/pages/widget/components/AddressBar/index.jsx index fc77f43c..e2f056e0 100644 --- a/app/renderer/pages/widget/components/AddressBar/index.jsx +++ b/app/renderer/pages/widget/components/AddressBar/index.jsx @@ -46,6 +46,7 @@ class AddressBar extends React.Component { state = { addressValue: '', isMenuOpen: false, + isMouseOverInput: false, }; moreBtnRef = React.createRef(); addressInputRef = React.createRef(); @@ -102,6 +103,11 @@ class AddressBar extends React.Component { this.setState({ addressValue: e.target.value }); }; + handleAddressCancel = () => { + this.setState({ addressValue: '' }); + this.addressInputRef.current.focus(); + }; + handleAddressEnter = (e) => { const { webView } = this.props; const { addressValue: address } = this.state; @@ -150,7 +156,7 @@ class AddressBar extends React.Component { }; render() { - const { addressValue, isMenuOpen } = this.state; + const { addressValue, isMouseOverInput, isMenuOpen } = this.state; const { id, currentUrl, @@ -215,15 +221,30 @@ class AddressBar extends React.Component { )}
- this.addressInputRef.current.select()} - /> +
this.setState({ isMouseOverInput: true })} + onMouseLeave={() => this.setState({ isMouseOverInput: false })} + > + this.addressInputRef.current.select()} + /> + {isMouseOverInput && ( + + )} +