From 50fdaa8e5ad9454e783f01e2c369767834120d11 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 18:08:38 +0100 Subject: v4.0.3: lobby and history screens behind commands --- tests/client_core.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'tests/client_core.rs') diff --git a/tests/client_core.rs b/tests/client_core.rs index 0a2cb7b..d070a5b 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs @@ -1407,3 +1407,83 @@ fn the_crash_view_follows_the_round() { assert!((view.multiplier - 2.0).abs() < 1e-6); assert_eq!(view.potential, 20); } + +#[test] +fn the_lobby_view_lists_the_games_and_the_account() { + let mut h = Harness::new(); + h.core.set_balance(1000); + + let Some(View::Lobby(lobby)) = h.core.view() else { + panic!("expected the lobby"); + }; + assert!(lobby.connected); + assert_eq!(lobby.user.as_deref(), Some("alice")); + assert_eq!(lobby.balance, Some(1000)); + + let games: Vec<&str> = lobby.games.iter().map(|(game, _)| game.as_str()).collect(); + assert_eq!(games, vec!["blackjack", "crash", "roulette", "slots"]); +} + +#[test] +fn a_play_command_opens_the_game_view() { + let mut h = Harness::new(); + + let effects = h.core.command(Command::Play { + game: "slots".to_string(), + bet: Some(25), + }); + h.apply(effects); + + let Some(View::Slots(view)) = h.core.view() else { + panic!("expected a slots view"); + }; + assert_eq!(view.bet, 25); + assert!(h.sent.iter().any(|line| line == "INFO")); + assert_eq!(h.board().len(), 10); +} + +#[test] +fn history_is_a_screen_and_keeps_its_records() { + let mut h = Harness::new(); + + let effects = h.core.command(Command::History { limit: 5 }); + h.apply(effects); + assert_eq!(h.sent.last().map(String::as_str), Some("HISTORY 5")); + + let json = r#"[{"game":"crash","bet":10,"winnings":11,"balance_after":1011,"at":"2026-11-01 12:00:00","details":{"result":"cashed","multiplier":1.13}}]"#; + h.reply(&format!("HISTORY {json}")); + + let Some(View::History(view)) = h.core.view() else { + panic!("expected the history screen"); + }; + assert_eq!(view.records.len(), 1); + assert_eq!(view.records[0].game, "crash"); + assert_eq!(view.records[0].summary(), "cashed 1.13x"); + + // The terminal adapter still prints the table. + assert!(h + .screen + .lines + .iter() + .any(|line| line.starts_with("Recent plays (1)"))); +} + +#[test] +fn logging_out_and_showing_the_lobby_switch_the_screen() { + let mut h = Harness::new(); + h.core.command(Command::History { limit: 5 }); + assert!(matches!(h.core.view(), Some(View::History(_)))); + + h.core.command(Command::ShowLobby); + let Some(View::Lobby(lobby)) = h.core.view() else { + panic!("expected the lobby"); + }; + assert_eq!(lobby.user.as_deref(), Some("alice")); + + let effects = h.core.command(Command::Logout); + h.apply(effects); + let Some(View::Lobby(lobby)) = h.core.view() else { + panic!("expected the lobby"); + }; + assert_eq!(lobby.user, None); +} -- cgit v1.2.3