2026-02-05 11:28:04 +00:00
|
|
|
/**
|
|
|
|
|
* Storybook preview: MSW intercepts all API calls when run via `npm run storybook` / `npm run build-storybook`.
|
|
|
|
|
* Those scripts set VITE_API_URL=/api/v1 (same-origin) and VITE_STORYBOOK=true (logger does not send to backend).
|
|
|
|
|
* Do not run Storybook with an absolute API URL or MSW will not intercept.
|
|
|
|
|
*/
|
2026-02-03 23:44:40 +00:00
|
|
|
import type { Preview } from '@storybook/react';
|
2026-02-04 00:01:45 +00:00
|
|
|
import { initialize, mswLoader } from 'msw-storybook-addon';
|
|
|
|
|
import { handlers } from '../src/mocks/handlers';
|
2026-02-03 08:56:11 +00:00
|
|
|
import '../src/index.css';
|
2026-02-03 23:44:40 +00:00
|
|
|
import '../src/lib/i18n'; // Initialize i18n
|
2026-02-03 08:56:11 +00:00
|
|
|
import React from 'react';
|
2026-02-05 12:01:49 +00:00
|
|
|
import { StorybookDecorator } from './decorators';
|
2026-02-03 08:56:11 +00:00
|
|
|
|
|
|
|
|
// Custom viewports for responsive testing
|
|
|
|
|
const customViewports = {
|
|
|
|
|
mobile: {
|
|
|
|
|
name: 'Mobile',
|
|
|
|
|
styles: {
|
|
|
|
|
width: '375px',
|
|
|
|
|
height: '667px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
tablet: {
|
|
|
|
|
name: 'Tablet',
|
|
|
|
|
styles: {
|
|
|
|
|
width: '768px',
|
|
|
|
|
height: '1024px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
desktop: {
|
|
|
|
|
name: 'Desktop',
|
|
|
|
|
styles: {
|
|
|
|
|
width: '1440px',
|
|
|
|
|
height: '900px',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-05 12:22:03 +00:00
|
|
|
// Initialize MSW: strict mode — any unhandled request throws in console and fails the story.
|
2026-02-04 18:33:00 +00:00
|
|
|
initialize({
|
2026-02-05 12:22:03 +00:00
|
|
|
onUnhandledRequest: 'error',
|
2026-02-04 18:33:00 +00:00
|
|
|
serviceWorker: {
|
|
|
|
|
url: './mockServiceWorker.js',
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-02-04 00:01:45 +00:00
|
|
|
|
2026-02-03 08:56:11 +00:00
|
|
|
const preview: Preview = {
|
|
|
|
|
parameters: {
|
2026-02-04 00:01:45 +00:00
|
|
|
msw: {
|
|
|
|
|
handlers: handlers,
|
|
|
|
|
},
|
2026-02-03 08:56:11 +00:00
|
|
|
controls: {
|
|
|
|
|
matchers: {
|
|
|
|
|
color: /(background|color)$/i,
|
|
|
|
|
date: /Date$/i,
|
|
|
|
|
},
|
|
|
|
|
expanded: true,
|
|
|
|
|
},
|
|
|
|
|
a11y: {
|
|
|
|
|
test: 'todo',
|
|
|
|
|
},
|
|
|
|
|
viewport: {
|
|
|
|
|
viewports: customViewports,
|
|
|
|
|
},
|
|
|
|
|
backgrounds: {
|
|
|
|
|
default: 'dark',
|
|
|
|
|
values: [
|
2026-02-12 01:15:11 +00:00
|
|
|
{ name: 'dark', value: '#121215' },
|
|
|
|
|
{ name: 'light', value: '#faf9f6' },
|
|
|
|
|
{ name: 'raised', value: '#1a1a1f' },
|
2026-02-03 08:56:11 +00:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
layout: 'centered',
|
|
|
|
|
docs: {
|
|
|
|
|
toc: true, // Enable table of contents in docs
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-02-05 12:01:49 +00:00
|
|
|
decorators: [StorybookDecorator],
|
2026-02-03 08:56:11 +00:00
|
|
|
tags: ['autodocs'],
|
2026-02-04 00:01:45 +00:00
|
|
|
loaders: [mswLoader],
|
2026-02-03 08:56:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default preview;
|