Skip to content

Commit

Permalink
rely on active element on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurbalduini committed Oct 10, 2024
1 parent cbb7216 commit 5355f67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable material-ui/disallow-active-element-as-key-event-target */
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
Expand Down Expand Up @@ -99,11 +100,8 @@ describe('<DigitalClock />', () => {
const options = screen.getAllByRole('option');
const lastOptionIndex = options.length - 1;

const firstElement = options[0];
const lastElement = options[lastOptionIndex];

fireEvent.keyDown(firstElement, { key: 'End' }); // moves focus to last element
fireEvent.keyDown(lastElement, { key: 'PageUp' });
fireEvent.keyDown(document.activeElement!, { key: 'End' }); // moves focus to last element
fireEvent.keyDown(document.activeElement!, { key: 'PageUp' });

expect(handleChange.callCount).to.equal(0);
expect(document.activeElement).to.equal(options[lastOptionIndex - 5]);
Expand Down Expand Up @@ -150,10 +148,9 @@ describe('<DigitalClock />', () => {
const options = screen.getAllByRole('option');
const lastOptionIndex = options.length - 1;

const firstElement = options[0];
const lastElement = options[lastOptionIndex];

fireEvent.keyDown(firstElement, { key: 'End' }); // moves focus to last element
fireEvent.keyDown(document.activeElement!, { key: 'End' }); // moves focus to last element
// moves focus 4 steps above last item using arrow up
[0, 1, 2].forEach((index) => {
fireEvent.keyDown(options[lastOptionIndex - index], { key: 'ArrowUp' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable material-ui/disallow-active-element-as-key-event-target */
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
Expand Down Expand Up @@ -114,11 +115,8 @@ describe('<MultiSectionDigitalClock />', () => {
const hoursOptions = within(hoursSectionListbox).getAllByRole('option');
const lastOptionIndex = hoursOptions.length - 1;

const firstElement = hoursOptions[0];
const lastElement = hoursOptions[lastOptionIndex];

fireEvent.keyDown(firstElement, { key: 'End' }); // moves focus to last element
fireEvent.keyDown(lastElement, { key: 'PageUp' });
fireEvent.keyDown(document.activeElement!, { key: 'End' }); // moves focus to last element
fireEvent.keyDown(document.activeElement!, { key: 'PageUp' });

expect(handleChange.callCount).to.equal(0);
expect(document.activeElement).to.equal(hoursOptions[lastOptionIndex - 5]);
Expand Down Expand Up @@ -169,10 +167,9 @@ describe('<MultiSectionDigitalClock />', () => {
const hoursOptions = within(hoursSectionListbox).getAllByRole('option');
const lastOptionIndex = hoursOptions.length - 1;

const firstElement = hoursOptions[0];
const lastElement = hoursOptions[lastOptionIndex];

fireEvent.keyDown(firstElement, { key: 'End' }); // moves focus to last element
fireEvent.keyDown(document.activeElement!, { key: 'End' }); // moves focus to last element
// moves focus 4 steps above last item using arrow up
[0, 1, 2].forEach((index) => {
fireEvent.keyDown(hoursOptions[lastOptionIndex - index], { key: 'ArrowUp' });
Expand Down

0 comments on commit 5355f67

Please sign in to comment.