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');