---
id: w5/m3/t008
title: Test coverage for i18n behavior
worker: worker5
status: done
estimate: 45m
depends_on: [w5/m3/t006]
---

## Objective

Add meaningful tests for the behavior this milestone shipped — asserting real
i18n behavior and failure modes, not trivial snapshots.

## Context

- Existing test setup: Vitest, tests in `__tests__/` adjacent to code
  (`dashboard/CLAUDE.md`). The reference has analogous tests
  (`src/i18n/__tests__/languages.test.ts`, `use-translations.test.ts`) to learn
  from — but assert *this* repo's behavior.
- Worth covering: server-side language detection priority (URL → cookie →
  Accept-Language → default); `persistLanguage` writes cookie + localStorage;
  `useTranslations` returns the right message and warns on unprefixed/unknown
  keys in dev; every shipped namespace has key parity between `en` and `zh` (no
  missing/extra keys); the switcher calls `changeLanguage` + `persistLanguage`.

## Steps

1. Add unit tests for the detector, `persistLanguage`, and `useTranslations`
   validation.
2. Add a locale-parity test (`en` vs `zh` keys per namespace).
3. Add a switcher interaction test (select → changeLanguage/persist called).
4. Run `yarn test` / `yarn test:coverage`.

## Files

- `dashboard/src/i18n/detect-language/__tests__/*.test.ts`
- `dashboard/src/i18n/__tests__/locale-parity.test.ts`
- `dashboard/src/common/hooks/__tests__/use-translations.test.tsx`
- `dashboard/src/features/i18n/__tests__/language-switcher.test.tsx`

## Acceptance criteria

- [ ] Tests assert real behavior + failure modes (detection fallbacks, key parity,
      dev warnings) — not tautological or snapshot-everything.
- [ ] Tests fail if a `zh` key is dropped or the detection priority regresses.
- [ ] `yarn test` passes.

## Out of scope

- E2E browser tests (unit/integration coverage only here).
</content>
