Skip to content

Commit

Permalink
[test] Fix Escape event firing event
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 1, 2024
1 parent f7feae3 commit fea8a19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ruleTester = new eslint.RuleTester({
ruleTester.run('disallow-active-element-as-key-event-target', rule, {
valid: [
"import { fireEvent } from '@mui/internal-test-utils';\nfireEvent.keyDown(getByRole('button'), { key: ' ' })",
"import { fireEvent } from '@mui/internal-test-utils';\nfireEvent.keyDown(document.body, { key: 'Esc' })",
"import { fireEvent } from '@mui/internal-test-utils';\nfireEvent.keyDown(document.body, { key: 'Escape' })",
"import { fireEvent } from '@mui/internal-test-utils';\nfireEvent.keyUp(document.body, { key: 'Tab' })",
],
invalid: [
Expand Down
8 changes: 4 additions & 4 deletions packages/mui-material/src/Dialog/Dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('<Dialog />', () => {

// keyDown not targetted at anything specific
// eslint-disable-next-line material-ui/disallow-active-element-as-key-event-target
fireEvent.keyDown(document.activeElement, { key: 'Esc' });
fireEvent.keyDown(document.activeElement, { key: 'Escape' });
expect(onClose.calledOnce).to.equal(true);

clock.tick(100);
Expand All @@ -107,10 +107,10 @@ describe('<Dialog />', () => {

// Actual Behavior when "あ" (Japanese) is entered and press the Esc for IME cancellation.
fireEvent.change(textbox, { target: { value: 'あ' } });
fireEvent.keyDown(textbox, { key: 'Esc', keyCode: 229 });
fireEvent.keyDown(textbox, { key: 'Escape', keyCode: 229 });
expect(onClose.callCount).to.equal(0);

fireEvent.keyDown(textbox, { key: 'Esc' });
fireEvent.keyDown(textbox, { key: 'Escape' });
expect(onClose.callCount).to.equal(1);
});

Expand Down Expand Up @@ -143,7 +143,7 @@ describe('<Dialog />', () => {
dialog.click();
// keyDown is not targetted at anything specific.
// eslint-disable-next-line material-ui/disallow-active-element-as-key-event-target
fireEvent.keyDown(document.activeElement, { key: 'Esc' });
fireEvent.keyDown(document.activeElement, { key: 'Escape' });
});

expect(onClose.callCount).to.equal(0);
Expand Down

0 comments on commit fea8a19

Please sign in to comment.