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.seotda!.view(s, who) as any; const nickOf = (id: string) => users[id]!.nickname; test('섯다: 내 차례(버튼·족보) / 상대 차례 / 관전', () => { const { state } = setupGame('seotda', 3); const turn = view(state, null).toAct as string; const other = ['A', 'B', 'C'].find((id) => id !== turn)!; const mine = helpNow(view(state, turn), turn, users); expect(mine).toContain('내 차례예요'); expect(mine).toContain('첫 베팅'); expect(mine).toContain('[다이]'); expect(mine).toContain('[체크]'); expect(mine).toContain('[삥]'); expect(mine).not.toContain('[콜]'); expect(mine).toContain('월 한 장만 받았어요'); const waiting = helpNow(view(state, other), other, users); expect(waiting).toContain(`${nickOf(turn)}님 차례예요(첫 베팅)`); expect(waiting).toContain('기다려 주세요'); const spec = helpNow(view(state, null), null, users); expect(spec).toContain(`${nickOf(turn)}님 차례예요`); expect(spec).toContain('모인 칩'); expect(spec).not.toContain('내 족보'); expect(spec).not.toContain('월 한 장'); // After a 삥 the next player sees [콜] with the amount to match. const s2 = applyAction('seotda', state, turn, { type: 'ping' }); const next = view(s2, null).toAct as string; const t = helpNow(view(s2, next), next, users); expect(t).toContain('[콜]'); expect(t).toContain('[따당]'); expect(t).toContain('[콜]은 그만큼(10 칩) 맞추는'); }); test('섯다: 2장째를 받으면 지금 내 족보와 마지막 베팅, 족보 숨기기 옵션', () => { let { state } = setupGame('seotda', 2); for (let i = 0; i < 2; i++) state = applyAction('seotda', state, view(state, null).toAct, { type: 'check' }); const v = view(state, null); expect(v.street).toBe(1); const t = helpNow(view(state, v.toAct), v.toAct, users); expect(t).toContain('마지막 베팅'); expect(t).toMatch(/지금 내 족보: .+\(|예요\./); const off = setupGame('seotda', 2, { hints: false }).state; const p = view(off, null).toAct as string; expect(helpNow(view(off, p), p, users)).toContain("'족보표'를 보고"); }); test('섯다: 3장 섯다 고르기 단계', () => { let { state } = setupGame('seotda', 3, { cardMode: 'three' }); while (view(state, null).handPhase === 'betting') state = applyAction('seotda', state, view(state, null).toAct, { type: 'check' }); expect(view(state, null).handPhase).toBe('choose'); const t = helpNow(view(state, 'A'), 'A', users); expect(t).toContain('2장을 눌러 고르면'); expect(t).toContain('정하기'); expect(t).toContain('[추천 조합]'); expect(helpNow(view(state, null), null, users)).toContain('몰래 고르는 중'); const v = view(state, 'A'); const s2 = applyAction('seotda', state, 'A', { type: 'choose', cardIds: v.myCombos[0].cardIds }); expect(helpNow(view(s2, 'A'), 'A', users)).toContain('골랐어요'); }); test('섯다: 모두 다이 → 판 결과와 [다음 판으로], 다이한 사람', () => { let { state } = setupGame('seotda', 3); const first = view(state, null).toAct as string; state = applyAction('seotda', state, first, { type: 'die' }); expect(helpNow(view(state, first), first, users)).toContain('이번 판은 다이했어요'); state = applyAction('seotda', state, view(state, null).toAct, { type: 'die' }); expect(view(state, null).handPhase).toBe('handEnd'); const t = helpNow(view(state, 'A'), 'A', users); expect(t).toContain('모두 다이해서'); expect(t).toContain('[다음 판으로]'); }); test('섯다: 칩 다시 받기 / 구사 재경기 참가 / 재경기 표시', () => { const { state } = setupGame('seotda', 3); const rebuy = structuredClone(state); rebuy.phase = 'rebuy'; rebuy.hand = null; rebuy.rebuyPending = ['B']; rebuy.seats.find((s: any) => s.id === 'B').status = 'busted'; rebuy.seats.find((s: any) => s.id === 'B').stack = 0; const b = helpNow(view(rebuy, 'B'), 'B', users); expect(b).toContain('[칩 다시 받기]'); expect(b).toContain('[그만하기]'); expect(helpNow(view(rebuy, 'A'), 'A', users)).toContain('고양이님이 칩을 다시 받을지'); const rejoin = structuredClone(state); rejoin.hand.phase = 'rejoin'; rejoin.hand.rejoinPending = ['C']; rejoin.hand.rejoinCost = 50; expect(helpNow(view(rejoin, 'C'), 'C', users)).toContain('[50 칩 내고 참가]'); expect(helpNow(view(rejoin, 'A'), 'A', users)).toContain('다시 들어올지'); const re = structuredClone(state); re.hand.rematchNo = 1; re.hand.rematchReason = 'gusa'; expect(helpNow(view(re, null), null, users)).toContain('재경기 1회차(구사)'); }); test('섯다: 게임 끝', () => { const { state } = setupGame('seotda', 2); const end = structuredClone(state); end.phase = 'finished'; end.hand = null; end.final = { ranking: [['A'], ['B']], scores: { A: 10, B: -10 }, summary: '20판 끝. 1위 +10칩' }; expect(helpNow(view(end, 'A'), 'A', users)).toContain('게임이 끝났어요. 20판 끝'); });