Skip to content

test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it. - #832

Open
junhaoliao wants to merge 2 commits into
y-scope:mainfrom
junhaoliao:react-storybook
Open

test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it.#832
junhaoliao wants to merge 2 commits into
y-scope:mainfrom
junhaoliao:react-storybook

Conversation

@junhaoliao

@junhaoliao junhaoliao commented Apr 17, 2025

Copy link
Copy Markdown
Member

Description

  1. Add React Storybook for UI testing & docs.
    1. Set up Vitest with Playwright.
  2. Extract TimeRangeInputBase from TimeRangeInput to make the component reusable and testable.
  3. Set up test cases for TimeRangeInputBase.

Checklist

Validation performed

  1. cd components/log-viewer-webui/client.
  2. npm ci
  3. npm run storybook and observed Storybook popped up in a browser with URL http://localhost:6006 .
  4. Observed a component TimeRangeInputBase showed up under a "Search" category in the left panel. image
  5. Observed the "Docs" were generated correctly from the inline comments: image
  6. Browsed through the 4 stories and found no test failures (by checking the "Component tests" tab in the bottom panel).
  7. Navigating through the steps in the "Custom" story worked without failures: image

Summary by CodeRabbit

  • New Features

    • Introduced a time range selection component with preset and custom date range options for improved query filtering.
    • Added Storybook integration for interactive UI component development and visual testing.
    • Implemented new utility functions and type definitions to support time range handling.
  • Bug Fixes

    • Ensured consistent handling of undefined string values in utility functions.
  • Chores

    • Updated configuration files to support Storybook, Vitest, and Playwright for enhanced testing and development workflows.
    • Expanded ESLint and TypeScript settings to include new files and configurations.
  • Tests

    • Added Storybook stories with user interaction tests for the new time range input component.

@junhaoliao
junhaoliao requested a review from a team as a code owner April 17, 2025 08:04
@junhaoliao
junhaoliao requested a review from davemarco April 17, 2025 08:04
@coderabbitai

coderabbitai Bot commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This set of changes introduces Storybook support, visual regression testing, and a new reusable TimeRangeInputBase component to the log-viewer-webui client. Storybook configuration files, stories, and testing setup are added, along with related scripts and dependencies in package.json. The existing time range input logic is refactored into a new base component, with updated typings and utility functions to support improved type safety and reusability. The ESLint and TypeScript configurations are expanded to include the new files. The original time range input component is removed and replaced with a wrapper that leverages the new base component.

Changes

File(s) Change Summary
.gitignore Added rule to ignore *storybook.log files under a new "Logs" section.
.storybook/main.ts, .storybook/preview.ts, .storybook/vitest.setup.ts Introduced Storybook configuration files for React with Vite, including global parameters, testing setup, and project annotations.
eslint.config.mjs, tsconfig/tsconfig.node.json Expanded ESLint and TypeScript configuration to include .storybook/ files and Vitest workspace files.
package.json Added Storybook, Chromatic, Playwright, and Vitest dependencies and scripts for UI development and testing. Modified the "antd" script for JSON correctness.
vitest.workspace.ts Added Vitest workspace configuration with Storybook plugin and browser testing setup.
src/components/TimeRangeInputBase/index.tsx, utils.tsx Added new reusable TimeRangeInputBase React component with supporting utilities and improved type safety.
src/pages/SearchPage/SearchControls/TimeRangeInput.tsx Added wrapper component using TimeRangeInputBase and store integration for updating search time range.
src/pages/SearchPage/SearchControls/TimeRangeInput/index.tsx Removed the original TimeRangeInput component implementation (now replaced by base + wrapper).
src/pages/SearchPage/SearchState.tsx Updated typings for time range state and update function to use new TimeRange type. Adjusted import paths for constants and utilities.
src/typings/time.ts Added new TimeRange type alias for consistent time range representation.
src/utils/string.ts Added safeString utility function for normalizing undefined strings.
src/stories/TimeRangeInputBase.stories.ts Added Storybook stories and test cases for TimeRangeInputBase, including presets and custom range scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TimeRangeInputBase
    participant SearchStore

    User->>TimeRangeInputBase: Selects preset from dropdown
    TimeRangeInputBase->>TimeRangeInputBase: Updates selected option state
    TimeRangeInputBase->>SearchStore: Calls onChange with mapped date range

    User->>TimeRangeInputBase: Selects "Custom" from dropdown
    TimeRangeInputBase->>TimeRangeInputBase: Shows date range picker

    User->>TimeRangeInputBase: Picks custom date range
    TimeRangeInputBase->>TimeRangeInputBase: Validates range
    TimeRangeInputBase->>SearchStore: Calls onChange with custom range
