Skip to content

Fix date picker test resilience by selecting any available date#104

Merged
jaruesink merged 1 commit into
mainfrom
codegen-bot/fix-date-picker-test-resilience-1753299566
Jul 25, 2025
Merged

Fix date picker test resilience by selecting any available date#104
jaruesink merged 1 commit into
mainfrom
codegen-bot/fix-date-picker-test-resilience-1753299566

Conversation

@codegen-sh
Copy link
Copy Markdown
Contributor

@codegen-sh codegen-sh Bot commented Jul 23, 2025

Problem

The date picker test was failing because it was hardcoded to look for a specific date button with aria-label 'Sunday, June 1st, 2025', but that specific date might not be available in the current calendar view.

This issue was introduced when commit e93dbf368be3cc9749d758ed4a530a5b0c4105cb reverted a previous fix that had made the test more resilient.

Error

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name "Sunday, June 1st, 2025"

Solution

This PR restores the resilient approach by:

  • Finding ANY available day button instead of looking for a specific date
  • Adding a regex constant (DAY_BUTTON_REGEX) to identify day buttons by their numeric content
  • Making date format assertion flexible to handle any valid date format (\d{1,2}\/\d{1,2}\/\d{4})
  • Checking for disabled state to ensure we only click selectable dates

Changes

  • Updated apps/docs/src/remix-hook-form/date-picker.stories.tsx to use the more resilient test approach
  • Added DAY_BUTTON_REGEX constant for better performance and readability
  • Modified the test to find any available day button rather than a specific date
  • Updated date format assertion to match any valid date format

Testing

✅ All tests now pass (27/27)
✅ Date picker test specifically works regardless of which dates are available in the calendar

Context

This fix addresses the test failure that occurred after Mohsen's revert, making the test robust and preventing future failures due to calendar date availability.

Requested by: Jake Ruesink


💻 View my work🚫 Ban all checksAbout Codegen

Summary by CodeRabbit

  • Tests
    • Improved reliability of the date picker story test by generalizing the selection of a day button and broadening date format assertions.

…date

- Updated date picker story test to find any available day button instead of a specific date
- Added top-level regex constant for better performance
- Made date format assertion more flexible to handle any valid date format
- This fixes the failing test that was looking for a specific date that wasn't available

The previous revert (e93dbf3) had made the test
brittle again by hardcoding it to look for 'Sunday, June 1st, 2025'. This change
restores the resilient approach that works regardless of which dates are available
in the calendar view.

Requested by: Jake Ruesink
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 23, 2025

Walkthrough

The test play function for the date picker story was updated to select any enabled day button with numeric text in the calendar, rather than a hardcoded date. The assertion for the submitted date was also generalized to match any standard date format. A regex constant for day button identification was added.

Changes

File(s) Change Summary
apps/docs/src/remix-hook-form/date-picker.stories.tsx Generalized day selection in test play function, broadened date assertion, added day button regex

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

In the garden of code, a picker of dates,
Now finds any day, whatever awaits.
Regex in paw, the rabbit hops quick,
To test all the days with a magical click.
Dates now match wide, not just one in the sun—
Review is a breeze; this hop is well done! 🗓️🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f98b38 and 3a30f0c.

📒 Files selected for processing (1)
  • apps/docs/src/remix-hook-form/date-picker.stories.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{tsx,ts}

📄 CodeRabbit Inference Engine (.cursor/rules/form-component-patterns.mdc)

**/*.{tsx,ts}: Props interfaces should be named as ComponentNameProps
Form schemas should be named formSchema or componentNameSchema

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
{apps,packages}/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo-organization.mdc)

{apps,packages}/**/*.{ts,tsx}: Use package name imports for published packages (e.g., import { TextField } from '@lambdacurry/forms/remix-hook-form')
Import from specific entry points (e.g., import { TextField } from '@lambdacurry/forms/remix-hook-form/text-field')
Do not use relative imports across packages (e.g., avoid import { TextField } from '../../packages/components/src/remix-hook-form/text-field')
Order imports: 1) external libraries, 2) internal package imports, 3) cross-package imports, 4) type-only imports (grouped separately)

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
{apps,packages}/**/src/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo-organization.mdc)

{apps,packages}/**/src/**/*.{ts,tsx}: Use relative imports within the same package (e.g., import { FormControl } from './form')
Use relative imports for sibling directories (e.g., import { Button } from '../ui/button')

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
apps/docs/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo-organization.mdc)

In apps/docs, import from package name instead of relative paths for cross-package dependencies

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
{apps,packages}/**/src/**/*.{tsx,ts}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo-organization.mdc)

{apps,packages}/**/src/**/*.{tsx,ts}: Use kebab-case for component file names (e.g., text-field.tsx, data-table.tsx)
Match component name in PascalCase to the exported component from the file (e.g., text-field.tsx exports TextField)

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo-organization.mdc)

Avoid circular dependencies

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
apps/docs/src/remix-hook-form/*.stories.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/storybook-testing.mdc)

apps/docs/src/remix-hook-form/*.stories.tsx: Story files must be named in kebab-case and have the .stories.tsx extension, located in apps/docs/src/remix-hook-form/.
Never use regular <form> elements; always use fetcher.Form for form submissions in stories using React Router stub.
Test both client-side and server-side validation in form stories.

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
**/*.stories.tsx

