라이어 게임 입력 중: 설명 차례인 사람이 토론 채팅을 쳐도 "입력 중"이 보이게
- BotActivity hide → hideBots: 컴퓨터 활동에만 적용(사람의 입력 중은 언제나 채팅 칸에서 오므로 숨기지 않음) - BotActivity.test.tsx: 설명 차례인 사람의 채팅 입력은 보이고, 설명 차례인 컴퓨터의 입력은 숨겨지고, 상태 줄에는 생각 중만 - e2e: 설명 첫 차례에 말하는 사람이 토론 채팅을 치면 다른 사람 채팅 칸에 입력 중, 보낸 말은 설명으로 치지 않음 - apps/web tsconfig: *.test.tsx도 타입 검사에서 제외(.test.ts와 같게) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
43
apps/web/src/components/BotActivity.test.tsx
Normal file
43
apps/web/src/components/BotActivity.test.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
/** "입력 중…" in 라이어 게임's chat box: `hideBots` leaves out a computer typing its description, never a person typing in the chat. */
|
||||
import { afterEach, expect, mock, test } from 'bun:test';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import type { RoomView } from '@bg/shared/lite';
|
||||
|
||||
// The real socket module needs a browser (document, WebSocket); BotActivity only reads `me` and `typing` from it.
|
||||
// A plain selector over a test-owned state (a zustand store renders its initial state on the server).
|
||||
type St = { me: { id: string } | null; typing: Record<string, { ch: 'room' | 'game'; until: number }> };
|
||||
let st: St = { me: null, typing: {} };
|
||||
mock.module('../net/socket', () => ({ useRoom: <T,>(sel: (s: St) => T) => sel(st) }));
|
||||
const { BotActivity } = await import('./BotActivity');
|
||||
|
||||
const room = (botActivity: RoomView['botActivity']) =>
|
||||
({
|
||||
seats: [
|
||||
{ user: { id: 'speaker', nickname: '말하는사람' } },
|
||||
{ user: { id: 'bot:1', nickname: '컴퓨터 1' } },
|
||||
],
|
||||
spectators: [],
|
||||
botActivity,
|
||||
}) as unknown as RoomView;
|
||||
const typingAs = (id: string) => (st = { me: { id: 'me' }, typing: { [id]: { ch: 'game', until: Date.now() + 5000 } } });
|
||||
|
||||
afterEach(() => (st = { me: null, typing: {} }));
|
||||
|
||||
test('설명 차례인 사람이 토론 채팅을 치면 hideBots에 있어도 "입력 중"이 보여요', () => {
|
||||
typingAs('speaker');
|
||||
const html = renderToStaticMarkup(<BotActivity room={room(undefined)} only="typing" ch="game" hideBots={['speaker']} />);
|
||||
expect(html).toContain('말하는사람 입력 중');
|
||||
});
|
||||
|
||||
test('설명 차례인 컴퓨터가 설명을 치는 중이면 채팅 칸에 "입력 중"을 띄우지 않아요', () => {
|
||||
const r = room({ 'bot:1': 'typing' });
|
||||
expect(renderToStaticMarkup(<BotActivity room={r} only="typing" ch="game" />)).toContain('컴퓨터 1 입력 중');
|
||||
expect(renderToStaticMarkup(<BotActivity room={r} only="typing" ch="game" hideBots={['bot:1']} />)).toBe('');
|
||||
});
|
||||
|
||||
test('상태 줄(only="thinking")에는 컴퓨터 "생각 중"만, 입력 중은 없어요', () => {
|
||||
typingAs('speaker');
|
||||
const html = renderToStaticMarkup(<BotActivity room={room({ 'bot:1': 'thinking' })} only="thinking" ch="game" />);
|
||||
expect(html).toContain('컴퓨터 1 생각 중');
|
||||
expect(html).not.toContain('입력 중');
|
||||
});
|
||||
@@ -3,15 +3,15 @@ import { useRoom } from '../net/socket';
|
||||
|
||||
/**
|
||||
* What the computers are doing right now (docs/06 §12.1): "🤖 컴퓨터 1 생각 중…", "💬 컴퓨터 2 입력 중…", and people
|
||||
* typing ("💬 고양이 입력 중…", `ch`: the room chat or the game's own public chat). `hide`: ids left out (라이어 게임:
|
||||
* the computer typing its description is not typing in the chat).
|
||||
* typing ("💬 고양이 입력 중…", `ch`: the room chat or the game's own public chat). `hideBots`: computers left out
|
||||
* (라이어 게임: the computer typing its description is not typing in the chat; people's "입력 중" always comes from a chat box).
|
||||
* Not announced to screen readers: the chat line or the move that follows is.
|
||||
*/
|
||||
export function BotActivity({ room, only, ch, hide }: { room: RoomView; only?: 'typing' | 'thinking'; ch?: 'room' | 'game'; hide?: string[] }) {
|
||||
export function BotActivity({ room, only, ch, hideBots }: { room: RoomView; only?: 'typing' | 'thinking'; ch?: 'room' | 'game'; hideBots?: string[] }) {
|
||||
const typing = useRoom((s) => s.typing);
|
||||
const me = useRoom((s) => s.me?.id);
|
||||
const entries = Object.entries(room.botActivity ?? {}).filter(([id, a]) => (!only || a === only) && !hide?.includes(id));
|
||||
const people = ch && only !== 'thinking' ? Object.entries(typing).filter(([id, t]) => t.ch === ch && id !== me && !hide?.includes(id)) : [];
|
||||
const entries = Object.entries(room.botActivity ?? {}).filter(([id, a]) => (!only || a === only) && !hideBots?.includes(id));
|
||||
const people = ch && only !== 'thinking' ? Object.entries(typing).filter(([id, t]) => t.ch === ch && id !== me) : [];
|
||||
if (!entries.length && !people.length) return null;
|
||||
const name = (id: string, fallback: string) =>
|
||||
room.seats.find((s) => s?.user.id === id)?.user.nickname ?? room.spectators.find((u) => u.id === id)?.nickname ?? fallback;
|
||||
|
||||
@@ -458,7 +458,7 @@ function ChatBox({ v, players, me, act }: { v: LiarView; players: Record<string,
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
{room && <BotActivity room={room} only="typing" ch="game" hide={v.phase.kind === 'describe' && v.phase.speaker ? [v.phase.speaker] : undefined} />}
|
||||
{room && <BotActivity room={room} only="typing" ch="game" hideBots={v.phase.kind === 'describe' && v.phase.speaker ? [v.phase.speaker] : undefined} />}
|
||||
{canWrite ? (
|
||||
<form
|
||||
className="lg-form"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"src/**/*.test.ts"
|
||||
"src/**/*.test.ts",
|
||||
"src/**/*.test.tsx"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3035,6 +3035,15 @@ const PLANS: Record<string, Plan> = {
|
||||
if (speaker < 0) throw new Error(`nobody can describe (turn ${turn + 1})`);
|
||||
const p = pages[speaker]!;
|
||||
const input = p.getByLabel('내 설명 (한 문장)');
|
||||
if (turn === 0) {
|
||||
// The chat is open while describing: the speaker typing in it shows "입력 중" inside the others' 토론 chat.
|
||||
const chat = p.getByLabel('토론 채팅 메시지');
|
||||
await chat.fill('잠깐만요');
|
||||
for (const q of pages.filter((_, i) => i !== speaker)) await q.locator('.lg-chat .bot-activity [data-person]', { hasText: `${LIAR_NICKS[speaker]} 입력 중` }).waitFor({ timeout: 10_000 });
|
||||
await chat.press('Enter');
|
||||
for (const q of pages) await q.locator('.lg-msgs .lg-msg', { hasText: '잠깐만요' }).waitFor({ timeout: 15_000 });
|
||||
if (!(await p.getByLabel('내 설명 (한 문장)').count())) throw new Error('a chat line counted as the description');
|
||||
}
|
||||
if (refused < 0 && speaker !== L) {
|
||||
await input.fill(`${[...word].join(' ')} 맞죠`);
|
||||
await input.press('Enter');
|
||||
|
||||
Reference in New Issue
Block a user