Loading

Possibly related PRs

  • feat(new-webui): Add a search bar to search view. #807: Adds a search bar with a TimeRangeInput component and search state management, which is related to this PR through the time range input feature, though this PR refactors and relocates the logic for broader reusability.

Suggested reviewers

  • davemarco
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
components/log-viewer-webui/client/src/utils/string.ts (1)

1-7: Add safeString utility.
This new helper cleanly normalizes undefined inputs to empty strings. For stricter nullish handling and to avoid masking other falsy values, consider using the nullish coalescing operator (value ?? "").

components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput.tsx (1)

5-9: Complete the JSDoc return statement

The JSDoc comment is missing a description for the @return tag.

 /**
  * Renders an input to setting the time range filter for the query.
  *
  * @return
+ * A React component for selecting time ranges in the search interface.
  */
components/log-viewer-webui/client/vitest.workspace.ts (1)

13-33: Comprehensive Vitest workspace configuration

The workspace configuration properly integrates Storybook testing with headless Chromium via Playwright. This setup aligns well with the PR objectives of adding UI testing capabilities.

Consider adding a brief comment explaining why only Chromium is specified for browser testing (if there's a specific reason).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ffbd533 and 087f63a.

⛔ Files ignored due to path filters (1)
  • components/log-viewer-webui/client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (16)
  • components/log-viewer-webui/client/.gitignore (1 hunks)
  • components/log-viewer-webui/client/.storybook/main.ts (1 hunks)
  • components/log-viewer-webui/client/.storybook/preview.ts (1 hunks)
  • components/log-viewer-webui/client/.storybook/vitest.setup.ts (1 hunks)
  • components/log-viewer-webui/client/eslint.config.mjs (1 hunks)
  • components/log-viewer-webui/client/package.json (2 hunks)
  • components/log-viewer-webui/client/src/components/TimeRangeInputBase/index.tsx (1 hunks)
  • components/log-viewer-webui/client/src/components/TimeRangeInputBase/utils.tsx (3 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput.tsx (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput/index.tsx (0 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchState.tsx (2 hunks)
  • components/log-viewer-webui/client/src/stories/TimeRangeInputBase.stories.ts (1 hunks)
  • components/log-viewer-webui/client/src/typings/time.ts (1 hunks)
  • components/log-viewer-webui/client/src/utils/string.ts (1 hunks)
  • components/log-viewer-webui/client/tsconfig/tsconfig.node.json (1 hunks)
  • components/log-viewer-webui/client/vitest.workspace.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput/index.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput.tsx
  • components/log-viewer-webui/client/src/utils/string.ts
  • components/log-viewer-webui/client/src/typings/time.ts
  • components/log-viewer-webui/client/vitest.workspace.ts
  • components/log-viewer-webui/client/src/components/TimeRangeInputBase/utils.tsx
  • components/log-viewer-webui/client/src/stories/TimeRangeInputBase.stories.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchState.tsx
  • components/log-viewer-webui/client/src/components/TimeRangeInputBase/index.tsx
🧬 Code Graph Analysis (2)
components/log-viewer-webui/client/src/components/TimeRangeInputBase/utils.tsx (2)
components/log-viewer-webui/client/src/components/TimeRangeInputBase/index.tsx (1)
  • TIME_RANGE_OPTION (103-103)
components/log-viewer-webui/client/src/typings/time.ts (1)
  • TimeRange (9-9)
components/log-viewer-webui/client/src/pages/SearchPage/SearchState.tsx (1)
components/log-viewer-webui/client/src/typings/time.ts (1)
  • TimeRange (9-9)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (26)
components/log-viewer-webui/client/.gitignore (1)

10-12: Appropriate exclusion of Storybook logs.
The addition of the “# Logs” section and the *storybook.log rule cleanly prevents transient Storybook log files from being committed.

components/log-viewer-webui/client/package.json (1)

31-49:

Details

✅ Verification successful

Verify React version compatibility and package correctness.
You’ve added react@^19.0.0 and react-dom@^19.0.0, along with other Storybook and Vitest dependencies. Please confirm these major versions are published and compatible with your environment.


🏁 Script executed:

#!/usr/bin/env bash
# Verify the latest published versions of React and React DOM
npm view react version
npm view react-dom version

Length of output: 67


React 19.x Verified (19.1.0) Availability
The ^19.0.0 specifier for both React and React DOM resolves to the published version 19.1.0, so these packages are available on npm.

• components/log-viewer-webui/client/package.json (devDependencies: lines 31–49)

components/log-viewer-webui/client/tsconfig/tsconfig.node.json (1)

4-6: Include new config files in Node tsconfig.
Adding ../.storybook/**/*.ts, ../vite.config.ts, and ../vitest.workspace.ts ensures TypeScript will type-check your Storybook setup and Vitest workspace alongside the existing configuration.

components/log-viewer-webui/client/src/typings/time.ts (1)

1-9: Define TimeRange alias.
Centralizing the tuple type [Nullable<Dayjs>, Nullable<Dayjs>] under TimeRange improves consistency and reusability across UI components and utilities.

components/log-viewer-webui/client/eslint.config.mjs (1)

24-28: ESLint configuration expanded to support Storybook files

The configuration has been properly updated to include the new Storybook TypeScript files and Vitest workspace file under the Node-specific TypeScript configuration. This change correctly supports the new Storybook and testing infrastructure being added.

components/log-viewer-webui/client/.storybook/main.ts (1)

1-20: Well-structured Storybook configuration

This is a clean and appropriate Storybook configuration for a React project using Vite. The stories pattern is correctly set up to find TypeScript stories, and the necessary addons are included for testing and documentation purposes.

components/log-viewer-webui/client/.storybook/vitest.setup.ts (1)

1-11: Correct setup for Storybook/Vitest integration

The integration between Storybook and Vitest is properly configured. The code correctly applies the project annotations and hooks into Vitest's lifecycle, following best practices for testing Storybook stories.

components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput.tsx (1)

10-18: Clean wrapper for TimeRangeInputBase component

The component implementation is clean and correctly uses the extracted TimeRangeInputBase component with appropriate props. This follows good separation of concerns by delegating the UI logic to the base component while this wrapper handles the connection to the search state.

components/log-viewer-webui/client/.storybook/preview.ts (1)

1-16: Well-configured Storybook preview file

This configuration correctly sets up the parameter matchers for automatic recognition of color and date properties in Storybook controls. The file is properly typed with the Preview type from @storybook/react.

components/log-viewer-webui/client/vitest.workspace.ts (1)

8-11: Directory path handling looks good

The code correctly handles directory path determination in a way that's compatible with both CommonJS and ES modules.

components/log-viewer-webui/client/src/pages/SearchPage/SearchState.tsx (3)

6-7: Properly updated import paths

The imports are correctly updated to reference the new location of time range utilities and the new TimeRange type.


20-20: Improved type consistency

Replacing the explicit tuple type with the TimeRange type alias improves code consistency.


22-22: Consistent parameter typing

The parameter type for updateTimeRange is correctly updated to match the timeRange property type.

components/log-viewer-webui/client/src/components/TimeRangeInputBase/utils.tsx (3)

3-4: Proper type import

The TimeRange type is correctly imported from the shared typing module.


23-62: Enhanced type safety and readability

The changes to TIME_RANGE_OPTION_DAYJS_MAP bring several improvements:

  1. Using Readonly<Record<...>> with Object.freeze ensures immutability
  2. Adopting the TimeRange type improves type consistency across the codebase
  3. The consistent formatting with each date range on separate lines enhances readability

These changes align well with the PR's goal of creating a more reusable and testable component.


79-80: Updated function signature for type consistency

The isValidDateRange function signature is properly updated to use the TimeRange type, maintaining type consistency throughout the codebase.

components/log-viewer-webui/client/src/stories/TimeRangeInputBase.stories.ts (4)

18-41: Well-structured Storybook meta configuration.

The meta configuration is well organized with appropriate categorization under "Search", centered layout, autodocs tag for automatic documentation, and properly configured controls for the component props.


46-64: Excellent test case for Custom time range input.

This story effectively tests the custom time range input functionality by:

  • Setting the default value to the CUSTOM option
  • Simulating user interactions with date inputs
  • Verifying that onChange is not triggered until Enter is pressed
  • Confirming the callback is called exactly once after proper input

This provides good coverage for the custom date range entry workflow.


73-92: Good test coverage for preset selection.

This story effectively tests selecting a preset from the dropdown by:

  • Verifying all preset options are rendered in the dropdown
  • Confirming that onChange is not called until an option is selected
  • Validating that the callback is triggered exactly once after selection

The comprehensive verification of all available options ensures the component renders the complete set of time range presets.


94-108: Proper testing of Custom option selection behavior.

This story correctly verifies that selecting the "Custom" option from the dropdown:

  • Does not immediately trigger the onChange callback
  • Allows the user to proceed to enter custom dates (which would be verified in the other Custom story)

This test complements the other stories by covering another important interaction path.

components/log-viewer-webui/client/src/components/TimeRangeInputBase/index.tsx (6)

25-34: Well-defined props interface with helpful documentation.

The TimeRangeInputProps interface is clearly defined with appropriate JSDoc comments explaining the purpose of each prop and their default behaviors.


36-49: Comprehensive component documentation.

The JSDoc comments effectively describe the component's purpose, behavior, and props, which will be valuable for automatic documentation generation in Storybook and for other developers using this component.


50-60: Well-implemented state management for option selection.

The state management approach is solid:

  • Tracking the selected option with useState
  • Using a ref to maintain the last non-custom selection for proper initialization
  • Correctly handling option changes with appropriate side effects

The option selection logic properly updates the time range through the onChange callback when selecting standard presets while deferring updates for custom ranges until the user specifies dates.


62-69: Proper validation in range picker change handler.

This handler correctly:

  • Follows the coding guideline using false === isValidDateRange(newRange) rather than negation
  • Prevents invalid date ranges from being passed to the onChange callback
  • Only updates when a valid range is selected

71-73: Smart default picker value calculation.

The logic for determining the default value for the date range picker is well thought out:

  • When the last option was CUSTOM, it defaults to TODAY
  • Otherwise, it uses the corresponding date range for the last selected option

This provides a good user experience when switching between preset and custom options.


75-97: Clean, accessible UI implementation.

The component's rendering logic is well structured:

  • The Select component is always visible with appropriate styling
  • The DatePicker.RangePicker is conditionally rendered only when CUSTOM is selected
  • Both components use the "large" size for consistency and better usability
  • CSS classes are applied conditionally for styling different states

Comment on lines +11 to +13
"antd": "VITE_USE_ANTD_APP=true npm run start",
"storybook": "storybook dev -p 6006",
"storybook:build": "storybook build"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Introduce ANTD and Storybook scripts.

  • The antd script enables launching the app with the ANTD design system.
  • The storybook and storybook:build scripts facilitate component development and static builds.
    Note: On Windows, setting VITE_USE_ANTD_APP=true may require a cross-platform tool like cross-env.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changes:

  • Refactor the interface to make the component reusable & testable.
  • Add inline docs for props.
  • Fix a bug where the datetime picker does not sync with the last selected range when "Custom" option is first selected.
  • Add util safeString to streamline unsafe CSS module class names handling.

@junhaoliao
junhaoliao requested a review from hoophalab April 17, 2025 08:10
@junhaoliao junhaoliao changed the title test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it. test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it (resolves #825), Apr 17, 2025
@junhaoliao junhaoliao changed the title test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it (resolves #825), test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it (resolves #825). Apr 17, 2025
@junhaoliao junhaoliao changed the title test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it (resolves #825). test(new-webui): Add React Storybook for UI testing & docs; Extract TimeRangeInputBase and set up tests for it. Apr 17, 2025

@hoophalab hoophalab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Storybook is neat and everything is working nicely.
The Search page still looks the same after the refactor.
I have a few comments on the code style.

* @param props.defaultValue
* @return
*/
const TimeRangeInputBase = ({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should treat "components" as extensions to antd.
Instead of naming this as TimeRangeInputBase, how about

  1. name this as TimeRangeInput,
  2. remove components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/TimeRangeInput.tsx
  3. supply parameters directly in components/log-viewer-webui/client/src/pages/SearchPage/SearchControls

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Naming things as utils often turns into a dumping ground over time.

We could rename this one to something more specific such as timeRangeOption.ts, and maintain it as a generic time range library.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We've been using a separate typings directory in both log-viewer and this repo, and it might be a bit late to bring it up. I have a personal take on it:

  1. typings directory hurts modularity.
    For instance, we wouldn’t move interface SearchState to typings since it’s only used in SearchControls.
    Same logic applies here: this TimeRange is only used by the users of TimeRangeInput.

  2. We're writing TypeScript from the ground up, not just adding types to existing JavaScript code.

How about:

  1. move everything into the proposed timeRangeOption.ts file.

@davemarco davemarco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review on storybook setup. Overall setup looks reasonable

three questions not in code:

  1. Do you know if there is a way to get rid of docs strings from docs? The "@PARAM" looks weird

Screenshot 2025-04-24 at 2 38 51 PM

  1. I tried the run tests feature, and it dosen't work. It says missing dependency but I ran npm ci?
    Screenshot 2025-04-24 at 3 54 35 PM

  2. It looks like there is a way to run all the tests from the CLI with vitest. We should probably set that up in this PR. I dont think will be difficult

Looking at actual tests now, but will be a second review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should add the reference for this?
I believe here.
https://storybook.js.org/docs/configure/integration/typescript

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When does it generated logs? I couldnt get it to generate any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should add the docs reference for this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this chromatic, i dont believe it is being used

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again I would add the reference for this. https://storybook.js.org/docs/writing-tests/test-addon
Also why did you pick this instead of the simple one?

import { defineConfig, mergeConfig } from 'vitest/config';
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
 
const dirname =
  typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url));
 
import viteConfig from './vite.config';
 
export default mergeConfig(
  viteConfig,
  defineConfig({
    plugins: [
      storybookTest({
        // The location of your Storybook config, main.js|ts
        configDir: path.join(dirname, '.storybook'),
        // This should match your package.json script to run Storybook
        // The --ci flag will skip prompts and not open a browser
        storybookScript: 'yarn storybook --ci',
      }),
    ],
    test: {
      // Enable browser mode
      browser: {
        enabled: true,
        name: 'chromium',
        // Make sure to install Playwright
        provider: 'playwright',
        headless: true,
      },
      setupFiles: ['./.storybook/vitest.setup.ts'],
    },
  })
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a reference for this?

@davemarco davemarco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review for the stories themselves. Next will put one for the changes you made to my existing code

},
play: async ({canvasElement, args}) => {
const canvas = within(canvasElement);
const startDateInput = await canvas.findByPlaceholderText("Start date");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can use GetByPlaceholderText and then can remove the await. Same comment for endDateInput.

type Story = StoryObj<typeof meta>;


const Custom: Story = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably have a comment at the top of each of these stories saying what it does.

@davemarco davemarco Apr 24, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should be next to the component itself (in its directory) and not in its own folder. See their docs.
https://storybook.js.org/docs/writing-stories#where-to-put-stories

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