fix: možnost připojit se ke hře Tetris během odpočtu před startem

This commit is contained in:
mates committed 2026-10-20 09:43:21 +02:00
1 parent fe12098ed0
commit bc2cc75d7d
3 files changed
+62 -17

No files matched your search

+26 -1
View File
@@ -1,4 +1,4 @@
import { TetrisGame, TetrisState, TetrisSettings, GarbageEvent, COUNTDOWN_SECONDS, MIN_ATTACK_GAP_MS, WATCH_FLUSH_MS, BOARD_WIDTH, BOARD_HEIGHT, PLAYER_TIMEOUT_MS, DEFAULT_SETTINGS } from '../tetrisGame';
import { TetrisGame, TetrisState, TetrisSettings, GarbageEvent, COUNTDOWN_SECONDS, JOIN_GRACE_SECONDS, MIN_ATTACK_GAP_MS, WATCH_FLUSH_MS, BOARD_WIDTH, BOARD_HEIGHT, PLAYER_TIMEOUT_MS, DEFAULT_SETTINGS } from '../tetrisGame';
import { GameError } from '../minigames';
import { fakeClock } from './helpers/fakeClock';
@@ -195,4 +195,29 @@ describe('tetris', () => {
ctx.startGame('alice');
expect(() => ctx.game.join('bob')).toThrow(GameError);
});
test('během odpočtu se lze ještě připojit', () => {
const ctx = setup();
ctx.game.join('alice');
ctx.game.start('alice');
ctx.clock.advance(1000);
ctx.game.join('bob');
expect(ctx.last()).toMatchObject({ phase: 'countdown', countdown: COUNTDOWN_SECONDS - 1 });
expect(ctx.last().players.map(p => p.login)).toEqual(['alice', 'bob']);
ctx.clock.advance((COUNTDOWN_SECONDS - 1) * 1000);
expect(ctx.last().phase).toBe('playing');
});
test('připojení na poslední chvíli prodlouží odpočet', () => {
const ctx = setup();
ctx.game.join('alice');
ctx.game.start('alice');
ctx.clock.advance((COUNTDOWN_SECONDS - 1) * 1000);
ctx.game.join('bob');
expect(ctx.last()).toMatchObject({ phase: 'countdown', countdown: JOIN_GRACE_SECONDS });
ctx.clock.advance((JOIN_GRACE_SECONDS - 1) * 1000);
expect(ctx.last().phase).toBe('countdown');
ctx.clock.advance(1000);
expect(ctx.last().phase).toBe('playing');
});
});