import { expect, test } from 'bun:test'; import { applyAction, setupGame, usersOf } from '../help-kit.test-util'; import { GAMES } from '@bg/games'; import { helpNow } from './help'; const users = usersOf(['A', 'B', 'C']); const view = (s: unknown, who: string | null) => GAMES.rummikub!.view(s, who) as any; const nickOf = (id: string) => `${users[id]!.nickname}님`; /** Fresh game; the current player gets a known rack (view-only edit, enough for help text). */ function game(options: Record = {}, rack?: string[]) { const { state, players } = setupGame('rummikub', 3, options); const cur: string = state.current; const other = players.find((p) => p !== cur)!; if (rack) state.racks[cur] = rack; return { state, cur, other }; } test('루미큐브: 내 차례(첫 등록 전) / 상대 차례 / 관전', () => { const { state, cur, other } = game(); const mine = helpNow(view(state, cur), cur, users); expect(mine).toContain('내 차례예요'); expect(mine).toContain('30점 이상'); expect(mine).toContain('(지금 0점)'); expect(mine).toContain('[한 장 가져오기]'); expect(mine).toContain('[도와줘]'); const theirs = helpNow(view(state, other), other, users); expect(theirs).toContain(`${nickOf(cur)} 차례예요. 기다려 주세요.`); expect(theirs).toContain('나는 아직 첫 등록 전'); expect(theirs).toContain('내 받침대 14장'); const spec = helpNow(view(state, null), null, users); expect(spec).toContain(`${nickOf(cur)} 차례예요(받침대 14장)`); expect(spec).toContain('첫 등록 전'); expect(spec).not.toContain('내 받침대'); }); test('루미큐브: 방 옵션 반영(첫 등록 없음, 힌트 끔)', () => { const { state, cur } = game({ initialMeldPoints: 0, hints: false }); const t = helpNow(view(state, cur), cur, users); expect(t).not.toContain('첫 등록'); expect(t).not.toContain('[도와줘]'); expect(t).toContain('바닥 묶음을 쪼개고 합쳐'); }); test('루미큐브: 틀린 배치 / 올바른 배치 / 조커', () => { const rack = ['R10a', 'R11a', 'R12a', 'K1a', 'JK1']; const { state, cur } = game({}, rack); const bad = applyAction('rummikub', state, cur, { type: 'setDraft', sets: [{ tileIds: ['K1a'] }] }); const tb = helpNow(view(bad, cur), cur, users); expect(tb).toContain('아직 확정할 수 없어요'); expect(tb).toContain('[되돌리기]'); expect(tb).toContain('3장을 가져와요'); expect(tb).toContain('조커'); const good = applyAction('rummikub', state, cur, { type: 'setDraft', sets: [{ tileIds: ['R10a', 'R11a', 'R12a'] }] }); const tg = helpNow(view(good, cur), cur, users); expect(tg).toContain('(지금 33점)'); expect(tg).toContain('[확정]을 눌러야'); const p3 = game({ invalidCommitPenalty: 'penalty3', invalidTimeoutPenalty: 1 }, rack); const bad3 = applyAction('rummikub', p3.state, p3.cur, { type: 'setDraft', sets: [{ tileIds: ['K1a'] }] }); const t3 = helpNow(view(bad3, p3.cur), p3.cur, users); expect(t3).toContain('틀린 채로 [확정]하면'); expect(t3).toContain('1장을 가져와요'); }); test('루미큐브: 판 끝(다음 판 시작) / 게임 끝', () => { const rack = ['R10a', 'R11a', 'R12a']; const m = game({ gamesPerMatch: '2' }, rack); let s = applyAction('rummikub', m.state, m.cur, { type: 'setDraft', sets: [{ tileIds: rack }] }); s = applyAction('rummikub', s, m.cur, { type: 'commit' }); expect(s.phase).toBe('roundEnd'); const t = helpNow(view(s, m.other), m.other, users); expect(t).toContain(`${nickOf(m.cur)}이 타일을 모두 내려놓아`); expect(t).toContain('[다음 판 시작]'); expect(t).toContain('이번 판 내 점수는 -'); const s2 = applyAction('rummikub', s, m.other, { type: 'ready' }); expect(helpNow(view(s2, m.other), m.other, users)).toContain('나는 준비했어요'); expect(helpNow(view(s2, null), null, users)).toContain('기다리는 중'); const one = game({}, rack); let f = applyAction('rummikub', one.state, one.cur, { type: 'setDraft', sets: [{ tileIds: rack }] }); f = applyAction('rummikub', f, one.cur, { type: 'commit' }); expect(f.phase).toBe('finished'); expect(helpNow(view(f, one.other), one.other, users)).toContain('게임이 끝났어요'); });