Posible mejora en el multidispositivo
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import 'package:farolero/modelos/jugador.dart';
|
||||
import 'package:farolero/modelos/partida.dart';
|
||||
import 'package:farolero/modelos/snapshot_partida_online.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('serializa resultado online preservando acentos y caracteres especiales',
|
||||
() {
|
||||
final partida = Partida(
|
||||
config: const ConfigPartida(categoria: 'animales'),
|
||||
jugadores: [
|
||||
Jugador(id: 'j1', nombre: 'León', esImpostor: true, eliminado: true),
|
||||
Jugador(id: 'j2', nombre: 'María'),
|
||||
Jugador(id: 'j3', nombre: 'Óscar'),
|
||||
],
|
||||
palabraSecreta: 'Camión',
|
||||
categoriaReal: 'Animales fantásticos',
|
||||
fase: FaseJuego.resultado,
|
||||
historialVotaciones: const [
|
||||
ResultadoVotacion(
|
||||
eliminadoId: 'j1',
|
||||
eliminadoNombre: 'León',
|
||||
eraImpostor: true,
|
||||
votos: {'j2': 'j1', 'j3': 'j1'},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final snapshot = SnapshotPartidaOnline.desdePartida(
|
||||
partida,
|
||||
roomId: 'sala-áéíóú',
|
||||
revelarPalabra: true,
|
||||
revelarImpostores: true,
|
||||
);
|
||||
|
||||
final reparsed = SnapshotPartidaOnline.fromJson(snapshot.toJson());
|
||||
|
||||
expect(reparsed.roomId, 'sala-áéíóú');
|
||||
expect(reparsed.categoria, 'Animales fantásticos');
|
||||
expect(reparsed.palabraSecreta, 'Camión');
|
||||
expect(reparsed.jugadores.map((jugador) => jugador.nombre), [
|
||||
'León',
|
||||
'María',
|
||||
'Óscar',
|
||||
]);
|
||||
expect(reparsed.resultadoActual?.eliminadoNombre, 'León');
|
||||
expect(reparsed.historialVotaciones.single.votos, {'j2': 'j1', 'j3': 'j1'});
|
||||
expect(reparsed.impostores, ['León']);
|
||||
});
|
||||
|
||||
test('no revela palabra ni impostores salvo que el host lo indique', () {
|
||||
final partida = Partida(
|
||||
config: const ConfigPartida(categoria: 'lugares'),
|
||||
jugadores: [
|
||||
Jugador(id: 'j1', nombre: 'Ana', esImpostor: true),
|
||||
Jugador(id: 'j2', nombre: 'Beto'),
|
||||
Jugador(id: 'j3', nombre: 'Carla'),
|
||||
],
|
||||
palabraSecreta: 'Biblioteca',
|
||||
categoriaReal: 'Lugares',
|
||||
fase: FaseJuego.debate,
|
||||
);
|
||||
|
||||
final datos = SnapshotPartidaOnline.desdePartida(partida).toJson();
|
||||
|
||||
expect(datos.containsKey('palabraSecreta'), isFalse);
|
||||
expect(datos.containsKey('impostores'), isFalse);
|
||||
expect(datos['jugadoresTodos'], hasLength(3));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user