Skip to content

Commit 62a0150

Browse files
Add delay after selection to fix dropdown tests
1 parent 56b14c4 commit 62a0150

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

apps/docs/src/remix-hook-form/select-custom.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { RemixFormProvider, getValidatedFormData, useRemixForm } from 'remix-hoo
99
import { z } from 'zod';
1010
import { withReactRouterStubDecorator } from '../lib/storybook/react-router-stub';
1111

12+
// Helper function to wait for a short time
13+
const waitForSelection = async (ms = 50) => new Promise(resolve => setTimeout(resolve, ms));
14+
1215
const formSchema = z.object({
1316
region: z.string().min(1, 'Please select a region'),
1417
theme: z.string().min(1, 'Please select a theme'),
@@ -233,6 +236,7 @@ Each custom component should use React.forwardRef to preserve focus, ARIA, and k
233236
await userEvent.click(themeSelect);
234237
const purple = await within(document.body).findByRole('option', { name: 'Purple' });
235238
await userEvent.click(purple);
239+
await waitForSelection();
236240
expect(themeSelect).toHaveTextContent('Purple');
237241
});
238242

@@ -241,6 +245,7 @@ Each custom component should use React.forwardRef to preserve focus, ARIA, and k
241245
await userEvent.click(fruitSelect);
242246
const banana = await within(document.body).findByRole('option', { name: '🍌 Banana' });
243247
await userEvent.click(banana);
248+
await waitForSelection();
244249
expect(fruitSelect).toHaveTextContent('🍌 Banana');
245250
});
246251

apps/docs/src/remix-hook-form/select.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { expect, userEvent, within } from '@storybook/test';
22
import { StoryContext } from '@storybook/react';
33

4+
// Helper function to wait for a short time
5+
const waitForSelection = async (ms = 50) => new Promise(resolve => setTimeout(resolve, ms));
6+
47
// Test selecting a US state
58
export const testUSStateSelection = async ({ canvasElement }: StoryContext) => {
69
const canvas = within(canvasElement);
@@ -13,6 +16,9 @@ export const testUSStateSelection = async ({ canvasElement }: StoryContext) => {
1316
const californiaOption = await within(document.body).findByRole('option', { name: 'California' });
1417
await userEvent.click(californiaOption);
1518

19+
// Wait for the selection to be applied
20+
await waitForSelection();
21+
1622
// Verify the selection
1723
expect(stateDropdown).toHaveTextContent('California');
1824
};
@@ -29,6 +35,9 @@ export const testCanadaProvinceSelection = async ({ canvasElement }: StoryContex
2935
const ontarioOption = await within(document.body).findByRole('option', { name: 'Ontario' });
3036
await userEvent.click(ontarioOption);
3137

38+
// Wait for the selection to be applied
39+
await waitForSelection();
40+
3241
// Verify the selection
3342
expect(provinceDropdown).toHaveTextContent('Ontario');
3443
};
@@ -42,18 +51,21 @@ export const testFormSubmission = async ({ canvasElement }: StoryContext) => {
4251
await userEvent.click(stateDropdown);
4352
const californiaOption = await within(document.body).findByRole('option', { name: 'California' });
4453
await userEvent.click(californiaOption);
54+
await waitForSelection();
4555

4656
// Select a province
4757
const provinceDropdown = canvas.getByLabelText('Canadian Province');
4858
await userEvent.click(provinceDropdown);
4959
const ontarioOption = await within(document.body).findByRole('option', { name: 'Ontario' });
5060
await userEvent.click(ontarioOption);
61+
await waitForSelection();
5162

5263
// Select a custom region
5364
const regionDropdown = canvas.getByLabelText('Custom Region');
5465
await userEvent.click(regionDropdown);
5566
const customOption = await within(document.body).findByRole('option', { name: 'New York' });
5667
await userEvent.click(customOption);
68+
await waitForSelection();
5769

5870
// Submit the form
5971
const submitButton = canvas.getByRole('button', { name: 'Submit' });

0 commit comments

Comments
 (0)