Story files have been created for isolated components to document their usage and enable visual regression testing. However, Storybook installation requires Node.js 20.19+ or 22.12+.
stories/DataGrid.stories.tsx- DataGrid component storiesstories/ReserveSun.stories.tsx- ReserveSun 3D component storiesstories/SystemStatus.stories.tsx- SystemStatus component storiesstories/ErrorBanner.stories.tsx- ErrorBanner component stories
Once you have upgraded Node.js to version 20.19+ or 22.12+, run:
npx storybook@latest initThis will:
- Install Storybook dependencies
- Create
.storybook/main.tsconfiguration - Create
.storybook/preview.tsconfiguration - Add Storybook scripts to package.json
If you prefer manual installation:
npm install --save-dev @storybook/react @storybook/react-vite @storybook/addon-essentials @storybook/addon-interactions @storybook/addon-links @storybook/blocks @storybook/test storybookThen create the configuration files:
import type { StorybookConfig } from '@storybook/react-vite';
const config: StorybookConfig = {
stories: ['../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
docs: {
autodocs: 'tag',
},
};
export default config;import type { Preview } from '@storybook/react';
import '../app/globals.css';
const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
backgrounds: {
default: 'void',
values: [
{
name: 'void',
value: '#050505',
},
{
name: 'obsidian',
value: '#080808',
},
],
},
},
};
export default preview;After installation, add these scripts to package.json:
{
"scripts": {
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
}
}Then run:
npm run storybook- Sign up at https://www.chromatic.com/
- Install:
npm install --save-dev chromatic - Add script:
"chromatic": "chromatic --project-token=<your-token>" - Run:
npm run chromatic
- Sign up at https://percy.io/
- Install:
npm install --save-dev @percy/storybook - Add script:
"percy:storybook": "percy storybook ./storybook-static" - Build Storybook:
npm run build-storybook - Run:
npm run percy:storybook
- Install:
npm install --save-dev @playwright/test - Create test files that load Storybook stories
- Capture screenshots for comparison
Each story includes:
- Component props documentation
- Multiple states (Normal, Critical, Mobile, etc.)
- Interactive controls for testing different values
- Viewport configurations for responsive testing
The stories cover:
- Normal state (reserve ratio > 400%)
- Critical state (reserve ratio < 400%)
- Different data ranges
- Mobile viewports (< 768px)
- Tablet viewports (768px - 1024px)
- Desktop viewports (> 1024px)
- Error states
- Warning states
- Stale data indicators
Once visual regression testing is set up, integrate it into your CI pipeline:
# Example GitHub Actions workflow
name: Visual Regression Tests
on: [push, pull_request]
jobs:
visual-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20.19'
- run: npm ci
- run: npm run build-storybook
- run: npm run chromatic # or percy:storybook