-
Notifications
You must be signed in to change notification settings - Fork 0
feat: set up MSW for Storybook API mocking across all pages #898
Description
Summary
Set up Mock Service Worker (MSW) as the standard API mocking layer for Storybook stories across the entire web dashboard. Replace the current ESM namespace mutation workaround in LoginPage.stories.tsx with proper network-level interception.
Context
The AdminCreation story in LoginPage.stories.tsx currently works around the lack of a backend by dynamically importing the setup API module and reassigning getSetupStatus on the ESM namespace. This works in Vite's dev server but is technically non-standard (ESM namespaces are spec-immutable) and won't scale as more pages need API-mocked stories.
With 5+ pages still to build (Setup Wizard, Agent Profiles, Org Chart, Task Board, Settings), each will need API mocking for meaningful Storybook coverage. Setting up MSW once gives all pages a clean, spec-compliant mocking layer.
Scope
- Install dependencies:
msw,msw-storybook-addon - Generate service worker:
npx msw init web/public/ --save - Wire into Storybook:
initialize()inweb/.storybook/preview.tsx - Create shared handlers:
web/src/__stories__/handlers/(or similar) with reusable API mocks for common endpoints (setup status, auth, company, agents, etc.) - Migrate LoginPage stories: Replace
AdminCreationGateESM mutation withparameters.msw.handlersper-story - Document the pattern: Add a section to the Storybook conventions showing how to add API-mocked stories for new pages
Acceptance Criteria
-
msw+msw-storybook-addoninstalled and configured - Service worker registered in
web/public/mockServiceWorker.js -
LoginPage.stories.tsxuses MSW handlers instead of ESM mutation - At least one reusable handler set (setup status) in shared handlers dir
-
storybook buildworks with MSW (static builds) - Pattern documented for future page stories
Effort
~1-2 hours. Most is initial MSW + Storybook integration setup. Per-page handler authoring is incremental after that.
Related
- PR feat: Login page + first-run bootstrap + Company page (#789, #888) #896 introduced the ESM mutation workaround (documented in
AdminCreationGatedocstring) - Setup Wizard page (next to be built) will be the first consumer of shared MSW handlers