Skip to content

Commit

Permalink
🧵 Attempt to make interaction tests more reliable
Browse files Browse the repository at this point in the history
There seem to be race conditions between opening/closing the panel
and its children being in a visible/hidden state. Wrapping the
assertions in waitFor should enable some 'natural' retry behaviour.
  • Loading branch information
sergei-maertens committed Oct 10, 2024
1 parent 8113a80 commit 03e0a41
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/registry/addressNL/edit.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Meta, StoryObj} from '@storybook/react';
import {expect, userEvent, within} from '@storybook/test';
import {expect, userEvent, waitFor, within} from '@storybook/test';

import ComponentEditForm from '@/components/ComponentEditForm';

Expand Down Expand Up @@ -36,7 +36,9 @@ export const PostcodeValidationTabWithoutConfiguration: Story = {
await userEvent.click(canvas.getByRole('link', {name: 'Validation'}));
await userEvent.click(canvas.getAllByText('Postcode')[0]);

expect(await canvas.findByLabelText('Regular expression for postcode')).toBeVisible();
await waitFor(() => {
expect(canvas.getByLabelText('Regular expression for postcode')).toBeVisible();
});
expect(await canvas.findByText('NL')).toBeVisible();
expect(await canvas.findByText('EN')).toBeVisible();
expect(await canvas.findByText('Error code')).toBeVisible();
Expand All @@ -56,7 +58,9 @@ export const CityValidationTabWithoutConfiguration: Story = {
await userEvent.click(canvas.getByRole('link', {name: 'Validation'}));
await userEvent.click(canvas.getAllByText('City')[0]);

expect(await canvas.findByLabelText('Regular expression for city')).toBeVisible();
await waitFor(() => {
expect(canvas.getByLabelText('Regular expression for city')).toBeVisible();
});
expect(await canvas.findByText('NL')).toBeVisible();
expect(await canvas.findByText('EN')).toBeVisible();
expect(await canvas.findByText('Error code')).toBeVisible();
Expand Down Expand Up @@ -98,7 +102,9 @@ export const PostcodeValidationTabWithConfiguration: Story = {
await userEvent.click(canvas.getAllByText('Postcode')[0]);
const patternInput = await canvas.findByLabelText('Regular expression for postcode');

expect(patternInput).toBeVisible();
await waitFor(() => {
expect(patternInput).toBeVisible();
});
expect(patternInput).toHaveValue('1017 [A-Za-z]{2}');

expect(await canvas.findByDisplayValue('pattern')).toBeVisible();
Expand Down Expand Up @@ -142,7 +148,9 @@ export const CityValidationTabWithConfiguration: Story = {
await userEvent.click(canvas.getAllByText('City')[0]);
const patternInput = await canvas.findByLabelText('Regular expression for city');

expect(patternInput).toBeVisible();
await waitFor(() => {
expect(patternInput).toBeVisible();
});
expect(patternInput).toHaveValue('Amsterdam');

expect(await canvas.findByDisplayValue('pattern')).toBeVisible();
Expand Down

0 comments on commit 03e0a41

Please sign in to comment.