fix: znemožnění spuštění Tetrisu v jednom hráči
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 26s
CI / Build server (push) Successful in 29s
CI / Build client (push) Successful in 43s
CI / Playwright E2E tests (push) Successful in 2m2s
CI / Build and push Docker image (push) Successful in 52s
CI / Notify (push) Successful in 4s

This commit is contained in:
mates committed 2026-10-20 09:47:00 +02:00
1 parent bc2cc75d7d
commit 304c7656e9
3 files changed
+19 -6

No files matched your search

+12 -2
View File
@@ -4,12 +4,12 @@ import { fakeClock } from './helpers/fakeClock';
const BOARD = '0'.repeat(BOARD_WIDTH * (BOARD_HEIGHT - 1)) + '1'.repeat(BOARD_WIDTH);
function setup() {
function setup(minPlayers = 1) {
const clock = fakeClock();
const all: TetrisState[] = [];
const watched: TetrisState[] = [];
const garbage: GarbageEvent[] = [];
const game = new TetrisGame(s => all.push(s), s => watched.push(s), e => garbage.push(e), 1, clock);
const game = new TetrisGame(s => all.push(s), s => watched.push(s), e => garbage.push(e), minPlayers, clock);
const last = () => all[all.length - 1];
const startWith = (settings: Partial<TetrisSettings>, ...logins: string[]) => {
logins.forEach(l => game.join(l));
@@ -22,6 +22,16 @@ function setup() {
}
describe('tetris', () => {
test('společnou hru nejde spustit jen s jedním hráčem', () => {
const ctx = setup(2);
ctx.game.join('alice');
expect(() => ctx.game.start('alice')).toThrow(GameError);
expect(ctx.last()).toMatchObject({ phase: 'lobby' });
ctx.game.join('bob');
ctx.game.start('alice');
expect(ctx.last()).toMatchObject({ phase: 'countdown' });
});
test('po odpočtu začne hra se společným seedem', () => {
const ctx = setup();
ctx.startGame('alice', 'bob');