Skip to content

Commit 4998908

Browse files
committed
Fix: incorporate community feedback for test stability and resolve lint
- Add explicit existence checks in selectRadixOption and stories\n- Memoize onChange handlers with useCallback\n- Use findByLabelText for initial canvas anchoring\n- All lint warnings resolved
1 parent d02ca0a commit 4998908

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

apps/docs/src/lib/storybook/test-utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ export async function selectRadixOption(
1818

1919
// 1. Find and click the trigger within the component canvas
2020
const trigger = await canvas.findByRole(triggerRole, { name: triggerName });
21+
if (!trigger) throw new Error(`Trigger with role ${triggerRole} and name ${triggerName} not found`);
22+
2123
await userEvent.click(trigger);
2224

2325
// 2. Wait for the listbox to appear in the document body (Portal)
24-
// We use findByRole on screen to wait for the element to mount.
2526
// We use a slightly longer timeout for CI stability.
2627
const listbox = await screen.findByRole('listbox', {}, { timeout: 3000 });
28+
if (!listbox) throw new Error('Radix listbox (portal) not found after clicking trigger');
2729

2830
// 3. Find the option specifically WITHIN the listbox
29-
let option: HTMLElement;
31+
let option: HTMLElement | null = null;
3032
if (optionTestId) {
3133
option = await within(listbox).findByTestId(optionTestId);
3234
} else {
3335
option = await within(listbox).findByRole('option', { name: optionName });
3436
}
3537

38+
if (!option) throw new Error(`Option ${optionName || optionTestId} not found in listbox`);
39+
3640
// 4. Click the option
3741
// pointerEventsCheck: 0 is used to bypass Radix's temporary pointer-event locks during animations
3842
await userEvent.click(option, { pointerEventsCheck: 0 });

apps/docs/src/remix-hook-form/use-on-form-value-change.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,14 @@ export const ConditionalFields: Story = {
512512

513513
// Shipping address field should appear
514514
const shippingInput = await canvas.findByLabelText(/shipping address/i);
515+
if (!shippingInput) throw new Error('Shipping address input not found');
515516
expect(shippingInput).toBeInTheDocument();
516517
await userEvent.type(shippingInput, '123 Main St');
517518

518519
// Switch to pickup
520+
// Give the DOM a moment to settle after the previous interaction
521+
await new Promise((resolve) => setTimeout(resolve, 1000));
522+
519523
await selectRadixOption(canvasElement, {
520524
triggerName: /delivery type/i,
521525
optionName: /store pickup/i,
@@ -524,6 +528,7 @@ export const ConditionalFields: Story = {
524528

525529
// Store location should appear, shipping address should be gone
526530
const storeSelect = await canvas.findByRole('combobox', { name: /store location/i });
531+
if (!storeSelect) throw new Error('Store location select not found');
527532
expect(storeSelect).toBeInTheDocument();
528533

529534
// Select a store
@@ -535,6 +540,7 @@ export const ConditionalFields: Story = {
535540

536541
// Submit form
537542
const submitButton = canvas.getByRole('button', { name: /complete order/i });
543+
if (!submitButton) throw new Error('Submit button not found');
538544
await userEvent.click(submitButton);
539545

540546
// Verify success message

0 commit comments

Comments
 (0)