From 9f16bf833a2194ae15d52a6562dff3816d85ae1c Mon Sep 17 00:00:00 2001 From: EJClaw Date: Sun, 18 Oct 2026 01:33:56 +0900 Subject: [PATCH] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EC=96=B4=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EC=9E=85=EB=A0=A5=20=EC=A4=91:=20=EC=84=A4?= =?UTF-8?q?=EB=AA=85=20=EC=B0=A8=EB=A1=80=EC=9D=B8=20=EC=82=AC=EB=9E=8C?= =?UTF-8?q?=EC=9D=B4=20=ED=86=A0=EB=A1=A0=20=EC=B1=84=ED=8C=85=EC=9D=84=20?= =?UTF-8?q?=EC=B3=90=EB=8F=84=20"=EC=9E=85=EB=A0=A5=20=EC=A4=91"=EC=9D=B4?= =?UTF-8?q?=20=EB=B3=B4=EC=9D=B4=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BotActivity hide → hideBots: 컴퓨터 활동에만 적용(사람의 입력 중은 언제나 채팅 칸에서 오므로 숨기지 않음) - BotActivity.test.tsx: 설명 차례인 사람의 채팅 입력은 보이고, 설명 차례인 컴퓨터의 입력은 숨겨지고, 상태 줄에는 생각 중만 - e2e: 설명 첫 차례에 말하는 사람이 토론 채팅을 치면 다른 사람 채팅 칸에 입력 중, 보낸 말은 설명으로 치지 않음 - apps/web tsconfig: *.test.tsx도 타입 검사에서 제외(.test.ts와 같게) Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/BotActivity.test.tsx | 43 ++++++++++++++++++++ apps/web/src/components/BotActivity.tsx | 10 ++--- apps/web/src/games/liar/index.tsx | 2 +- apps/web/tsconfig.json | 3 +- e2e/games.e2e.ts | 9 ++++ 5 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 apps/web/src/components/BotActivity.test.tsx diff --git a/apps/web/src/components/BotActivity.test.tsx b/apps/web/src/components/BotActivity.test.tsx new file mode 100644 index 0000000..a39412d --- /dev/null +++ b/apps/web/src/components/BotActivity.test.tsx @@ -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 }; +let st: St = { me: null, typing: {} }; +mock.module('../net/socket', () => ({ useRoom: (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(); + expect(html).toContain('말하는사람 입력 중'); +}); + +test('설명 차례인 컴퓨터가 설명을 치는 중이면 채팅 칸에 "입력 중"을 띄우지 않아요', () => { + const r = room({ 'bot:1': 'typing' }); + expect(renderToStaticMarkup()).toContain('컴퓨터 1 입력 중'); + expect(renderToStaticMarkup()).toBe(''); +}); + +test('상태 줄(only="thinking")에는 컴퓨터 "생각 중"만, 입력 중은 없어요', () => { + typingAs('speaker'); + const html = renderToStaticMarkup(); + expect(html).toContain('컴퓨터 1 생각 중'); + expect(html).not.toContain('입력 중'); +}); diff --git a/apps/web/src/components/BotActivity.tsx b/apps/web/src/components/BotActivity.tsx index 1be981d..f6d1b1d 100644 --- a/apps/web/src/components/BotActivity.tsx +++ b/apps/web/src/components/BotActivity.tsx @@ -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; diff --git a/apps/web/src/games/liar/index.tsx b/apps/web/src/games/liar/index.tsx index ee65bd0..da1820e 100644 --- a/apps/web/src/games/liar/index.tsx +++ b/apps/web/src/games/liar/index.tsx @@ -458,7 +458,7 @@ function ChatBox({ v, players, me, act }: { v: LiarView; players: Record - {room && } + {room && } {canWrite ? (
= { 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');