혼자인 대기실에서 브라우저 뒤로가기(홈)로 나가면 빈 방이 10분 동안 남던 문제: 다른 사람이 없고 게임 전이면 detach를 나가기로 처리해 방을 바로 닫음. 방 안 📖 규칙도 팝업으로(규칙 페이지로 넘어가며 방을 떠나지 않게), e2e/room-back.e2e.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-14 05:03:12 +09:00
parent b93228e5af
commit 71bdfd201a
6 changed files with 175 additions and 4 deletions

View File

@@ -93,12 +93,51 @@ describe('idle guests', () => {
});
describe('leaving the room page', () => {
test('detach keeps the seat but the room no longer counts the connection', async () => {
test('alone with no game running (뒤로가기 from the lobby): leaving the page leaves the room and it closes at once', async () => {
const s = start();
const g = await guest(s.base, '혼자');
const c = await connect(s, g);
const r = await api(s.base, '/api/rooms', { method: 'POST', cookie: c.cookie, body: JSON.stringify({ gameId: 'omok' }) });
c.send({ t: 'join', code: r.body.code, as: 'player' });
await c.waitFor((m) => m.t === 'room');
expect(s.rooms.get(r.body.code)).toBeDefined();
c.send({ t: 'detach' });
for (let i = 0; i < 50 && s.rooms.get(r.body.code); i++) await sleep(10);
expect(s.rooms.get(r.body.code)).toBeUndefined();
expect(s.rooms.activeRoomFor(g.id)).toBeNull();
// The same socket is fine afterwards.
c.send({ t: 'ping', ts: 1 });
await c.waitFor((m) => m.t === 'pong');
});
test('someone else is in the lobby: leaving the page keeps my seat (I can come back)', async () => {
const s = start();
const a = await guest(s.base, '방장');
const b = await guest(s.base, '친구');
const ca = await connect(s, a);
const cb = await connect(s, b);
const r = await api(s.base, '/api/rooms', { method: 'POST', cookie: ca.cookie, body: JSON.stringify({ gameId: 'omok' }) });
ca.send({ t: 'join', code: r.body.code, as: 'player' });
await ca.waitFor((m) => m.t === 'room');
cb.send({ t: 'join', code: r.body.code, as: 'player' });
await cb.waitFor((m) => m.t === 'room');
const room = s.rooms.get(r.body.code)!;
ca.send({ t: 'detach' });
for (let i = 0; i < 50 && room.conns.size > 1; i++) await sleep(10);
expect(room.conns.size).toBe(1);
expect(room.seatOf(a.id)).toBeGreaterThanOrEqual(0);
expect(s.rooms.get(r.body.code)).toBe(room);
});
test('detach during a game keeps the seat but the room no longer counts the connection', async () => {
const s = start();
const g = await guest(s.base, '홈으로');
const c = await connect(s, g);
const code = await practiceRoom(s, c);
const room = s.rooms.get(code)!;
c.send({ t: 'start' });
for (let i = 0; i < 50 && room.status !== 'playing'; i++) await sleep(10);
expect(room.status).toBe('playing');
expect(room.conns.size).toBe(1);
c.send({ t: 'detach' });
for (let i = 0; i < 50 && room.conns.size; i++) await sleep(10);

View File

@@ -546,6 +546,9 @@ export class Room {
const u = conn.userId;
if (this.conns.get(u) !== conn) return;
if (this.spectators.has(u)) return this.disconnect(conn);
// Alone in the lobby: nobody to come back to, so leaving the page (뒤로가기, 홈) leaves the room and the empty room
// closes now instead of lingering (2026-10-14). A game (running, or its result: 다시 보기 comes back) keeps the seat.
if (this.status === 'lobby' && this.conns.size === 1 && !this.seatedIds().some((x) => x !== u && !isBotId(x) && !this.leftDuringGame.has(x))) return this.leave(u);
this.conns.delete(u);
this.detached.set(u, conn);
if (this.conns.size === 0) this.becameEmpty('disconnect');