/** Beginner help (docs/07 §5) for every game: 3 summary cards, and help text on every view of a random game. */ import { describe, expect, test } from 'bun:test'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { GAMES } from '@bg/games'; import { GAME_UI } from './registry'; import { assertCleanText, eachView, seatIds, usersOf } from './help-kit.test-util'; const IDS = Object.keys(GAME_UI); test('모든 게임에 도움말이 있어요', () => { expect(IDS).toHaveLength(35); for (const id of IDS) { const src = readFileSync(join(import.meta.dir, id, 'index.tsx'), 'utf8'); expect(src, id).toMatch(/\bquickStart,/); expect(src, id).toMatch(/\bhelpNow,/); } }); describe.each(IDS)('%s', (id) => { test('30초 요약 카드 3장', async () => { const { quickStart } = await import(`./${id}/quick`); expect(quickStart).toHaveLength(3); for (const c of quickStart) { expect(c.pic).toBeTruthy(); expect(c.alt.length).toBeGreaterThan(4); expect(c.title.length).toBeGreaterThan(1); expect(c.title.length).toBeLessThanOrEqual(20); expect(c.text.length).toBeGreaterThan(10); expect(c.text.length).toBeLessThanOrEqual(110); } }); test('무작위 한 판의 모든 화면(각 자리 + 관전)에서 지금 할 수 있는 것', async () => { const { helpNow } = await import(`./${id}/help`); const def = GAMES[id]!; const range = def.playersFor?.(def.defaultOptions) ?? { min: def.minPlayers, max: def.maxPlayers }; // 3 players where allowed; otherwise the nearest count the game accepts (e.g. 쿼리도: 2 or 4). const want = Math.min(range.max, Math.max(range.min, 3)); const counts = Array.from({ length: range.max - range.min + 1 }, (_, i) => range.min + i).sort((a, b) => Math.abs(a - want) - Math.abs(b - want) || a - b); const n = counts.find((c) => !def.playerCountError?.(def.defaultOptions, c)) ?? want; const users = usersOf(seatIds(n)); let count = 0; eachView(id, n, (view, who) => { assertCleanText(helpNow(view, who, users), `${id} viewer=${who}`); count++; }); expect(count).toBeGreaterThan(n); }); });