Skip to content

Expand frontend unit test coverage #140

Description

@karutoil

Summary

The frontend currently has only 1 unit test file (src/__tests__/rbac-permissions.test.tsx) covering permission helpers. The rest of the frontend — hooks, stores, API services, and utility functions — has zero unit test coverage.

Current State

  • Vitest configured with jsdom environment and @testing-library/jest-dom
  • 1 test file: rbac-permissions.test.tsx (~460 lines)
  • Frontend tests are NOT run in CI (jsdom not installed in CI environment)
  • Playwright E2E covers UI behavior (functional.spec.ts, 1340 lines) but is slow and not granular
  • ~32 custom hooks, 3 Zustand stores, 23 API service files — all untested

Priority Test Targets

  1. Zustand stores (authStore, themeStore, backupDownloadStore) — state transitions, persistence, side effects
  2. Custom hooks (useServer, useServers, useNodes, useFileManager, useSseConsole) — query key usage, refetch intervals, error handling
  3. API client (services/api/client.ts) — 401 interceptor, CSRF handling, error reporting
  4. Utility functions — query key factory (queryKeys.ts), validators
  5. Plugin system (plugins/PluginProvider.tsx, plugins/loader.ts) — manifest loading, dynamic imports

Acceptance Criteria

  • Unit tests for all 3 Zustand stores
  • Unit tests for at least 10 priority hooks
  • Unit tests for API client (interceptors, CSRF, error paths)
  • Frontend Vitest added to CI pipeline (jsdom dependency added)
  • Test infrastructure: shared test utilities (mock API client, mock stores, test wrappers)
  • Coverage threshold set (e.g., 50% for hooks/stores as initial target)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions