Skip to content

Commit

Permalink
test: Improve stability of the ImagesTable tests
Browse files Browse the repository at this point in the history
This should help with tests flaking on the `act()` error.
  • Loading branch information
regexowl authored and lucasgarfield committed Oct 10, 2023
1 parent cbe710e commit 51ad859
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('On Recreate', () => {
await waitFor(() => expect(createImageButton).toBeEnabled());

// check that the FSC contains a /tmp partition
const navigation = screen.getByRole('navigation');
const navigation = await screen.findByRole('navigation');
await user.click(
await within(navigation).findByRole('button', {
name: /file system configuration/i,
Expand Down
21 changes: 10 additions & 11 deletions src/test/Components/ImagesTable/ImagesTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,14 @@ describe('Images Table', () => {
name: 'Actions',
});

await waitFor(() => {
expect(actionsButton).toBeEnabled();
});
expect(actionsButton).toBeEnabled();

user.click(actionsButton);
await user.click(actionsButton);
const recreateButton = await screen.findByRole('menuitem', {
name: 'Recreate image',
});

act(() => {
user.click(recreateButton);
});
await user.click(recreateButton);

await waitFor(() =>
expect(router.state.location.pathname).toBe(
Expand All @@ -157,15 +153,15 @@ describe('Images Table', () => {
const actionsButton = await within(rows[1]).findByRole('button', {
name: 'Actions',
});
user.click(actionsButton);
await user.click(actionsButton);

const downloadButton = await screen.findByRole('menuitem', {
name: 'Download compose request (.json)',
});

// No actual clicking because downloading is hard to test.
// Instead, we just check href and download properties of the <a> element.
const downloadLink = within(downloadButton).getByRole('link');
const downloadLink = await within(downloadButton).findByRole('link');
expect(downloadLink.download).toBe(
'request-1579d95b-8f1d-4982-8c53-8c2afa4ab04c.json'
);
Expand All @@ -174,8 +170,11 @@ describe('Images Table', () => {
expect(hrefParts.length).toBe(2);
const [header, encodedRequest] = hrefParts;
expect(header).toBe('data:text/plain;charset=utf-8');
expect(encodedRequest).toBe(
encodeURIComponent(JSON.stringify(expectedRequest, null, ' '))

await waitFor(() =>
expect(encodedRequest).toBe(
encodeURIComponent(JSON.stringify(expectedRequest, null, ' '))
)
);
});

Expand Down

0 comments on commit 51ad859

Please sign in to comment.