📄 CodeRabbit Inference Engine (.cursor/rules/storybook-testing.mdc)

**/*.stories.tsx: Always use semantic queries (e.g., getByRole, getByLabelText) instead of CSS selectors or getByTestId in Storybook play functions.
Always use findBy* queries for async elements instead of getBy* in play functions.
Always click an input before clearing it with userEvent.clear in play functions.
Never place decorators in the meta configuration; always place decorators on individual stories.
Each story should test only one primary workflow; do not test multiple unrelated scenarios in a single story.
Always use play functions to simulate user interactions and assert results in stories.
Use the three-phase testing pattern in play functions: default state, invalid submission, valid submission.
Always include required imports for Storybook interaction testing: Meta, StoryObj, expect, userEvent, and withReactRouterStubDecorator.
Meta configuration in stories should be minimal and clean, without global decorators.
Use the step function to organize complex interactions in play functions.
Export individual test functions for reusability and group related test functions together in story files.
Stories should serve as both documentation and automated tests.
Tests should complete in under 10 seconds for fast feedback.
Use accessibility-first queries and test keyboard navigation in stories.

Files:

  • apps/docs/src/remix-hook-form/date-picker.stories.tsx
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Use accessibility-first queries and test keyboard navigation in stories.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.stories.tsx : Form components should work with the existing Storybook testing patterns
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always use play functions to simulate user interactions and assert results in stories.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Use the three-phase testing pattern in play functions: default state, invalid submission, valid submission.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always use semantic queries (e.g., getByRole, getByLabelText) instead of CSS selectors or getByTestId in Storybook play functions.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always click an input before clearing it with `userEvent.clear` in play functions.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always use `findBy*` queries for async elements instead of `getBy*` in play functions.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Use the step function to organize complex interactions in play functions.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Export individual test functions for reusability and group related test functions together in story files.
Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Stories should serve as both documentation and automated tests.
apps/docs/src/remix-hook-form/date-picker.stories.tsx (20)

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always use play functions to simulate user interactions and assert results in stories.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.stories.tsx : Form components should work with the existing Storybook testing patterns

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always use semantic queries (e.g., getByRole, getByLabelText) instead of CSS selectors or getByTestId in Storybook play functions.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Use the three-phase testing pattern in play functions: default state, invalid submission, valid submission.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to apps/docs/src/remix-hook-form/*.stories.tsx : Story files must be named in kebab-case and have the .stories.tsx extension, located in apps/docs/src/remix-hook-form/.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Use accessibility-first queries and test keyboard navigation in stories.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always click an input before clearing it with userEvent.clear in play functions.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always use findBy* queries for async elements instead of getBy* in play functions.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to apps/docs/src/remix-hook-form/*.stories.tsx : Test both client-side and server-side validation in form stories.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Export individual test functions for reusability and group related test functions together in story files.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Always include required imports for Storybook interaction testing: Meta, StoryObj, expect, userEvent, and withReactRouterStubDecorator.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to apps/docs/src/remix-hook-form/*.stories.tsx : Never use regular <form> elements; always use fetcher.Form for form submissions in stories using React Router stub.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.tsx : Use Zod schemas for all form validation

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.tsx : Always define Zod schemas with proper error messages for form validation

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Meta configuration in stories should be minimal and clean, without global decorators.

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.tsx : Use the required imports for Remix Hook Form integration, Zod, and base UI components in form-aware components

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.test.tsx : Verify server-side validation integration in form component tests

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.test.tsx : Test component composition and customization in form component tests

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/form-component-patterns.mdc:0-0
Timestamp: 2025-07-23T12:46:51.768Z
Learning: Applies to packages/components/src/remix-hook-form/**/*.test.tsx : Test both valid and invalid form states in form component tests

Learnt from: CR
PR: lambda-curry/forms#0
File: .cursor/rules/storybook-testing.mdc:0-0
Timestamp: 2025-07-23T12:48:03.183Z
Learning: Applies to **/*.stories.tsx : Tests should complete in under 10 seconds for fast feedback.

🔇 Additional comments (3)
apps/docs/src/remix-hook-form/date-picker.stories.tsx (3)

11-12: LGTM! Well-structured regex constant for day button identification.

The regex pattern correctly matches numeric day buttons and improves code readability and performance by avoiding repeated regex compilation.


131-143: Excellent resilient date selection implementation.

This change successfully addresses the test failure issue by:

  • Using semantic queries (findAllByRole) as required by coding guidelines
  • Properly filtering for enabled day buttons with numeric content
  • Including robust error handling for edge cases
  • Making the test independent of specific calendar dates

The approach aligns perfectly with Storybook testing best practices and the PR objectives.


153-154: Well-designed flexible date format assertion.

The regex pattern correctly validates standard date formats (MM/DD/YYYY or DD/MM/YYYY) while maintaining test reliability. Using findByText with the regex pattern follows the async querying best practices from the coding guidelines.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codegen-bot/fix-date-picker-test-resilience-1753299566

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown
Contributor

📝 Storybook Preview: View Storybook

This preview will be updated automatically when you push new changes to this PR.

Note: The preview will be available after the workflow completes and the PR is approved for deployment.

@jaruesink jaruesink merged commit 2098a2e into main Jul 25, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant