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.uno!.view(s, who) as any; const nickOf = (id: string) => users[id]!.nickname; const R = (v: number, c = 'a') => ({ id: `R${v}${c}`, kind: 'num', color: 'R', value: v }); /** A plain turn for the first seat with a red 5 on the table. */ function plain() { const { state } = setupGame('uno', 3); state.discard = [R(5)]; state.color = 'R'; state.phase = { kind: 'turn' }; state.current = 'A'; state.pending = 0; state.unoWindow = null; return state; } test('우노: 내 차례 / 상대 차례 / 관전', () => { const state = plain(); const mine = helpNow(view(state, 'A'), 'A', users); expect(mine).toContain('내 차례예요'); expect(mine).toContain('지금 색(빨강)'); expect(mine).toMatch(/초록 테두리|낼 수 있는 카드가 없어요/); expect(helpNow(view(state, 'B'), 'B', users)).toContain(`${nickOf('A')}님 차례예요. 기다려 주세요`); const spec = helpNow(view(state, null), null, users); expect(spec).toContain(`${nickOf('A')}님 차례예요`); expect(spec).not.toContain('내 차례'); }); test('우노: 2장일 때 우노 안내, 안 외친 사람 잡기', () => { const state = plain(); state.hands.A = [R(1), R(2)]; expect(helpNow(view(state, 'A'), 'A', users)).toContain('[우노!]를 눌러 두면'); state.hands.B = [R(3)]; state.unoWindow = { player: 'B', declared: false }; expect(helpNow(view(state, 'B'), 'B', users)).toContain('[우노!] 버튼을 빨리 눌러요'); expect(helpNow(view(state, 'C'), 'C', users)).toContain(`${nickOf('B')}님이 1장 남았는데`); }); test('우노: 와일드 드로우4 도전, 쌓인 카드, 시작 색', () => { const state = plain(); state.phase = { kind: 'wild4', by: 'A', target: 'B', prevColor: 'R', illegal: false }; state.pending = 4; state.current = 'B'; const t = helpNow(view(state, 'B'), 'B', users); expect(t).toContain('[도전하기]'); expect(t).toContain('6장을 먹어요'); expect(helpNow(view(state, 'A'), 'A', users)).toContain('도전할지 고르는 중'); expect(helpNow(view(state, null), null, users)).toContain('도전할지 고르는 중'); const st = setupGame('uno', 3, { stacking: true }).state; st.discard = [{ id: 'RDa', kind: 'draw2', color: 'R' }]; st.color = 'R'; st.phase = { kind: 'turn' }; st.current = 'A'; st.pending = 2; st.hands.A = [R(1)]; expect(helpNow(view(st, 'A'), 'A', users)).toContain('[2장 뽑기]'); const sc = plain(); sc.phase = { kind: 'startColor' }; sc.color = null; expect(helpNow(view(sc, 'A'), 'A', users)).toContain('처음 낼 색'); expect(helpNow(view(sc, 'B'), 'B', users)).toContain('시작 색을 고르는 중'); }); test('우노: 끝나면 결과 안내', () => { const def = GAMES.uno!; let { state: s } = setupGame('uno', 2); for (let i = 0; i < 3000 && !def.result(s); i++) { const actor = def.activePlayers(s)[0]!; s = applyAction('uno', s, actor, def.legalActions!(s, actor)[0]); } expect(def.result(s)).toBeTruthy(); expect(helpNow(view(s, 'A'), 'A', usersOf(['A', 'B']))).toContain('게임이 끝났어요'); });