Skip to content

Commit

Permalink
Fix test linting
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Aug 14, 2024
1 parent b0611c7 commit f27e6eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 46 deletions.
64 changes: 30 additions & 34 deletions packages/mui-base/src/Composite/Root/CompositeRoot.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { test } from 'mocha';
import { createRenderer, act, screen, fireEvent } from '@mui/internal-test-utils';
import { createRenderer, act, screen, fireEvent, flushMicrotasks } from '@mui/internal-test-utils';
import { describeConformance } from '../../../test/describeConformance';
import { CompositeRoot } from './CompositeRoot';
import { CompositeItem } from '../Item/CompositeItem';

function microtask() {
return act(async () => {});
}

describe('<CompositeRoot />', () => {
const { render } = createRenderer();

Expand Down Expand Up @@ -38,25 +34,25 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('2')).to.have.attribute('data-active');
expect(screen.getByTestId('2')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('2')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('2'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('3')).to.have.attribute('data-active');
expect(screen.getByTestId('3')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('3')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('3'), { key: 'ArrowUp' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('2')).to.have.attribute('data-active');
expect(screen.getByTestId('2')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('2')).toHaveFocus();

act(() => screen.getByTestId('1').focus());
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('1')).to.have.attribute('data-active');
expect(screen.getByTestId('1')).to.have.attribute('tabindex', '0');
});
Expand All @@ -74,25 +70,25 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('2')).to.have.attribute('data-active');
expect(screen.getByTestId('2')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('2')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('2'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('3')).to.have.attribute('data-active');
expect(screen.getByTestId('3')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('3')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('3'), { key: 'ArrowUp' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('2')).to.have.attribute('data-active');
expect(screen.getByTestId('2')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('2')).toHaveFocus();

act(() => screen.getByTestId('1').focus());
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('1')).to.have.attribute('data-active');
expect(screen.getByTestId('1')).to.have.attribute('tabindex', '0');
});
Expand All @@ -119,37 +115,37 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('4')).to.have.attribute('data-active');
expect(screen.getByTestId('4')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('4')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('4'), { key: 'ArrowRight' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('5')).to.have.attribute('data-active');
expect(screen.getByTestId('5')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('5')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('5'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('8')).to.have.attribute('data-active');
expect(screen.getByTestId('8')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('8')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('8'), { key: 'ArrowLeft' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('7')).to.have.attribute('data-active');
expect(screen.getByTestId('7')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('7')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('7'), { key: 'ArrowUp' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('4')).to.have.attribute('data-active');
expect(screen.getByTestId('4')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('4')).toHaveFocus();

act(() => screen.getByTestId('9').focus());
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('9')).to.have.attribute('data-active');
expect(screen.getByTestId('9')).to.have.attribute('tabindex', '0');
});
Expand Down Expand Up @@ -185,37 +181,37 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('456')).to.have.attribute('data-active');
expect(screen.getByTestId('456')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('456')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('456'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('7')).to.have.attribute('data-active');
expect(screen.getByTestId('7')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('7')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('7'), { key: 'ArrowRight' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('8')).to.have.attribute('data-active');
expect(screen.getByTestId('8')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('8')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('8'), { key: 'ArrowUp' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('456')).to.have.attribute('data-active');
expect(screen.getByTestId('456')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('456')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('456'), { key: 'ArrowUp' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('1')).to.have.attribute('data-active');
expect(screen.getByTestId('1')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('1')).toHaveFocus();

act(() => screen.getByTestId('9').focus());
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('9')).to.have.attribute('data-active');
expect(screen.getByTestId('9')).to.have.attribute('tabindex', '0');
});
Expand Down Expand Up @@ -250,37 +246,37 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('4578')).to.have.attribute('data-active');
expect(screen.getByTestId('4578')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('4578')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('4578'), { key: 'ArrowRight' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('6')).to.have.attribute('data-active');
expect(screen.getByTestId('6')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('6')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('6'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('9')).to.have.attribute('data-active');
expect(screen.getByTestId('9')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('9')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('9'), { key: 'ArrowLeft' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('4578')).to.have.attribute('data-active');
expect(screen.getByTestId('4578')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('4578')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('4578'), { key: 'ArrowUp' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('1')).to.have.attribute('data-active');
expect(screen.getByTestId('1')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('1')).toHaveFocus();

act(() => screen.getByTestId('9').focus());
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('9')).to.have.attribute('data-active');
expect(screen.getByTestId('9')).to.have.attribute('tabindex', '0');
});
Expand Down Expand Up @@ -314,7 +310,7 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('78')).to.have.attribute('data-active');
expect(screen.getByTestId('78')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('78')).toHaveFocus();
Expand Down Expand Up @@ -350,13 +346,13 @@ describe('<CompositeRoot />', () => {
expect(screen.getByTestId('1')).to.have.attribute('data-active');

fireEvent.keyDown(screen.getByTestId('1'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('4')).to.have.attribute('data-active');
expect(screen.getByTestId('4')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('4')).toHaveFocus();

fireEvent.keyDown(screen.getByTestId('4'), { key: 'ArrowDown' });
await microtask();
await flushMicrotasks();
expect(screen.getByTestId('78')).to.have.attribute('data-active');
expect(screen.getByTestId('78')).to.have.attribute('tabindex', '0');
expect(screen.getByTestId('78')).toHaveFocus();
Expand Down
21 changes: 9 additions & 12 deletions packages/mui-base/src/RadioGroup/Root/RadioGroupRoot.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';
import * as RadioGroup from '@base_ui/react/RadioGroup';
import * as Radio from '@base_ui/react/Radio';
import { expect } from 'chai';
import { spy } from 'sinon';
import { createRenderer, act, screen } from '@mui/internal-test-utils';
import { createRenderer, act, screen, fireEvent } from '@mui/internal-test-utils';
import userEvent from '@testing-library/user-event';
import * as RadioGroup from '@base_ui/react/RadioGroup';
import * as Radio from '@base_ui/react/Radio';
import { describeConformance } from '../../../test/describeConformance';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);
Expand All @@ -22,6 +22,7 @@ describe('<RadioGroup.Root />', () => {
describe('extra props', () => {
it('can override the built-in attributes', () => {
const { container } = render(<RadioGroup.Root role="switch" />);
// eslint-disable-next-line testing-library/no-node-access
expect(container.firstElementChild as HTMLElement).to.have.attribute('role', 'switch');
});
});
Expand All @@ -36,9 +37,7 @@ describe('<RadioGroup.Root />', () => {

const item = screen.getByTestId('item');

act(() => {
item.click();
});
fireEvent.click(item);

expect(handleChange.callCount).to.equal(1);
expect(handleChange.firstCall.args[0]).to.equal('a');
Expand Down Expand Up @@ -66,9 +65,7 @@ describe('<RadioGroup.Root />', () => {

expect(item).to.have.attribute('aria-checked', 'false');

act(() => {
item.click();
});
fireEvent.click(item);

expect(item).to.have.attribute('aria-checked', 'false');
});
Expand Down Expand Up @@ -98,9 +95,7 @@ describe('<RadioGroup.Root />', () => {

expect(item).to.have.attribute('aria-checked', 'false');

act(() => {
item.click();
});
fireEvent.click(item);

expect(item).to.have.attribute('aria-checked', 'false');
});
Expand All @@ -116,6 +111,7 @@ describe('<RadioGroup.Root />', () => {
const group = screen.getByTestId('root');
const item = screen.getByTestId('item');

// eslint-disable-next-line testing-library/no-node-access
const input = group.querySelector('input');

act(() => {
Expand Down Expand Up @@ -156,6 +152,7 @@ describe('<RadioGroup.Root />', () => {
it('should set the name attribute on the input', () => {
render(<RadioGroup.Root name="radio-group" />);
const group = screen.getByRole('radiogroup');
// eslint-disable-next-line testing-library/no-node-access
expect(group.nextElementSibling).to.have.attribute('name', 'radio-group');
});

Expand Down

0 comments on commit f27e6eb

Please sign in to comment.