Content-Length: 507378 | pFad | https://github.com/coder/coder/pull/18679

F4 feat: add tests for dynamic parameters by jaaydenh · Pull Request #18679 · coder/coder · GitHub
Skip to content

feat: add tests for dynamic parameters #18679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jaaydenh
Copy link
Contributor

@jaaydenh jaaydenh commented Jun 30, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a new testing attribute to the multi-select combobox component, improving testability.
    • Expanded mock data for dynamic parameters, covering a wider range of input types and validation scenarios.
  • Bug Fixes

    • Improved loader and error handling on the experimental workspace creation page to better display WebSocket errors.
  • Tests

    • Introduced comprehensive tests for the experimental workspace creation page, including dynamic parameter updates, error handling, and form submission scenarios.

@jaaydenh jaaydenh self-assigned this Jun 30, 2025
@jaaydenh jaaydenh changed the title feat: initial commit feat: add tests for dynamic parameters Jun 30, 2025
@jaaydenh jaaydenh force-pushed the jaaydenh/dynamic-parameters-tests branch from 82e1666 to 3d3ccc3 Compare July 3, 2025 17:16
@jaaydenh jaaydenh requested a review from Emyrk July 3, 2025 21:23
@jaaydenh jaaydenh marked this pull request as ready for review July 3, 2025 21:23
@github-actions github-actions bot added the stale This issue is like stale bread. label Jul 11, 2025
@github-actions github-actions bot closed this Jul 14, 2025
@Kira-Pilot Kira-Pilot requested review from a team and BrunoQuaresma and removed request for Emyrk and a team July 17, 2025 19:01
@Kira-Pilot Kira-Pilot reopened this Jul 17, 2025
@Kira-Pilot Kira-Pilot requested a review from aslilac as a code owner July 17, 2025 19:20
@@ -276,7 +276,7 @@ const CreateWorkspacePageExperimental: FC = () => {
<Helmet>
<title>{pageTitle(title)}</title>
</Helmet>
{!latestResponse ||
{(!latestResponse && !wsError) ||
Copy link
Member

@Kira-Pilot Kira-Pilot Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an actual fix, right? Also, should we not guard against rendering if either one of these conditions is missing (regardless of whether they're missing together)?

Lastly, this boolean logic is getting difficult to reason about; I wonder if it's time to pull into a distinct boolean.

readyState: number;
};

function createMockWebSocket(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@Kira-Pilot
Copy link
Member

I think a 1000+ LOC testing PR is difficult to review thoroughly. Your websocket mock could be a PR by itself, as could your fixtures in the entities.ts. I would prefer to see this chunked up.

@github-actions github-actions bot removed the stale This issue is like stale bread. label Jul 18, 2025
@jaaydenh
Copy link
Contributor Author

@CodeRabbit review

Copy link

coderabbitai bot commented Jul 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 21, 2025

Walkthrough

The changes introduce a new data-testid prop to the MultiSelectCombobox component for improved testability and update its usage in dynamic parameter forms. A comprehensive test suite for the experimental workspace creation page is added, including extensive mock data for various parameter types. Loader rendering logic is refined, and test helpers are expanded with detailed mock parameters.

Changes

File(s) Change Summary
site/src/components/MultiSelectCombobox/MultiSelectCombobox.tsx Added optional data-testid prop to MultiSelectComboboxProps and passed it to the root element for testing purposes.
site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx Set explicit inputProps={{ id: id }} and added data-testid attribute to MultiSelectCombobox for multi-select parameter fields.
site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx Added a comprehensive test suite for the experimental workspace creation page, including custom WebSocket mocks, UI interaction tests, validation, error handling, and navigation coverage.
site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx Refactored loader display logic into a single boolean shouldShowLoader consolidating multiple loading and error conditions for cleaner rendering control.
site/src/testHelpers/entities.ts Refactored and expanded mock PreviewParameter data: added new mock parameters for dropdown, tag-select, switch, slider, multi-select, and validation scenarios, with comprehensive fields for each.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestSuite
    participant MockWebSocket
    participant CreateWorkspacePageExperimental

    User->>TestSuite: Run test
    TestSuite->>MockWebSocket: Create mock connection
    MockWebSocket->>CreateWorkspacePageExperimental: Simulate open event
    CreateWorkspacePageExperimental->>MockWebSocket: Listen for messages
    MockWebSocket->>CreateWorkspacePageExperimental: Send dynamic parameter data
    User->>CreateWorkspacePageExperimental: Interact with form fields
    CreateWorkspacePageExperimental->>MockWebSocket: Send parameter updates
    MockWebSocket->>CreateWorkspacePageExperimental: Simulate error/close events
    CreateWorkspacePageExperimental->>TestSuite: Render error or loader based on wsError/latestResponse
    User->>CreateWorkspacePageExperimental: Submit form
    CreateWorkspacePageExperimental->>TestSuite: Navigate or display errors
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~90 minutes

Poem

In the garden of code, a new test suite grows,
With mock websockets and data that flows.
Comboboxes now boast a test ID,
Dynamic forms dance in full harmony.
Mock parameters bloom, each with their own flair—
A rabbit reviewer hops, finding bugs rare! 🐇✨


📜 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 39fda2f and ba8794d.

📒 Files selected for processing (2)
  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx (1 hunks)
  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.tsx
🧰 Additional context used
📓 Path-based instructions (4)
site/**/*.tsx

📄 CodeRabbit Inference Engine (.cursorrules)

All user-facing frontend code is developed in TypeScript using React and lives in the site/ directory.

Files:

  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx
site/src/**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (.cursorrules)

React components and pages are organized in the site/src/ directory, with Jest used for testing.

Files:

  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx
site/src/**/*.tsx

📄 CodeRabbit Inference Engine (site/CLAUDE.md)

site/src/**/*.tsx: MUI components are deprecated - migrate away from these when encountered
Use shadcn/ui components first - check site/src/components for existing implementations
Emotion CSS is deprecated. Use Tailwind CSS instead.
Responsive design - use Tailwind's responsive prefixes (sm:, md:, lg:, xl:)
Do not use dark: prefix for dark mode
Group related Tailwind classes
Prefer Tailwind utilities over custom CSS when possible
Use Tailwind classes for all new styling
Replace Emotion css prop with Tailwind classes
Leverage custom color tokens: content-primary, surface-secondary, etc.
Use className with clsx for conditional styling
Don’t call component functions directly; render them via JSX. This keeps Hook rules intact and lets React optimize reconciliation.
After calling a setter you’ll still read the previous state during the same event; updates are queued and batched.
Use functional updates (setX(prev ⇒ …)) whenever next state depends on previous state.
Pass a function to useState(initialFn) for lazy initialization—it runs only on the first render.
If the next state is Object.is-equal to the current one, React skips the re-render.
An Effect takes a setup function and optional cleanup; React runs setup after commit, cleanup before the next setup or on unmount.
The dependency array must list every reactive value referenced inside the Effect, and its length must stay constant.
Effects run only on the client, never during server rendering.
Use Effects solely to synchronize with external systems; if you’re not “escaping React,” you probably don’t need one.
Every sibling element in a list needs a stable, unique key prop. Never use array indexes or Math.random(); prefer data-driven IDs.
Keys aren’t passed to children and must not change between renders; if you return multiple nodes per item, use
useRef stores a mutable .current without causing re-renders.
Avoid reading or mutating refs during render; access them in event handlers or Effects ...

Files:

  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx
site/src/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (site/CLAUDE.md)

site/src/**/*.{ts,tsx}: Use ES modules (import/export) syntax, not CommonJS (require)
Destructure imports when possible (eg. import { foo } from 'bar')
Prefer for...of over forEach for iteration
Components and custom Hooks must be pure and idempotent—same inputs → same output; move side-effects to event handlers or Effects.
Never mutate props, state, or values returned by Hooks. Always create new objects or use the setter from useState.
Only call Hooks at the top level of a function component or another custom Hook—never in loops, conditions, nested functions, or try / catch.
Only call Hooks from React functions. Regular JS functions, classes, event handlers, useMemo, etc. are off-limits.
Never pass Hooks around as values or mutate them dynamically. Keep Hook usage static and local to each component.
Don’t call Hooks (including useRef) inside loops, conditions, or map(). Extract a child component instead.

Files:

  • site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to site/src/**/*.test.{ts,tsx,js,jsx} : React components and pages are organized in the `site/src/` directory, with Jest used for testing.
Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to coderdenttest/**/* : Enterprise features have dedicated test utilities in the `coderdenttest` package.
site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx (6)

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to site/src/**/*.test.{ts,tsx,js,jsx} : React components and pages are organized in the site/src/ directory, with Jest used for testing.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.034Z
Learning: Applies to site/**/*.tsx : All user-facing frontend code is developed in TypeScript using React and lives in the site/ directory.

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.{ts,tsx} : Use ES modules (import/export) syntax, not CommonJS (require)

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.034Z
Learning: Applies to site/**/*.ts : All user-facing frontend code is developed in TypeScript using React and lives in the site/ directory.

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : After calling a setter you’ll still read the previous state during the same event; updates are queued and batched.

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Avoid reading or mutating refs during render; access them in event handlers or Effects after commit.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test-e2e
  • GitHub Check: chromatic
  • GitHub Check: lint
  • GitHub Check: gen
🔇 Additional comments (8)
site/src/pages/CreateWorkspacePage/CreateWorkspacePageExperimental.test.tsx (8)

1-23: Well-structured imports following ES modules best practices.

The imports are properly organized with clear separation between testing utilities, API types, mock data, and the component under test. Good use of destructuring and TypeScript type imports.


25-34: Clear and purposeful type definitions for WebSocket mocking.

The type definitions provide a clean interface for the WebSocket mock functionality with appropriate type safety.


160-185: Well-structured mock data for comprehensive testing scenarios.

The mock responses cover both success and error cases with realistic data structures that match the API schema.


187-246: Excellent test setup with proper mocking and cleanup.

The test setup follows best practices with comprehensive API mocking, proper WebSocket mock configuration, and clean resource management in the afterEach hook.


418-506: Comprehensive testing of dynamic parameter types.

The tests thoroughly cover different parameter types (dropdown, slider, switch, tag input, multi-select) with proper assertions and user interactions. The multi-select test correctly uses the data-testid attribute for element selection.


541-644: Excellent validation error testing with realistic scenarios.

The validation tests cover both general diagnostic errors and specific min/max constraint violations with proper error message assertions and visual styling verification.


647-801: Thorough coverage of external authentication and URL parameter handling.

The tests properly cover external auth states, auto-creation prevention, fallback modes, and custom template version handling with appropriate assertions.


731-849: Well-implemented form submission and navigation tests.

The tests verify complete workflows including form submission with correct parameter values and proper navigation after workspace creation. Good use of router state verification.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jaaydenh/dynamic-parameters-tests

🪧 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.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as outdated.

@jaaydenh jaaydenh force-pushed the jaaydenh/dynamic-parameters-tests branch from 39fda2f to ba8794d Compare July 23, 2025 23:20
@coder coder deleted a comment from coderabbitai bot Jul 23, 2025
@coder coder deleted a comment from coderabbitai bot Jul 23, 2025
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.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/coder/coder/pull/18679

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy