You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.4 KiB
84 lines
2.4 KiB
import { expect, it } from 'vitest';
|
|
import { diceFeedback } from '../src/lib/dice-feedback.js';
|
|
import type { Room } from '../src/lib/types.js';
|
|
|
|
const room: Room = {
|
|
id: 'table',
|
|
code: 'code',
|
|
name: 'Parchís',
|
|
gameId: 'parchis',
|
|
gameVersion: '2.0.0',
|
|
status: 'playing',
|
|
visibility: 'private',
|
|
maxPlayers: 2,
|
|
version: 2,
|
|
createdAt: '',
|
|
seat: 0,
|
|
players: [
|
|
{ userId: 'ana', nick: 'Ana', seat: 0, ready: true },
|
|
{ userId: 'luis', nick: 'Luis', seat: 1, ready: true },
|
|
],
|
|
state: { turn: 0, rolled: 6, die: 7 },
|
|
events: [
|
|
{
|
|
sequence: 1,
|
|
type: 'roll',
|
|
actorId: 'ana',
|
|
nick: 'Ana',
|
|
label: 'Dado: 6 · avanza 7',
|
|
createdAt: '',
|
|
},
|
|
],
|
|
legalActions: [{ type: 'move', piece: 0 }],
|
|
};
|
|
|
|
it('el jugador que tira recibe la distancia real y la ficha que debe elegir', () => {
|
|
expect(diceFeedback(room)).toMatchObject({
|
|
own: true,
|
|
title: 'Has sacado un 6',
|
|
next: 'Elige una ficha resaltada para avanzar 7 casillas.',
|
|
});
|
|
});
|
|
it('los demás ven quién ha tirado y quién debe mover, sin instrucciones propias', () => {
|
|
expect(diceFeedback({ ...room, seat: 1, legalActions: [] })).toMatchObject({
|
|
own: false,
|
|
title: 'Ana ha sacado un 6',
|
|
next: 'Ana debe elegir una ficha para avanzar 7 casillas.',
|
|
});
|
|
});
|
|
it('el cambio automático de turno no convierte una tirada ajena en una tirada propia', () => {
|
|
const next = {
|
|
...room,
|
|
seat: 1,
|
|
state: { turn: 1, rolled: 3, die: null },
|
|
legalActions: [{ type: 'roll' }],
|
|
};
|
|
expect(diceFeedback(next)).toMatchObject({
|
|
own: false,
|
|
title: 'Ana ha sacado un 3',
|
|
next: 'Es tu turno. Puedes lanzar el dado.',
|
|
});
|
|
expect(diceFeedback({ ...next, seat: 0 })).toMatchObject({
|
|
own: true,
|
|
next: 'Ahora juega Luis. Espera su tirada.',
|
|
});
|
|
});
|
|
it('un tercer seis anuncia el fin del turno y no promete otra tirada', () => {
|
|
const next = {
|
|
...room,
|
|
state: { turn: 1, rolled: 6, die: null },
|
|
events: [{ ...room.events![0], label: 'Tercer seis: termina el turno' }],
|
|
};
|
|
expect(diceFeedback(next).next).toBe(
|
|
'Tercer seis: tu turno ha terminado. Ahora juega Luis. Espera su tirada.',
|
|
);
|
|
});
|
|
it('los apodos repetidos no cambian la identidad del jugador que tira', () => {
|
|
const next = {
|
|
...room,
|
|
players: [room.players[0], { ...room.players[1], nick: 'Ana' }],
|
|
events: [{ ...room.events![0], actorId: 'luis' }],
|
|
};
|
|
expect(diceFeedback(next).own).toBe(false);
|
|
});
|