fix missing FocusScope in button tests

This commit is contained in:
David Lechner
2023-11-15 17:48:17 -06:00
committed by David Lechner
parent 2d968381c4
commit 5389d59842
4 changed files with 34 additions and 13 deletions
@@ -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';
@@ -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' })));
+9 -3
View File
@@ -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';
@@ -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' })));
+12 -6
View File
@@ -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';
@@ -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' })));
+9 -3
View File
@@ -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';
@@ -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' })));