Skip to content

Frontend tests #17

Merged
LuckyIntegral merged 9 commits intodevelopfrom
tests-frontend
Mar 11, 2026
Merged

Frontend tests #17
LuckyIntegral merged 9 commits intodevelopfrom
tests-frontend

Conversation

@timofeykafanov
Copy link
Copy Markdown
Collaborator

Frontend Tests

Added comprehensive test coverage for the client using Vitest, React Testing Library, and jsdom.

What's covered

  • Components: GameModeSelector, LoadingOverlay, LoginForm, RegisterForm, ProtectedRoute, PublicOnlyRoute
  • Services: authService (token management, register, login, logout, getProfile), gamesService (pagination, stats computation)
  • Redux: authSlice (sync reducers, async thunks for register/login/logout/fetchProfile), store configuration
  • Hooks: useGameSocket (socket lifecycle, room management, game state), useKeyboardControls
  • Routes: meta functions for game, home, login, register; full game route integration (board rendering, opponent cards, win/lose detection, restart flow, keyboard controls, host display)
  • Utilities: pieceHelpers (shape/color building per mode), constants validation, tetromino definitions
  • Pages: Welcome page (user stats, logout, empty/populated states)

Tooling changes

  • Added vitest.config.ts with jsdom environment and path aliases
  • Added test setup file with localStorage mock and @testing-library/jest-dom matchers
  • Relaxed strict type-checking ESLint rules for test files (e.g. no-explicit-any, no-unsafe-*) since test mocks commonly need loose typing

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Vitest + React Testing Library test setup for the client and introduces a game-page refactor that extracts socket/keyboard logic into reusable hooks and components, enabling broader frontend test coverage.

Changes:

  • Added Vitest configuration + jsdom test environment and a shared test setup (jest-dom matchers, localStorage mock).
  • Added comprehensive client tests covering routes, auth/services, redux store/slice, utilities, and game route integration.
  • Refactored the game route to delegate UI/logic into GamePage, useGameSocket, useKeyboardControls, and supporting UI components/utilities.

Reviewed changes

Copilot reviewed 32 out of 36 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/tests/gameEngine.test.ts Removes an eslint-disable comment now covered by global test lint overrides.
pnpm-lock.yaml Adds Vitest/RTL/jsdom dependencies and lock entries.
eslint.config.mts Ignores coverage output and relaxes several strict TS-eslint rules for tests.
client/vitest.config.ts Introduces Vitest config (jsdom env, setup file, coverage settings).
client/tests/* Adds extensive client test suite; removes old placeholder Mocha test.
client/package.json Switches client test/coverage scripts to Vitest; adds Vitest/RTL/jsdom dev deps.
client/app/utils/pieceHelpers.ts Extracts piece shape/color mapping logic for reuse and testability.
client/app/routes/game.tsx Replaces large in-route implementation with GamePage composition.
client/app/hooks/useKeyboardControls.ts Extracts keyboard intent handling into a hook.
client/app/hooks/useGameSocket.ts Extracts socket lifecycle, room actions, and derived game state into a hook.
client/app/components/game/* Adds modular game UI components (board, previews, opponent card, room controls).
.gitignore Updates coverage ignore pattern.
client/app/welcome/logo-*.svg Removes unused SVG assets.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread client/package.json
Comment thread client/app/hooks/useGameSocket.ts Outdated
@LuckyIntegral
Copy link
Copy Markdown
Owner

The tests do not run for me

@LuckyIntegral
Copy link
Copy Markdown
Owner

  1. Unit tests must cover at least 50% of branches, OpponentCard.tsx has 39.28 only
  2. Console is full of react warnings, please suppress them or fix
  3. Weird errors pop up on pnpm coverage: failed to fetch profile after create Error: Fetch failed, they should not pop up

@timofeykafanov timofeykafanov removed the request for review from LuckyIntegral March 11, 2026 21:23
@LuckyIntegral LuckyIntegral merged commit 0008fc7 into develop Mar 11, 2026
3 checks passed
@LuckyIntegral LuckyIntegral deleted the tests-frontend branch March 11, 2026 22:20
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.

3 participants