Skip to content

feat: set up MSW for Storybook API mocking across all pages #898

@Aureliolo

Description

@Aureliolo

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

  1. Install dependencies: msw, msw-storybook-addon
  2. Generate service worker: npx msw init web/public/ --save
  3. Wire into Storybook: initialize() in web/.storybook/preview.tsx
  4. Create shared handlers: web/src/__stories__/handlers/ (or similar) with reusable API mocks for common endpoints (setup status, auth, company, agents, etc.)
  5. Migrate LoginPage stories: Replace AdminCreationGate ESM mutation with parameters.msw.handlers per-story
  6. 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-addon installed and configured
  • Service worker registered in web/public/mockServiceWorker.js
  • LoginPage.stories.tsx uses MSW handlers instead of ESM mutation
  • At least one reusable handler set (setup status) in shared handlers dir
  • storybook build works 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope:smallLess than 1 day of worktype:featureNew feature implementationv0.5Minor version v0.5v0.5.1Patch release v0.5.1

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions