test: test: Remove act() warnings

This removes `Warning: An update to <component> inside a test was not wrapped inact(...)` warnings.
This commit is contained in:
regexowl 2024-07-08 11:10:38 +02:00 committed by Ondřej Ezr
parent 6964e8b312
commit 8597929ff3
21 changed files with 841 additions and 626 deletions

View file

@ -182,13 +182,14 @@ const INVALID_IMAGE_TYPE_JSON = `{
}`;
const uploadFile = async (filename: string, content: string): Promise<void> => {
const user = userEvent.setup();
const fileInput: HTMLElement | null =
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('input[type="file"]');
if (fileInput) {
const file = new File([content], filename, { type: 'application/json' });
await userEvent.upload(fileInput, file);
user.upload(fileInput, file);
}
};
@ -203,11 +204,14 @@ describe('Import model', () => {
const setUp = async () => {
renderWithReduxRouter('', {});
await user.click(await screen.findByTestId('import-blueprint-button'));
const importBlueprintBtn = await screen.findByTestId(
'import-blueprint-button'
);
await waitFor(() => user.click(importBlueprintBtn));
const reviewButton = await screen.findByRole('button', {
name: /review and finish/i,
});
expect(reviewButton).toHaveClass('pf-m-disabled');
await waitFor(() => expect(reviewButton).toHaveClass('pf-m-disabled'));
};
test('should show alert on invalid blueprint', async () => {
@ -218,7 +222,7 @@ describe('Import model', () => {
const helperText = await screen.findByText(
/not compatible with the blueprints format\./i
);
expect(helperText).toBeInTheDocument();
await waitFor(() => expect(helperText).toBeInTheDocument());
});
test('should show alert on invalid blueprint incorrect architecture', async () => {
@ -229,7 +233,7 @@ describe('Import model', () => {
const helperText = await screen.findByText(
/not compatible with the blueprints format\./i
);
expect(helperText).toBeInTheDocument();
await waitFor(() => expect(helperText).toBeInTheDocument());
});
test('should show alert on invalid blueprint incorrect image type', async () => {
@ -240,7 +244,7 @@ describe('Import model', () => {
const helperText = await screen.findByText(
/not compatible with the blueprints format\./i
);
expect(helperText).toBeInTheDocument();
await waitFor(() => expect(helperText).toBeInTheDocument());
});
test('should enable button on correct blueprint and go to wizard', async () => {
@ -248,10 +252,12 @@ describe('Import model', () => {
await uploadFile(`blueprints.json`, BLUEPRINT_JSON);
const reviewButton = screen.getByTestId('import-blueprint-finish');
await waitFor(() => expect(reviewButton).not.toHaveClass('pf-m-disabled'));
await user.click(reviewButton);
user.click(reviewButton);
expect(
await screen.findByText('Image output', { selector: 'h1' })
).toBeInTheDocument();
await waitFor(async () =>
expect(
await screen.findByText('Image output', { selector: 'h1' })
).toBeInTheDocument()
);
});
});