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
+5 -5
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021-2022 The Pybricks Authors
// Copyright (c) 2021-2023 The Pybricks Authors
import { getByLabelText, waitFor } from '@testing-library/react';
import { act, getByLabelText, waitFor } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../test';
import AboutDialog from './AboutDialog';
@@ -11,7 +11,7 @@ it('should close when the button is clicked', async () => {
const [user, dialog] = testRender(<AboutDialog isOpen={true} onClose={close} />);
await user.click(dialog.getByLabelText('Close'));
await act(() => user.click(dialog.getByLabelText('Close')));
expect(close).toHaveBeenCalled();
});
@@ -25,7 +25,7 @@ it('should manage license dialog open/close', async () => {
dialog.queryByRole('dialog', { name: 'Open Source Software Licenses' }),
).toBeNull();
await user.click(dialog.getByText('Software Licenses'));
await act(() => user.click(dialog.getByText('Software Licenses')));
const licenseDialog = dialog.getByRole('dialog', {
name: 'Open Source Software Licenses',
@@ -33,7 +33,7 @@ it('should manage license dialog open/close', async () => {
expect(licenseDialog).toBeVisible();
await user.click(getByLabelText(licenseDialog, 'Close'));
await act(() => user.click(getByLabelText(licenseDialog, 'Close')));
await waitFor(() => expect(licenseDialog).not.toBeVisible());
});
+4 -4
View File
@@ -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 Activities from './Activities';
@@ -48,7 +48,7 @@ describe('Activities', () => {
);
}
await user.click(explorerTab);
await act(() => user.click(explorerTab));
for (const tab of activities.getAllByRole('tab')) {
expect(tab).toHaveAttribute('aria-selected', 'false');
@@ -68,7 +68,7 @@ describe('Activities', () => {
);
}
await user.click(settingsTab);
await act(() => user.click(settingsTab));
for (const tab of activities.getAllByRole('tab')) {
expect(tab).toHaveAttribute(
+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 { unexpectedError } from './UnexpectedErrorAlert';
@@ -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 { updateServerFailure } from './UpdateServerFailure';
@@ -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,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 { bluetoothNotAvailable } from './BluetoothNotAvailable';
@@ -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 { missingService } from './MissingService';
@@ -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 { noGatt } from './NoGatt';
@@ -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');
});
+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 { noHub } from './NoHub';
@@ -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 flash firmware when button is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /firmware/i }));
await act(() => user.click(message.getByRole('button', { name: /firmware/i })));
expect(callback).toHaveBeenCalledWith('flashFirmware');
});
+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 { noWebBluetooth } from './NoWebBluetooth';
@@ -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');
});
+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 { oldFirmware } from './OldFirmware';
@@ -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 flash firmware when button is clicked', async () => {
const [user, message] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /firmware/i }));
await act(() => user.click(message.getByRole('button', { name: /firmware/i })));
expect(callback).toHaveBeenCalledWith('flashFirmware');
});
+13 -13
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { RenderResult, cleanup } from '@testing-library/react';
import { RenderResult, act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { Toolbar } from './Toolbar';
@@ -55,7 +55,7 @@ describe('Toolbar', () => {
expect(button2).toHaveAttribute('tabindex', '-1');
expect(button3).toHaveAttribute('tabindex', '-1');
await user.tab();
await act(() => user.tab());
expect(button1).toHaveFocus();
expect(button1).not.toHaveAttribute('tabindex');
@@ -69,7 +69,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button1.focus();
await user.keyboard('{ArrowRight}');
await act(() => user.keyboard('{ArrowRight}'));
expect(button2).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -83,7 +83,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button3.focus();
await user.keyboard('{ArrowLeft}');
await act(() => user.keyboard('{ArrowLeft}'));
expect(button2).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -97,7 +97,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button3.focus();
await user.keyboard('{ArrowRight}');
await act(() => user.keyboard('{ArrowRight}'));
expect(button1).toHaveFocus();
expect(button1).not.toHaveAttribute('tabindex');
@@ -111,7 +111,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button1.focus();
await user.keyboard('{ArrowLeft}');
await act(() => user.keyboard('{ArrowLeft}'));
expect(button3).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -125,7 +125,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button3.focus();
await user.keyboard('{Home}');
await act(() => user.keyboard('{Home}'));
expect(button1).toHaveFocus();
expect(button1).not.toHaveAttribute('tabindex');
@@ -139,7 +139,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button1.focus();
await user.keyboard('{End}');
await act(() => user.keyboard('{End}'));
expect(button3).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -153,7 +153,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button2.focus();
await user.keyboard('{ArrowUp}');
await act(() => user.keyboard('{ArrowUp}'));
expect(button2).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -167,7 +167,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button2.focus();
await user.keyboard('{ArrowDown}');
await act(() => user.keyboard('{ArrowDown}'));
expect(button2).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -181,7 +181,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
button2.focus();
await user.tab();
await act(() => user.tab());
expect(document.body).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
@@ -194,7 +194,7 @@ describe('Toolbar', () => {
const { button1, button2, button3 } = getButtons(toolbar);
await user.click(button2);
await act(() => user.click(button2));
expect(button2).toHaveFocus();
expect(button1).toHaveAttribute('tabindex', '-1');
+25 -15
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2021-2023 The Pybricks Authors
import { Classes } from '@blueprintjs/core';
import { cleanup, fireEvent, waitFor } from '@testing-library/react';
import { act, cleanup, fireEvent, waitFor } from '@testing-library/react';
import * as monaco from 'monaco-editor';
import React from 'react';
import { testRender, uuid } from '../../test';
@@ -41,7 +41,7 @@ describe('Editor', () => {
editor: { openFileUuids: [testFile.uuid] },
});
await user.click(editor.getByRole('tab', { name: 'test.file' }));
await act(() => user.click(editor.getByRole('tab', { name: 'test.file' })));
expect(dispatch).toHaveBeenCalledWith(editorActivateFile(testFile.uuid));
});
@@ -56,7 +56,9 @@ describe('Editor', () => {
editor: { openFileUuids: [testFile.uuid] },
});
await user.type(editor.getByRole('tab', { name: 'test.file' }), key);
await act(() =>
user.type(editor.getByRole('tab', { name: 'test.file' }), key),
);
expect(dispatch).toHaveBeenCalledWith(
editorActivateFile(testFile.uuid),
@@ -72,7 +74,9 @@ describe('Editor', () => {
editor: { openFileUuids: [testFile.uuid] },
});
await user.click(editor.getByRole('button', { name: 'Close test.file' }));
await act(() =>
user.click(editor.getByRole('button', { name: 'Close test.file' })),
);
expect(dispatch).toHaveBeenCalledWith(editorCloseFile(testFile.uuid));
});
@@ -85,7 +89,9 @@ describe('Editor', () => {
editor: { openFileUuids: [testFile.uuid] },
});
await user.type(editor.getByRole('tab', { name: 'test.file' }), '{Delete}');
await act(() =>
user.type(editor.getByRole('tab', { name: 'test.file' }), '{Delete}'),
);
expect(dispatch).toHaveBeenCalledWith(editorCloseFile(testFile.uuid));
});
@@ -98,10 +104,12 @@ describe('Editor', () => {
editor: { openFileUuids: [testFile.uuid] },
});
await user.pointer({
keys: '[MouseMiddle]',
target: editor.getByRole('tab', { name: 'test.file' }),
});
await act(() =>
user.pointer({
keys: '[MouseMiddle]',
target: editor.getByRole('tab', { name: 'test.file' }),
}),
);
expect(dispatch).toHaveBeenCalledWith(editorCloseFile(testFile.uuid));
});
@@ -145,7 +153,7 @@ describe('Editor', () => {
expect(editor.getByRole('menuitem', { name: 'Copy' })).toHaveFocus(),
);
await user.keyboard('{Escape}');
await act(() => user.keyboard('{Escape}'));
await waitFor(() => expect(contextMenu).not.toBeInTheDocument());
@@ -169,10 +177,12 @@ describe('Editor', () => {
editor.queryByRole('menu', { name: 'Editor context menu' }),
).toBeNull();
await user.pointer({
keys: '[MouseRight]',
target: editor.getByRole('textbox', { name: /^Editor content/ }),
});
await act(() =>
user.pointer({
keys: '[MouseRight]',
target: editor.getByRole('textbox', { name: /^Editor content/ }),
}),
);
const contextMenu = await editor.findByRole('menu', {
name: 'Editor context menu',
@@ -190,7 +200,7 @@ describe('Editor', () => {
defined(overlay);
await user.click(overlay);
await act(() => user.click(overlay));
await waitFor(() => expect(contextMenu).not.toBeInTheDocument());
+24 -24
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup, waitFor } from '@testing-library/react';
import { act, cleanup, waitFor } from '@testing-library/react';
import React from 'react';
import { testRender, uuid } from '../../test';
import { FileMetadata } from '../fileStorage';
@@ -39,7 +39,7 @@ describe('archive button', () => {
const button = explorer.getByTitle('Backup all files');
expect(button).toBeEnabled();
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(explorerArchiveAllFiles());
});
});
@@ -50,7 +50,7 @@ describe('import file button', () => {
const button = explorer.getByTitle('Import a file');
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(explorerImportFiles());
});
});
@@ -61,7 +61,7 @@ describe('new file button', () => {
const button = explorer.getByTitle('Create a new file');
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(explorerCreateNewFile());
});
});
@@ -73,7 +73,7 @@ describe('tree item', () => {
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.click(treeItem);
await act(() => user.click(treeItem));
expect(dispatch).toHaveBeenCalledWith(
explorerUserActivateFile('test.file', uuid(0)),
@@ -86,8 +86,8 @@ describe('tree item', () => {
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.click(treeItem);
await user.keyboard('{Enter}');
await act(() => user.click(treeItem));
await act(() => user.keyboard('{Enter}'));
expect(dispatch).toHaveBeenCalledWith(
explorerUserActivateFile('test.file', uuid(0)),
@@ -100,14 +100,14 @@ describe('tree item', () => {
const [user, explorer, dispatch] = testRender(<Explorer />);
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.hover(treeItem);
await act(() => user.hover(treeItem));
const button = await waitFor(() =>
explorer.getByRole('button', { name: 'Duplicate test.file' }),
);
// user.click() has bad interaction with hover so we use user.pointer() instead
await user.pointer({ keys: '[MouseLeft]', target: button });
await act(() => user.pointer({ keys: '[MouseLeft]', target: button }));
expect(dispatch).toHaveBeenCalledWith(explorerDuplicateFile('test.file'));
@@ -121,8 +121,8 @@ describe('tree item', () => {
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.click(treeItem);
await user.keyboard('{Control>}d{/Control}');
await act(() => user.click(treeItem));
await act(() => user.keyboard('{Control>}d{/Control}'));
expect(dispatch).toHaveBeenCalledWith(explorerDuplicateFile('test.file'));
});
@@ -134,14 +134,14 @@ describe('tree item', () => {
const [user, explorer, dispatch] = testRender(<Explorer />);
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.hover(treeItem);
await act(() => user.hover(treeItem));
const button = await waitFor(() =>
explorer.getByRole('button', { name: 'Rename test.file' }),
);
// user.click() has bad interaction with hover so we use user.pointer() instead
await user.pointer({ keys: '[MouseLeft]', target: button });
await act(() => user.pointer({ keys: '[MouseLeft]', target: button }));
expect(dispatch).toHaveBeenCalledWith(explorerRenameFile('test.file'));
@@ -155,8 +155,8 @@ describe('tree item', () => {
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.click(treeItem);
await user.keyboard('{F2}');
await act(() => user.click(treeItem));
await act(() => user.keyboard('{F2}'));
expect(dispatch).toHaveBeenCalledWith(explorerRenameFile('test.file'));
});
@@ -168,14 +168,14 @@ describe('tree item', () => {
const [user, explorer, dispatch] = testRender(<Explorer />);
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.hover(treeItem);
await act(() => user.hover(treeItem));
const button = await waitFor(() =>
explorer.getByRole('button', { name: 'Export test.file' }),
);
// user.click() has bad interaction with hover so we use user.pointer() instead
await user.pointer({ keys: '[MouseLeft]', target: button });
await act(() => user.pointer({ keys: '[MouseLeft]', target: button }));
expect(dispatch).toHaveBeenCalledWith(explorerExportFile('test.file'));
@@ -189,8 +189,8 @@ describe('tree item', () => {
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.click(treeItem);
await user.keyboard('{Control>}e{/Control}');
await act(() => user.click(treeItem));
await act(() => user.keyboard('{Control>}e{/Control}'));
expect(dispatch).toHaveBeenCalledWith(explorerExportFile('test.file'));
});
@@ -202,14 +202,14 @@ describe('tree item', () => {
const [user, explorer, dispatch] = testRender(<Explorer />);
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.hover(treeItem);
await act(() => user.hover(treeItem));
const button = await waitFor(() =>
explorer.getByRole('button', { name: 'Delete test.file' }),
);
// user.click() has bad interaction with hover so we use user.pointer() instead
await user.pointer({ keys: '[MouseLeft]', target: button });
await act(() => user.pointer({ keys: '[MouseLeft]', target: button }));
expect(dispatch).toHaveBeenCalledWith(
explorerDeleteFile('test.file', uuid(0)),
@@ -225,8 +225,8 @@ describe('tree item', () => {
const treeItem = explorer.getByRole('treeitem', { name: 'test.file' });
await user.click(treeItem);
await user.keyboard('{Delete}');
await act(() => user.click(treeItem));
await act(() => user.keyboard('{Delete}'));
expect(dispatch).toHaveBeenCalledWith(
explorerDeleteFile('test.file', uuid(0)),
+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 { fileInUse } from './FileInUseAlert';
@@ -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 { noFilesToBackup } from './NoFilesToBackup';
@@ -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 { noPyFiles } from './NoPyFiles';
@@ -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, waitFor } from '@testing-library/react';
import { act, cleanup, waitFor } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import DeleteFileAlert from './DeleteFileAlert';
@@ -17,7 +17,7 @@ describe('accept', () => {
explorer: { deleteFileAlert: { fileName: 'test.file', isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: 'Delete' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Delete' })));
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidAccept());
});
@@ -29,7 +29,7 @@ describe('accept', () => {
await waitFor(() =>
expect(dialog.getByRole('button', { name: 'Delete' })).toHaveFocus(),
);
await user.keyboard('{Enter}');
await act(() => user.keyboard('{Enter}'));
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidAccept());
});
@@ -41,7 +41,7 @@ describe('cancel', () => {
explorer: { deleteFileAlert: { fileName: 'test.file', isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: 'Keep' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Keep' })));
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidCancel());
});
@@ -55,7 +55,7 @@ describe('cancel', () => {
expect(dialog.getByRole('button', { name: 'Delete' })).toHaveFocus(),
);
await user.keyboard('{Escape}');
await act(() => user.keyboard('{Escape}'));
expect(dispatch).toHaveBeenCalledWith(deleteFileAlertDidCancel());
});
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import DuplicateFileDialog from './DuplicateFileDialog';
@@ -20,10 +21,10 @@ describe('duplicate button', () => {
// have to type a new file name before Duplicate button is enabled
const input = dialog.getByRole('textbox', { name: 'File name' });
await waitFor(() => expect(input).toHaveFocus());
await user.type(input, 'new', { skipClick: true });
await act(() => user.type(input, 'new', { skipClick: true }));
await waitFor(() => expect(button).not.toBeDisabled());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(
duplicateFileDialogDidAccept('source.file', 'new.file'),
);
@@ -39,7 +40,7 @@ describe('duplicate button', () => {
// have to type a new file name before Duplicate button is enabled
const input = dialog.getByRole('textbox', { name: 'File name' });
await waitFor(() => expect(input).toHaveFocus());
await user.type(input, 'new{Enter}', { skipClick: true });
await act(() => user.type(input, 'new{Enter}', { skipClick: true }));
expect(dispatch).toHaveBeenCalledWith(
duplicateFileDialogDidAccept('source.file', 'new.file'),
@@ -57,7 +58,7 @@ describe('duplicate button', () => {
await waitFor(() => expect(button).toBeVisible());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(duplicateFileDialogDidCancel());
});
@@ -72,7 +73,7 @@ describe('duplicate button', () => {
expect(dialog.getByRole('textbox', { name: 'File name' })).toHaveFocus(),
);
await user.keyboard('{Escape}');
await act(() => user.keyboard('{Escape}'));
expect(dispatch).toHaveBeenCalledWith(duplicateFileDialogDidCancel());
});
@@ -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 { FileNameValidationResult } from '../../pybricksMicropython/lib';
@@ -40,7 +40,7 @@ it('should fix file names with spaces', async () => {
/>,
);
await user.click(group.getByRole('button', { name: /fix it/i }));
await act(() => user.click(group.getByRole('button', { name: /fix it/i })));
expect(callback).toHaveBeenCalledWith('test_name');
});
@@ -57,7 +57,7 @@ it('should fix file names with file extension', async () => {
/>,
);
await user.click(group.getByRole('button', { name: /fix it/i }));
await act(() => user.click(group.getByRole('button', { name: /fix it/i })));
expect(callback).toHaveBeenCalledWith('test');
});
@@ -74,7 +74,7 @@ it('should fix file names with invalid characters', async () => {
/>,
);
await user.click(group.getByRole('button', { name: /fix it/i }));
await act(() => user.click(group.getByRole('button', { name: /fix it/i })));
expect(callback).toHaveBeenCalledWith('test_name');
});
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { waitFor } from '@testing-library/dom';
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';
@@ -22,10 +22,12 @@ describe('accept', () => {
const button = dialog.getByLabelText('Create');
// have to type a file name before Create button is enabled
await user.type(dialog.getByRole('textbox', { name: 'File name' }), 'test');
await act(() =>
user.type(dialog.getByRole('textbox', { name: 'File name' }), 'test'),
);
await waitFor(() => expect(button).not.toBeDisabled());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(
newFileWizardDidAccept('test', '.py', Hub.Move),
);
@@ -36,9 +38,11 @@ describe('accept', () => {
explorer: { newFileWizard: { isOpen: true } },
});
await user.type(
dialog.getByRole('textbox', { name: 'File name' }),
'test{Enter}',
await act(() =>
user.type(
dialog.getByRole('textbox', { name: 'File name' }),
'test{Enter}',
),
);
expect(dispatch).toHaveBeenCalledWith(
@@ -53,7 +57,7 @@ describe('cancel', () => {
explorer: { newFileWizard: { isOpen: true } },
});
await user.click(dialog.getByRole('button', { name: 'Close' }));
await act(() => user.click(dialog.getByRole('button', { name: 'Close' })));
expect(dispatch).toHaveBeenCalledWith(newFileWizardDidCancel());
});
@@ -67,7 +71,7 @@ describe('cancel', () => {
expect(dialog.getByRole('textbox', { name: 'File name' })).toHaveFocus(),
);
await user.keyboard('{Escape}');
await act(() => user.keyboard('{Escape}'));
expect(dispatch).toHaveBeenCalledWith(newFileWizardDidCancel());
});
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import RenameFileDialog from './RenameFileDialog';
@@ -18,10 +19,10 @@ describe('rename button', () => {
// have to type a new file name before Rename button is enabled
const input = dialog.getByLabelText('File name');
await waitFor(() => expect(input).toHaveFocus());
await user.type(input, 'new', { skipClick: true });
await act(() => user.type(input, 'new', { skipClick: true }));
await waitFor(() => expect(button).not.toBeDisabled());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(
renameFileDialogDidAccept('old.file', 'new.file'),
);
@@ -35,7 +36,7 @@ describe('rename button', () => {
// have to type a new file name before Rename button is enabled
const input = dialog.getByLabelText('File name');
await waitFor(() => expect(input).toHaveFocus());
await user.type(input, 'new{Enter}', { skipClick: true });
await act(() => user.type(input, 'new{Enter}', { skipClick: true }));
expect(dispatch).toHaveBeenCalledWith(
renameFileDialogDidAccept('old.file', 'new.file'),
@@ -51,7 +52,7 @@ describe('rename button', () => {
await waitFor(() => expect(button).toBeVisible());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(renameFileDialogDidCancel());
});
});
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import RenameImportDialog from './RenameImportDialog';
@@ -18,10 +19,10 @@ describe('rename button', () => {
// have to type a new file name before Rename button is enabled
const input = dialog.getByLabelText('File name');
await waitFor(() => expect(input).toHaveFocus());
await user.type(input, 'new', { skipClick: true });
await act(() => user.type(input, 'new', { skipClick: true }));
await waitFor(() => expect(button).not.toBeDisabled());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(
renameImportDialogDidAccept('old.file', 'new.file'),
);
@@ -35,7 +36,7 @@ describe('rename button', () => {
// have to type a new file name before Rename button is enabled
const input = dialog.getByLabelText('File name');
await waitFor(() => expect(input).toHaveFocus());
await user.type(input, 'new{Enter}', { skipClick: true });
await act(() => user.type(input, 'new{Enter}', { skipClick: true }));
expect(dispatch).toHaveBeenCalledWith(
renameImportDialogDidAccept('old.file', 'new.file'),
@@ -51,7 +52,7 @@ describe('rename button', () => {
await waitFor(() => expect(button).toBeVisible());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(renameImportDialogDidCancel());
});
@@ -64,7 +65,7 @@ describe('rename button', () => {
await waitFor(() => expect(button).toBeVisible());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(renameImportDialogDidCancel());
});
});
@@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 The Pybricks Authors
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import RenameImportDialog from './ReplaceImportDialog';
@@ -32,11 +33,11 @@ describe('replace button', () => {
const rememberCheckBox = dialog.getByRole('checkbox', {
name: /remember/i,
});
await user.click(rememberCheckBox);
await act(() => user.click(rememberCheckBox));
}
const button = dialog.getByRole('button', { name: buttonName });
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(
replaceImportDialogDidAccept(action, remember),
@@ -53,7 +54,7 @@ describe('replace button', () => {
await waitFor(() => expect(button).toBeVisible());
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(replaceImportDialogDidCancel());
});
});
+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));
},
+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 { userProgramSize } from './UserProgramSize';
@@ -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');
});
+3 -3
View File
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { Classes } from '@blueprintjs/core';
import { cleanup } from '@testing-library/react';
import { act, cleanup } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../test';
import LicenseDialog from './LicenseDialog';
@@ -50,7 +50,7 @@ describe('LicenseDialog', () => {
expect(dialog.queryByText('Joe Somebody')).toBeNull();
// then when you click on a license name, the license is shown
await user.click(treeNode);
await act(() => user.click(treeNode));
expect(dialog.getByText('Joe Somebody')).toBeDefined();
});
});
+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, uuid } from '../../../test';
import { editorGoto } from '../../editor/actions';
@@ -18,7 +19,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 dispatch go to error when clicked', async () => {
const [user, message, dispatch] = testRender(<Toast {...toast} />);
await user.click(message.getByRole('button', { name: /go to/i }));
await act(() => user.click(message.getByRole('button', { name: /go to/i })));
expect(dispatch).toHaveBeenCalledWith(editorGoto(uuid(0), 1));
});
+8 -8
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2022-2023 The Pybricks Authors
import { cleanup, getByLabelText, waitFor } from '@testing-library/react';
import { act, cleanup, getByLabelText, waitFor } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../test';
import { firmwareInstallPybricks } from '../firmware/actions';
@@ -23,11 +23,11 @@ describe('darkMode setting switch', () => {
expect(darkMode).not.toBeChecked();
expect(localStorage.getItem('usehooks-ts-ternary-dark-mode')).toBe(null);
await user.click(darkMode);
await act(() => user.click(darkMode));
expect(darkMode).toBeChecked();
expect(localStorage.getItem('usehooks-ts-ternary-dark-mode')).toBe('"dark"');
await user.click(darkMode);
await act(() => user.click(darkMode));
expect(darkMode).not.toBeChecked();
expect(localStorage.getItem('usehooks-ts-ternary-dark-mode')).toBe('"light"');
});
@@ -40,7 +40,7 @@ describe('firmware', () => {
const button = settings.getByRole('button', {
name: 'Install Pybricks Firmware',
});
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(firmwareInstallPybricks());
});
@@ -51,7 +51,7 @@ describe('firmware', () => {
const button = settings.getByRole('button', {
name: 'Restore Official LEGO® Firmware',
});
await user.click(button);
await act(() => user.click(button));
expect(dispatch).toHaveBeenCalledWith(firmwareRestoreOfficialDialogShow());
});
@@ -65,13 +65,13 @@ describe('about dialog', () => {
expect(settings.queryByRole('dialog', { name: `About ${appName}` })).toBeNull();
await user.click(settings.getByText('About'));
await act(() => user.click(settings.getByText('About')));
const dialog = settings.getByRole('dialog', { name: `About ${appName}` });
expect(dialog).toBeVisible();
await user.click(getByLabelText(dialog, 'Close'));
await act(() => user.click(getByLabelText(dialog, 'Close')));
await waitFor(() => expect(dialog).not.toBeVisible());
});
+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 { addressCopied } from './AddressCopied';
@@ -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');
});
+4 -4
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021-2022 The Pybricks Authors
// Copyright (c) 2021-2023 The Pybricks Authors
import { waitFor } from '@testing-library/react';
import { act, waitFor } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../test';
import { BleConnectionState } from '../ble/reducers';
@@ -21,7 +21,7 @@ it('should show popover when hub name is clicked', async () => {
},
});
await user.click(statusBar.getByText(testHubName));
await act(() => user.click(statusBar.getByText(testHubName)));
await waitFor(() => statusBar.getByText('Connected to:'));
});
@@ -40,7 +40,7 @@ it('should show popover when battery is clicked', async () => {
},
});
await user.click(statusBar.getByTitle('Battery'));
await act(() => user.click(statusBar.getByTitle('Battery')));
await waitFor(() => statusBar.getByText('Battery level is OK.'));
});
@@ -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 { toggleBluetooth } from '../../../ble/actions';
@@ -16,7 +16,7 @@ it('should dispatch action when clicked', async () => {
<BluetoothButton id="test-bluetooth-button" />,
);
await user.click(button.getByRole('button', { name: 'Bluetooth' }));
await act(() => user.click(button.getByRole('button', { name: 'Bluetooth' })));
expect(dispatch).toHaveBeenCalledWith(toggleBluetooth());
});
+3 -3
View File
@@ -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 { repl } from '../../../hub/actions';
@@ -17,7 +17,7 @@ it('should dispatch action when clicked', async () => {
hub: { hasRepl: true, runtime: HubRuntimeState.Idle },
});
await user.click(button.getByRole('button', { name: 'REPL' }));
await act(() => user.click(button.getByRole('button', { name: 'REPL' })));
expect(dispatch).toHaveBeenCalledWith(repl(false));
});
+3 -3
View File
@@ -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, uuid } from '../../../../test';
import { FileFormat } from '../../../ble-pybricks-service/protocol';
@@ -22,7 +22,7 @@ it('should dispatch action when clicked', async () => {
},
});
await user.click(button.getByRole('button', { name: 'Run' }));
await act(() => user.click(button.getByRole('button', { name: 'Run' })));
expect(dispatch).toHaveBeenCalledWith(downloadAndRun(FileFormat.MultiMpy6, false));
});
+3 -3
View File
@@ -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 { stop } from '../../../hub/actions';
@@ -17,7 +17,7 @@ it('should dispatch action when clicked', async () => {
hub: { runtime: HubRuntimeState.Running },
});
await user.click(button.getByRole('button', { name: 'Stop' }));
await act(() => user.click(button.getByRole('button', { name: 'Stop' })));
expect(dispatch).toHaveBeenCalledWith(stop());
});