Files
SpaceWanderer/e2e/smoke.spec.ts

59 lines
2.9 KiB
TypeScript

import { expect, test } from '@playwright/test';
// Mirrors the /api/world response shape (lib/game/save.ts) — kept local so the spec stays self-contained.
interface WorldSystemDto { id: number; name: string; x: number; y: number; discovered: boolean; current: boolean }
interface WorldState { systems: WorldSystemDto[]; edges: [number, number][]; turn: number }
test('landing page loads with the SpaceWanderer title', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: 'SpaceWanderer' })).toBeVisible();
});
test('game template tabs render (scificn-ui component layer wired in)', async ({ page }) => {
await page.goto('/');
// Stat card + footer badge prove the layout shell; Radix Tabs.Trigger renders role="tab".
await expect(page.getByText('NEXT ENCOUNTER')).toBeVisible();
await expect(page.getByRole('tab', { name: 'WORLD MAP' })).toBeVisible();
await expect(page.getByRole('tab', { name: 'CREW' })).toBeVisible();
await expect(page.getByRole('tab', { name: 'SKILL TREE' })).toBeVisible();
await expect(page.getByText('SYS ONLINE')).toBeVisible();
});
test('tabs switch panels client-side (event log terminal)', async ({ page }) => {
await page.goto('/');
await page.getByRole('tab', { name: 'EVENT LOG' }).click();
await expect(page.getByText('SHIP LOG // PLACEHOLDER FEED')).toBeVisible();
});
test('world map shows the generated starting system and its neighbours', async ({ page }) => {
await page.goto('/');
// Live chart title carries the turn counter; a fresh save sits at the start with six jump routes.
await expect(page.getByText(/GALACTIC CHART \/\/ JUMP ROUTES — TURN \d+/)).toBeVisible();
const jumpButtons = page.getByRole('button', { name: /\/\/ JUMP$/ });
await expect(jumpButtons.first()).toBeVisible();
await expect(jumpButtons).toHaveCount(6);
});
test('jumping to an adjacent system updates the world state and turn counter', async ({ page }) => {
const before = (await (await page.request.get('/api/world')).json()) as WorldState;
const currentId = before.systems.find((s) => s.current)!.id;
const edge = before.edges.find(([a, b]) => a === currentId || b === currentId)!;
const targetId = edge[0] === currentId ? edge[1] : edge[0];
const targetName = before.systems.find((s) => s.id === targetId)!.name;
await page.goto('/');
await page.getByRole('button', { name: `${targetName.toUpperCase()} // JUMP` }).click();
const after = (await (await page.request.get('/api/world')).json()) as WorldState;
expect(after.turn).toBe(before.turn + 1);
expect(after.systems.find((s) => s.current)?.id).toBe(targetId);
});
test('GET /api/version reports the app version as JSON', async ({ page }) => {
const res = await page.request.get('/api/version');
expect(res.status()).toBe(200);
expect(res.headers()['content-type']).toContain('application/json');
const body = (await res.json()) as { version: string };
expect(body.version).toMatch(/^\d+\.\d+\.\d+$/);
});