From bb8015eae50e18db4e80e77b698d177727c28f00 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 22 Nov 2022 14:49:22 -0600 Subject: [PATCH] test: finish TODO for escape key hack Fix was merged upstream so we can remove the hack. --- src/editor/Editor.test.tsx | 10 +--------- .../deleteFileAlert/DeleteFileAlert.test.tsx | 13 +++---------- .../DuplicateFileDialog.test.tsx | 13 +++---------- src/explorer/newFileWizard/NewFileWizard.test.tsx | 12 ++---------- 4 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/editor/Editor.test.tsx b/src/editor/Editor.test.tsx index 7a939776..ca1484a2 100644 --- a/src/editor/Editor.test.tsx +++ b/src/editor/Editor.test.tsx @@ -137,15 +137,7 @@ describe('Editor', () => { expect(editor.getByRole('menuitem', { name: 'Copy' })).toHaveFocus(), ); - // FIXME: use userEvent instead of fireEvent - // blocked by https://github.com/palantir/blueprint/pull/5349 - // await user.keyboard('{Escape}'); - user; - fireEvent.keyDown(document.activeElement ?? document, { - key: 'Escape', - keyCode: 27, - which: 27, - }); + await user.keyboard('{Escape}'); await waitFor(() => expect(contextMenu).not.toBeInTheDocument()); diff --git a/src/explorer/deleteFileAlert/DeleteFileAlert.test.tsx b/src/explorer/deleteFileAlert/DeleteFileAlert.test.tsx index f47646d4..2cf0c93e 100644 --- a/src/explorer/deleteFileAlert/DeleteFileAlert.test.tsx +++ b/src/explorer/deleteFileAlert/DeleteFileAlert.test.tsx @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { cleanup, fireEvent, waitFor } from '@testing-library/react'; +import { cleanup, waitFor } from '@testing-library/react'; import React from 'react'; import { testRender } from '../../../test'; import DeleteFileAlert from './DeleteFileAlert'; @@ -54,15 +54,8 @@ describe('cancel', () => { await waitFor(() => expect(dialog.getByRole('button', { name: 'Delete' })).toHaveFocus(), ); - // FIXME: use userEvent instead of fireEvent - // blocked by https://github.com/palantir/blueprint/pull/5349 - // await user.keyboard('{Escape}'); - user; - fireEvent.keyDown(document.activeElement ?? document, { - key: 'Escape', - keyCode: 27, - which: 27, - }); + + await user.keyboard('{Escape}'); expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidCancel()); }); diff --git a/src/explorer/duplicateFileDialog/DuplicateFileDialog.test.tsx b/src/explorer/duplicateFileDialog/DuplicateFileDialog.test.tsx index 2c8c6255..5969fcdb 100644 --- a/src/explorer/duplicateFileDialog/DuplicateFileDialog.test.tsx +++ b/src/explorer/duplicateFileDialog/DuplicateFileDialog.test.tsx @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { fireEvent, waitFor } from '@testing-library/dom'; +import { waitFor } from '@testing-library/dom'; import React from 'react'; import { testRender } from '../../../test'; import DuplicateFileDialog from './DuplicateFileDialog'; @@ -71,15 +71,8 @@ describe('duplicate button', () => { await waitFor(() => expect(dialog.getByRole('textbox', { name: 'File name' })).toHaveFocus(), ); - // FIXME: use userEvent instead of fireEvent - // blocked by https://github.com/palantir/blueprint/pull/5349 - // await user.keyboard('{Escape}'); - user; - fireEvent.keyDown(document.activeElement ?? document, { - key: 'Escape', - keyCode: 27, - which: 27, - }); + + await user.keyboard('{Escape}'); expect(dispatch).toHaveBeenCalledWith(duplicateFileDialogDidCancel()); }); diff --git a/src/explorer/newFileWizard/NewFileWizard.test.tsx b/src/explorer/newFileWizard/NewFileWizard.test.tsx index 909a8b1b..c083d731 100644 --- a/src/explorer/newFileWizard/NewFileWizard.test.tsx +++ b/src/explorer/newFileWizard/NewFileWizard.test.tsx @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { fireEvent, waitFor } from '@testing-library/dom'; +import { waitFor } from '@testing-library/dom'; import { cleanup } from '@testing-library/react'; import React from 'react'; import { testRender } from '../../../test'; @@ -67,15 +67,7 @@ describe('cancel', () => { expect(dialog.getByRole('textbox', { name: 'File name' })).toHaveFocus(), ); - // FIXME: use userEvent instead of fireEvent - // blocked by https://github.com/palantir/blueprint/pull/5349 - // await user.keyboard('{Escape}'); - user; - fireEvent.keyDown(document.activeElement ?? document, { - key: 'Escape', - keyCode: 27, - which: 27, - }); + await user.keyboard('{Escape}'); expect(dispatch).toHaveBeenCalledWith(newFileWizardDidCancel()); });