test: wrap all user calls in act()

Some user events trigger react dom changes. These need to be wrapped in
act() to avoid a warning printed to the console. To be save, we wrap
all instances.
This commit is contained in:
David Lechner
2023-03-10 18:16:27 -06:00
committed by David Lechner
parent 78290eb927
commit d88ce8998f
42 changed files with 212 additions and 172 deletions
+3 -2
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { dfuError } from './DfuError';
@@ -12,7 +13,7 @@ it('should dismiss when close is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
});
@@ -23,7 +24,7 @@ it('should try again when clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /again/i }));
await act(() => user.click(message.getByRole('button', { name: /again/i })));
expect(callback).toHaveBeenCalledWith('tryAgain');
});
+2 -1
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { flashProgress } from './FlashProgress';
@@ -16,7 +17,7 @@ it.each(['erase' as ActionType, 'flash' as ActionType])(
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
},
+3 -2
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { isLinux, isWindows } from '../../utils/os';
@@ -19,7 +20,7 @@ it('should dismiss when close is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
});
@@ -33,7 +34,7 @@ it('should install windows driver when clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /driver/i }));
await act(() => user.click(message.getByRole('button', { name: /driver/i })));
expect(callback).toHaveBeenCalledWith('installWindowsDriver');
});
+2 -1
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { noDfuInterface } from './NoDfuInterface';
@@ -12,7 +13,7 @@ it('should dismiss when close is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
});
+2 -1
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { noWebUsb } from './NoWebUsb';
@@ -12,7 +13,7 @@ it('should dismiss when close is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
});
+2 -1
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { releaseButton } from './ReleaseButton';
@@ -12,7 +13,7 @@ it('should dismiss when close is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /close/i }));
await act(() => user.click(message.getByRole('button', { name: /close/i })));
expect(callback).toHaveBeenCalledWith('dismiss');
});
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import DfuWindowsDriverInstallDialog from './DfuWindowsDriverInstallDialog';
@@ -19,7 +19,7 @@ it('should dispatch action when the close button is pressed', async () => {
firmware: { dfuWindowsDriverInstallDialog: { isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: 'Close' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Close' })));
expect(dispatch).toHaveBeenCalledWith(
firmwareDfuWindowsDriverInstallDialogDialogHide(),
@@ -32,10 +32,10 @@ it('should navigate when next button is pressed and dispatch action when the don
});
for (let i = 1; i < 9; i++) {
await user.click(dialog.getByRole('button', { name: 'Next' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Next' })));
}
await user.click(dialog.getByRole('button', { name: 'Done' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Done' })));
expect(dispatch).toHaveBeenCalledWith(
firmwareDfuWindowsDriverInstallDialogDialogHide(),
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { InstallPybricksDialog } from './InstallPybricksDialog';
@@ -24,7 +24,7 @@ it('should dispatch when close is clicked', async () => {
firmware: { installPybricksDialog: { isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: /close/i }));
await act(() => user.click(dialog.getByRole('button', { name: /close/i })));
expect(dispatch).toHaveBeenCalledWith(firmwareInstallPybricksDialogCancel());
});
@@ -35,17 +35,17 @@ it('should dispatch when done is clicked', async () => {
});
// first page - select hub
await user.click(dialog.getByRole('button', { name: /next/i }));
await act(() => user.click(dialog.getByRole('button', { name: /next/i })));
// second page - accept license
await user.click(dialog.getByRole('checkbox', { name: /agree/i }));
await user.click(dialog.getByRole('button', { name: /next/i }));
await act(() => user.click(dialog.getByRole('checkbox', { name: /agree/i })));
await act(() => user.click(dialog.getByRole('button', { name: /next/i })));
// third page - options
await user.click(dialog.getByRole('button', { name: /next/i }));
await act(() => user.click(dialog.getByRole('button', { name: /next/i })));
// last page
await user.click(dialog.getByRole('button', { name: /install/i }));
await act(() => user.click(dialog.getByRole('button', { name: /install/i })));
expect(dispatch).toHaveBeenCalledWith(
firmwareInstallPybricksDialogAccept(
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { Hub } from '../../components/hubPicker';
@@ -21,7 +21,7 @@ describe('closing', () => {
firmware: { restoreOfficialDialog: { isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: 'Close' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Close' })));
expect(dispatch).toHaveBeenCalledWith(firmwareRestoreOfficialDialogHide());
});
@@ -31,8 +31,8 @@ describe('closing', () => {
firmware: { restoreOfficialDialog: { isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: 'Next' }));
await user.click(dialog.getByRole('button', { name: 'Done' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Next' })));
await act(() => user.click(dialog.getByRole('button', { name: 'Done' })));
expect(dispatch).toHaveBeenCalledWith(firmwareRestoreOfficialDialogHide());
});
@@ -50,9 +50,11 @@ describe('flashing', () => {
firmware: { restoreOfficialDialog: { isOpen: true } },
});
await user.click(dialog.getByRole('radio', { name: hubName }));
await user.click(dialog.getByRole('button', { name: 'Next' }));
await user.click(dialog.getByRole('button', { name: 'Restore' }));
await act(() => user.click(dialog.getByRole('radio', { name: hubName })));
await act(() => user.click(dialog.getByRole('button', { name: 'Next' })));
await act(() =>
user.click(dialog.getByRole('button', { name: 'Restore' })),
);
expect(dispatch).toHaveBeenCalledWith(firmwareRestoreOfficialDfu(hub));
},