Files
joke-app/apps/web/src/games/one-card/help.test.ts

89 lines
4.7 KiB
TypeScript

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['one-card']!.view(s, who) as any;
const nickOf = (id: string) => users[id]!.nickname;
test('원카드: 내 차례 / 상대 차례 / 관전', () => {
const { state } = setupGame('one-card', 3);
const cur = state.current as string;
const other = ['A', 'B', 'C'].find((p) => p !== cur)!;
const mine = helpNow(view(state, cur), cur, users);
expect(mine).toContain('내 차례예요');
expect(mine).toContain('무늬나 숫자가 같은 카드');
expect(mine).toMatch(/초록 테두리|낼 수 있는 카드가 없어요/);
expect(helpNow(view(state, other), other, users)).toContain(`${nickOf(cur)}님 차례예요. 기다려 주세요`);
const spec = helpNow(view(state, null), null, users);
expect(spec).toContain(`${nickOf(cur)}님 차례예요`);
expect(spec).not.toContain('내 차례');
});
test('원카드: 공격을 받으면 받아치기/먹기 안내', () => {
const { state } = setupGame('one-card', 3);
const cur = state.current as string;
state.discard.push({ id: 'H2', kind: 'std', suit: 'H', rank: 2 });
state.pendingAttack = 2;
state.hands[cur] = [{ id: 'S9', kind: 'std', suit: 'S', rank: 9 }, { id: 'C5', kind: 'std', suit: 'C', rank: 5 }];
const t = helpNow(view(state, cur), cur, users);
expect(t).toContain('공격 2장을 받고 있어요');
expect(t).toContain('[2장 먹기]');
state.hands[cur].push({ id: 'H3', kind: 'std', suit: 'H', rank: 3 });
expect(helpNow(view(state, cur), cur, users)).toContain('같은 무늬 3');
const other = ['A', 'B', 'C'].find((p) => p !== cur)!;
expect(helpNow(view(state, other), other, users)).toContain(`${nickOf(cur)}님이 공격 2장을 받고 있어요`);
});
test('원카드: 7로 정한 무늬, 원카드 잡기', () => {
const { state } = setupGame('one-card', 3);
const cur = state.current as string;
state.declaredSuit = 'H';
state.discard.push({ id: 'S7', kind: 'std', suit: 'S', rank: 7 });
expect(helpNow(view(state, cur), cur, users)).toContain('♥ 하트로 정해졌어요');
const other = ['A', 'B', 'C'].find((p) => p !== cur)!;
state.oneCardWindow = { player: other, declared: false, openedSeq: state.seq };
state.hands[other] = [state.hands[other][0]];
expect(helpNow(view(state, other), other, users)).toContain('[원카드!] 버튼을 빨리 눌러요');
expect(helpNow(view(state, cur), cur, users)).toContain(`${nickOf(other)}님이 1장 남았는데`);
expect(helpNow(view(state, cur), cur, users)).toContain('2초가 지나면 [원카드!]를 먼저 눌러 잡을 수 있어요');
});
test('원카드: 끝에서 두 번째 카드를 낼 때는 원카드를 따로 누르라고 안내', () => {
const { state } = setupGame('one-card', 3);
const cur = state.current as string;
state.discard.push({ id: 'H8', kind: 'std', suit: 'H', rank: 8 });
state.hands[cur] = [{ id: 'H9', kind: 'std', suit: 'H', rank: 9 }, { id: 'C5', kind: 'std', suit: 'C', rank: 5 }];
const t = helpNow(view(state, cur), cur, users);
expect(t).toContain('카드를 낸 다음 동그란 [원카드!] 버튼을 따로 꼭 눌러요');
expect(t).not.toContain('내면서');
});
test('색깔 카드: 색 바꾸기+4 의심하기', () => {
const { state } = setupGame('one-card', 3, { mode: 'uno-style', unoWild4Rule: 'challenge' });
const by = state.current as string;
const target = state.seats[(state.seats.indexOf(by) + 1) % 3] as string;
state.phase = { kind: 'wild4Response', by, target, prevColor: 'R', illegal: false };
state.pendingAttack = 4;
state.current = target;
const t = helpNow(view(state, target), target, users);
expect(t).toContain('[의심하기]');
expect(t).toContain('[받아들이기]');
expect(helpNow(view(state, by), by, users)).toContain('의심할지 고르는 중');
expect(helpNow(view(state, null), null, users)).toContain('의심할지 고르는 중');
});
test('원카드: 끝나면 결과 안내', () => {
const def = GAMES['one-card']!;
let { state: s } = setupGame('one-card', 2, { handSize: 5 });
for (let i = 0; i < 2000 && !def.result(s); i++) {
const actor = def.activePlayers(s)[0]!;
// The clock here stands still, so a catch (only after the protection time) is never allowed: skip it.
const legal = def.legalActions!(s, actor).filter((a) => def.validate(s, actor, a, { now: 1_700_000_100_000 }).ok);
s = applyAction('one-card', s, actor, legal[0]);
}
expect(def.result(s)).toBeTruthy();
expect(helpNow(view(s, 'A'), 'A', usersOf(['A', 'B']))).toContain('게임이 끝났어요');
});