Files
restitution/tests/App.test.js
kaykayyali 3fc29f728e feat: Colyseus authoritative server + invite-code lobby
- Replace socket.io relay with Colyseus 0.15 authoritative server
- GameRoom with GameState schema (players, units, resources)
- Pure TS services: CombatResolver, EconomyService, PathfindingService, UnitManager
- POST /api/create-room → 4-char invite code
- React/MUI LobbyScreen: Create (shows code + START GAME) / Join by code
- ColyseusClient: joinOrCreate/join by room type = invite code
- Nginx: static assets direct, all else proxied to Colyseus (WS upgrade)
- Content-hashed JS bundles for Cloudflare cache-busting
- 1-player lobbies: START GAME button bypasses 2-player wait
2026-05-30 02:49:20 +00:00

64 lines
1.8 KiB
JavaScript

/**
* App tests — RED phase
*
* Tests the lobby→game flow:
* 1. App renders LobbyScreen when no game started
* 2. App renders PhaserGame after onGameStart fires
* 3. ColyseusClient is passed through to LobbyScreen
*/
import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom";
// Set up Phaser global before importing App (PhaserGame uses it as a global)
window.Phaser = { Game: jest.fn() };
// Mock the LobbyScreen to avoid needing ColyseusClient in test
jest.mock("Components/LobbyScreen.jsx", () => ({
__esModule: true,
default: ({ onGameStart }) => (
<div data-testid="lobby">
<button onClick={() => onGameStart("ABCD")}>Mock Start</button>
</div>
),
}));
// Mock Phaser.Game to avoid canvas errors
jest.mock("phaser", () => ({
Game: jest.fn(),
}));
// Mock gameWindow to prevent pulling in Phaser Scene deps
jest.mock("Components/gameWindow.jsx", () => ({
__esModule: true,
default: ({ code }) => <div>Game started with code: {code}</div>,
}));
import App from "Components/app.jsx";
describe("App", () => {
it("renders LobbyScreen when no game has started", () => {
render(<App />);
// LobbyScreen should be visible
expect(screen.getByTestId("lobby")).toBeInTheDocument();
});
it("transitions to Phaser game when onGameStart fires", () => {
render(<App />);
// Lobby visible initially
expect(screen.getByTestId("lobby")).toBeInTheDocument();
// Click mock start to trigger onGameStart("ABCD")
fireEvent.click(screen.getByText("Mock Start"));
// Lobby should no longer be rendered
expect(screen.queryByTestId("lobby")).not.toBeInTheDocument();
// Phaser mount point should be visible
expect(screen.getByText(/Game started with code: ABCD/)).toBeInTheDocument();
});
});