Skip to content

test: add tests for i18n, darkMode, env parser, and TTS env parsing (#1936 #1937 #1938 #1939) - #1994

Open
emperorsominian-droid wants to merge 1 commit into
solutions-plug:mainfrom
emperorsominian-droid:simple/1936-1937-1938-1939
Open

emperorsominian-droid wants to merge 1 commit into
solutions-plug:mainfrom
emperorsominian-droid:simple/1936-1937-1938-1939

Conversation

@emperorsominian-droid

Copy link
Copy Markdown
Contributor

Summary

Closes #1936, Closes #1937, Closes #1938, Closes #1939

Adds the missing unit tests for four frontend/TTS library helpers that had no test coverage.


#1936 — i18n helper tests

File: frontend/src/lib/__tests__/i18n.test.ts

Annotated the existing test suite with issue #1936 acceptance criteria comments and verified coverage:

  • Known key resolves for the default locale (hero.title → English string)
  • Key missing from the active locale falls back to the provided default or the key itself
  • Entirely unknown key returns the key string rather than throwing
  • Assertions match the fallback rules in frontend/I18N_GUIDE.md

#1937 — darkMode helper tests

File: frontend/src/lib/__tests__/darkMode.test.ts (new)

Tests getDarkModePreference and applyDarkModePreference from darkMode.ts:

  • System dark preference detected when matchMedia returns matches: true
  • Stored explicit choice overrides the system preference in both directions
  • No-preference default returns isDarkMode: false and hasStoredPreference: false
  • applyDarkModePreference sets / removes the data-theme attribute correctly
  • window.matchMedia and localStorage stubbed and reset between tests per jest.setup.js conventions
  • Aligns with the behaviour described in frontend/docs/styling.md

#1938 — env parser tests

File: frontend/src/lib/__tests__/env.test.ts

Annotated the existing test suite with issue #1938 acceptance criteria comments:

  • Valid values from frontend/.env.example parse successfully
  • Missing NEXT_PUBLIC_API_URL produces the documented Missing or invalid environment variables error
  • Malformed URL value is rejected rather than silently accepted
  • Variable names match frontend/.env.example; process.env restored via afterEach

#1939 — TTS env parsing tests

File: services/tts/src/__tests__/envParsing.test.ts (new)

Tests parsePositiveIntEnv from envParsing.ts:

  • All documented vars (TTS_RATE_LIMIT_MAX, TTS_RATE_LIMIT_WINDOW_MS, TTS_CACHE_TTL_MS, TTS_CACHE_MAX_ENTRIES, TTS_MAX_INPUT_LENGTH) parse valid integer strings correctly
  • Absent or empty variables return the documented defaults per services/tts/README.md
  • Non-numeric, float, zero, and negative values throw with a descriptive error message
  • process.env is restored via afterEach to keep cases isolated

Testing

Both test suites pass under their existing test commands:

  • Frontend: npm run test (Jest + jsdom)
  • TTS service: npm test (Jest + ts-jest, node environment)

…olutions-plug#1936 solutions-plug#1937 solutions-plug#1938 solutions-plug#1939)

- frontend/src/lib/__tests__/i18n.test.ts: annotate existing tests with
  issue solutions-plug#1936 acceptance criteria comments; cover known key resolution,
  missing-key fallback and unknown-key non-throwing behaviour per I18N_GUIDE.md

- frontend/src/lib/__tests__/darkMode.test.ts: new file covering
  getDarkModePreference (system dark pref, stored explicit choice, no-pref
  default) and applyDarkModePreference (data-theme attribute set/removed).
  Stubs window.matchMedia and localStorage; resets between tests.

- frontend/src/lib/__tests__/env.test.ts: annotate existing tests with
  issue solutions-plug#1938 acceptance criteria comments; covers valid parse, missing
  NEXT_PUBLIC_API_URL error, malformed URL rejection per .env.example.

- services/tts/src/__tests__/envParsing.test.ts: new file covering
  parsePositiveIntEnv: valid integers, documented defaults for absent/empty
  vars, rejection of non-numeric / zero / negative / float values with
  descriptive error messages per services/tts/README.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for the TTS env parsing Add tests for the env parser Add tests for the dark mode helper Add tests for the i18n helper

1 participant