cm_whatsapp_bot_v1/apps/web/vitest.config.ts
yiekheng 4f6d9c3f38 test(web): unit tests for accounts-list layout and behaviour
Refactor the /accounts page into a thin data-fetching shell plus a
pure presentational AccountsListView. The view has no DB or server-
action dependencies (the deleteFormAction is passed in), which makes
it directly unit-testable.

Tests use react-dom/server's renderToStaticMarkup — no jsdom or DOM
testing-library needed. next/link and the radix Dialog are mocked to
plain wrappers so the markup is deterministic.

Coverage:
- one cell per account, each with one main account-card and one
  delete-card
- main card links to /accounts/[id]
- account label appears in main card, delete card description, and
  the destructive confirm dialog
- delete card is a <button> with the right aria-label
- delete dialog form has a hidden accountId input matching the row
- phone number renders when paired; "Not paired yet" when not
- header CTA renders an Add Account link
- empty state replaces the grid and still offers Add Account

vitest config: include src/**/*.test.{ts,tsx} and switch esbuild jsx
to "automatic" so test files don't need a React import.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 01:06:38 +08:00

20 lines
462 B
TypeScript

import { defineConfig } from "vitest/config";
import path from "node:path";
export default defineConfig({
test: {
environment: "node",
include: ["src/**/*.test.{ts,tsx}"],
},
esbuild: {
jsx: "automatic",
},
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
// Stub out next's "server-only" import — vitest can't load it
"server-only": path.resolve(__dirname, "src/test/server-only-stub.ts"),
},
},
});