diff --git a/mattermost-plugin/webapp/src/components/__snapshots__/boardSelector.test.tsx.snap b/mattermost-plugin/webapp/src/components/__snapshots__/boardSelector.test.tsx.snap index 1adca377d..0d7afa983 100644 --- a/mattermost-plugin/webapp/src/components/__snapshots__/boardSelector.test.tsx.snap +++ b/mattermost-plugin/webapp/src/components/__snapshots__/boardSelector.test.tsx.snap @@ -1,5 +1,108 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`components/boardSelector escape button should unmount the component 1`] = ` +
+
+
+
+
+ +
+
+
+
+`; + exports[`components/boardSelector renders with no results 1`] = `
{ expect(container).toMatchSnapshot() }) -}) + it("escape button should unmount the component", () => { + mockedOctoClient.searchLinkableBoards.mockResolvedValueOnce([]) + + const store = mockStateStore([], state) + const origDispatch = store.dispatch + store.dispatch = jest.fn(origDispatch) + const {container, getByText} = render(wrapIntl( + + + + )) + + expect(getByText(/Link boards/i)).not.toBeNull() + + expect(store.dispatch).toHaveBeenCalledTimes(0) + + fireEvent.keyDown(getByText(/Link boards/i), { + key: "Escape", + code: "Escape", + keyCode: 27, + charCode: 27 + }) + + expect(store.dispatch).toHaveBeenCalledTimes(2) + expect(container).toMatchSnapshot() + }) +}) diff --git a/mattermost-plugin/webapp/src/components/boardSelector.tsx b/mattermost-plugin/webapp/src/components/boardSelector.tsx index 900af3212..eed6d4be5 100644 --- a/mattermost-plugin/webapp/src/components/boardSelector.tsx +++ b/mattermost-plugin/webapp/src/components/boardSelector.tsx @@ -129,10 +129,29 @@ const BoardSelector = () => { }, {boardName: showLinkBoardConfirmation?.title}) } + const closeDialog = () => { + dispatch(setLinkToChannel('')) + setResults([]) + setIsSearching(false) + setSearchQuery('') + setShowLinkBoardConfirmation(null) + } + + const handleKeyDown = (event: React.KeyboardEvent) => { + if(event.key == 'Escape') { + closeDialog() + } + } + + return ( -
+
{ /> } - onClose={() => { - dispatch(setLinkToChannel('')) - setResults([]) - setIsSearching(false) - setSearchQuery('') - setShowLinkBoardConfirmation(null) - }} > {showLinkBoardConfirmation &&