mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
fix breaking changes for user-event v14
This commit is contained in:
committed by
David Lechner
parent
4299b36e6c
commit
883807b4b4
@@ -1,8 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2022 The Pybricks Authors
|
||||
|
||||
import { cleanup, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { cleanup, fireEvent, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { testRender } from '../../../test';
|
||||
import DeleteFileAlert from './DeleteFileAlert';
|
||||
@@ -14,48 +13,56 @@ afterEach(() => {
|
||||
|
||||
describe('accept', () => {
|
||||
it('should dispatch accept action when delete button is clicked', async () => {
|
||||
const [dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
const [user, dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
explorer: { deleteFileAlert: { fileName: 'test.file', isOpen: true } },
|
||||
});
|
||||
|
||||
userEvent.click(dialog.getByRole('button', { name: 'Delete' }));
|
||||
await user.click(dialog.getByRole('button', { name: 'Delete' }));
|
||||
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidAccept());
|
||||
});
|
||||
|
||||
it('should dispatch accept action when enter is pressed ', async () => {
|
||||
const [dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
const [user, dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
explorer: { deleteFileAlert: { fileName: 'test.file', isOpen: true } },
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(dialog.getByRole('button', { name: 'Delete' })).toHaveFocus(),
|
||||
);
|
||||
userEvent.keyboard('{enter}');
|
||||
await user.keyboard('{Enter}');
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidAccept());
|
||||
});
|
||||
});
|
||||
|
||||
describe('cancel', () => {
|
||||
it('should dispatch cancel when keep button is clicked', () => {
|
||||
const [dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
it('should dispatch cancel when keep button is clicked', async () => {
|
||||
const [user, dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
explorer: { deleteFileAlert: { fileName: 'test.file', isOpen: true } },
|
||||
});
|
||||
|
||||
userEvent.click(dialog.getByRole('button', { name: 'Keep' }));
|
||||
await user.click(dialog.getByRole('button', { name: 'Keep' }));
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidCancel());
|
||||
});
|
||||
|
||||
it('should dispatch cancel when escape button is pressed', async () => {
|
||||
const [dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
const [user, dialog, dispatch] = testRender(<DeleteFileAlert />, {
|
||||
explorer: { deleteFileAlert: { fileName: 'test.file', isOpen: true } },
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(dialog.getByRole('button', { name: 'Delete' })).toHaveFocus(),
|
||||
);
|
||||
userEvent.keyboard('{esc}');
|
||||
// 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,
|
||||
});
|
||||
|
||||
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidCancel());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user