Skip to content

Commit

Permalink
fix missing FocusScope in button tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlech committed Nov 15, 2023
1 parent 2d96838 commit 5389d59
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/toolbar/buttons/bluetooth/BluetoothButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { FocusScope } from 'react-aria';
import { testRender } from '../../../../test';
import { toggleBluetooth } from '../../../ble/actions';
import BluetoothButton from './BluetoothButton';
Expand All @@ -13,7 +14,9 @@ afterEach(() => {

it('should dispatch action when clicked', async () => {
const [user, button, dispatch] = testRender(
<BluetoothButton id="test-bluetooth-button" />,
<FocusScope>
<BluetoothButton id="test-bluetooth-button" />
</FocusScope>,
);

await act(() => user.click(button.getByRole('button', { name: 'Bluetooth' })));
Expand Down
12 changes: 9 additions & 3 deletions src/toolbar/buttons/repl/ReplButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { FocusScope } from 'react-aria';
import { testRender } from '../../../../test';
import { hubStartRepl } from '../../../hub/actions';
import { HubRuntimeState } from '../../../hub/reducers';
Expand All @@ -13,9 +14,14 @@ afterEach(() => {
});

it('should dispatch action when clicked', async () => {
const [user, button, dispatch] = testRender(<ReplButton id="test-repl-button" />, {
hub: { hasRepl: true, runtime: HubRuntimeState.Idle },
});
const [user, button, dispatch] = testRender(
<FocusScope>
<ReplButton id="test-repl-button" />
</FocusScope>,
{
hub: { hasRepl: true, runtime: HubRuntimeState.Idle },
},
);

await act(() => user.click(button.getByRole('button', { name: 'REPL' })));

Expand Down
18 changes: 12 additions & 6 deletions src/toolbar/buttons/run/RunButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { FocusScope } from 'react-aria';
import { testRender, uuid } from '../../../../test';
import { FileFormat } from '../../../ble-pybricks-service/protocol';
import { downloadAndRun } from '../../../hub/actions';
Expand All @@ -14,13 +15,18 @@ afterEach(() => {
});

it('should dispatch action when clicked', async () => {
const [user, button, dispatch] = testRender(<RunButton id="test-run-button" />, {
editor: { activeFileUuid: uuid(0) },
hub: {
runtime: HubRuntimeState.Idle,
preferredFileFormat: FileFormat.MultiMpy6,
const [user, button, dispatch] = testRender(
<FocusScope>
<RunButton id="test-run-button" />
</FocusScope>,
{
editor: { activeFileUuid: uuid(0) },
hub: {
runtime: HubRuntimeState.Idle,
preferredFileFormat: FileFormat.MultiMpy6,
},
},
});
);

await act(() => user.click(button.getByRole('button', { name: 'Run' })));

Expand Down
12 changes: 9 additions & 3 deletions src/toolbar/buttons/stop/StopButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { FocusScope } from 'react-aria';
import { testRender } from '../../../../test';
import { hubStopUserProgram } from '../../../hub/actions';
import { HubRuntimeState } from '../../../hub/reducers';
Expand All @@ -13,9 +14,14 @@ afterEach(() => {
});

it('should dispatch action when clicked', async () => {
const [user, button, dispatch] = testRender(<StopButton id="test-stop-button" />, {
hub: { runtime: HubRuntimeState.Running },
});
const [user, button, dispatch] = testRender(
<FocusScope>
<StopButton id="test-stop-button" />
</FocusScope>,
{
hub: { runtime: HubRuntimeState.Running },
},
);

await act(() => user.click(button.getByRole('button', { name: 'Stop' })));

Expand Down

0 comments on commit 5389d59

Please sign in to comment.