diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 18:08:38 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 18:08:38 +0100 |
| commit | 50fdaa8e5ad9454e783f01e2c369767834120d11 (patch) | |
| tree | b68fabbb7a8750a363cf41c1301acd0903cd0c73 /tests/client_core.rs | |
| parent | v4.0.2: port slots, blackjack and crash to structured views (diff) | |
| download | zagan-bet-50fdaa8e5ad9454e783f01e2c369767834120d11.tar.gz zagan-bet-50fdaa8e5ad9454e783f01e2c369767834120d11.zip | |
v4.0.3: lobby and history screens behind commands
Diffstat (limited to '')
| -rw-r--r-- | tests/client_core.rs | 80 |
1 files changed, 80 insertions, 0 deletions
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() { | |||
| 1407 | assert!((view.multiplier - 2.0).abs() < 1e-6); | 1407 | assert!((view.multiplier - 2.0).abs() < 1e-6); |
| 1408 | assert_eq!(view.potential, 20); | 1408 | assert_eq!(view.potential, 20); |
| 1409 | } | 1409 | } |
| 1410 | |||
| 1411 | #[test] | ||
| 1412 | fn the_lobby_view_lists_the_games_and_the_account() { | ||
| 1413 | let mut h = Harness::new(); | ||
| 1414 | h.core.set_balance(1000); | ||
| 1415 | |||
| 1416 | let Some(View::Lobby(lobby)) = h.core.view() else { | ||
| 1417 | panic!("expected the lobby"); | ||
| 1418 | }; | ||
| 1419 | assert!(lobby.connected); | ||
| 1420 | assert_eq!(lobby.user.as_deref(), Some("alice")); | ||
| 1421 | assert_eq!(lobby.balance, Some(1000)); | ||
| 1422 | |||
| 1423 | let games: Vec<&str> = lobby.games.iter().map(|(game, _)| game.as_str()).collect(); | ||
| 1424 | assert_eq!(games, vec!["blackjack", "crash", "roulette", "slots"]); | ||
| 1425 | } | ||
| 1426 | |||
| 1427 | #[test] | ||
| 1428 | fn a_play_command_opens_the_game_view() { | ||
| 1429 | let mut h = Harness::new(); | ||
| 1430 | |||
| 1431 | let effects = h.core.command(Command::Play { | ||
| 1432 | game: "slots".to_string(), | ||
| 1433 | bet: Some(25), | ||
| 1434 | }); | ||
| 1435 | h.apply(effects); | ||
| 1436 | |||
| 1437 | let Some(View::Slots(view)) = h.core.view() else { | ||
| 1438 | panic!("expected a slots view"); | ||
| 1439 | }; | ||
| 1440 | assert_eq!(view.bet, 25); | ||
| 1441 | assert!(h.sent.iter().any(|line| line == "INFO")); | ||
| 1442 | assert_eq!(h.board().len(), 10); | ||
| 1443 | } | ||
| 1444 | |||
| 1445 | #[test] | ||
| 1446 | fn history_is_a_screen_and_keeps_its_records() { | ||
| 1447 | let mut h = Harness::new(); | ||
| 1448 | |||
| 1449 | let effects = h.core.command(Command::History { limit: 5 }); | ||
| 1450 | h.apply(effects); | ||
| 1451 | assert_eq!(h.sent.last().map(String::as_str), Some("HISTORY 5")); | ||
| 1452 | |||
| 1453 | 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}}]"#; | ||
| 1454 | h.reply(&format!("HISTORY {json}")); | ||
| 1455 | |||
| 1456 | let Some(View::History(view)) = h.core.view() else { | ||
| 1457 | panic!("expected the history screen"); | ||
| 1458 | }; | ||
| 1459 | assert_eq!(view.records.len(), 1); | ||
| 1460 | assert_eq!(view.records[0].game, "crash"); | ||
| 1461 | assert_eq!(view.records[0].summary(), "cashed 1.13x"); | ||
| 1462 | |||
| 1463 | // The terminal adapter still prints the table. | ||
| 1464 | assert!(h | ||
| 1465 | .screen | ||
| 1466 | .lines | ||
| 1467 | .iter() | ||
| 1468 | .any(|line| line.starts_with("Recent plays (1)"))); | ||
| 1469 | } | ||
| 1470 | |||
| 1471 | #[test] | ||
| 1472 | fn logging_out_and_showing_the_lobby_switch_the_screen() { | ||
| 1473 | let mut h = Harness::new(); | ||
| 1474 | h.core.command(Command::History { limit: 5 }); | ||
| 1475 | assert!(matches!(h.core.view(), Some(View::History(_)))); | ||
| 1476 | |||
| 1477 | h.core.command(Command::ShowLobby); | ||
| 1478 | let Some(View::Lobby(lobby)) = h.core.view() else { | ||
| 1479 | panic!("expected the lobby"); | ||
| 1480 | }; | ||
| 1481 | assert_eq!(lobby.user.as_deref(), Some("alice")); | ||
| 1482 | |||
| 1483 | let effects = h.core.command(Command::Logout); | ||
| 1484 | h.apply(effects); | ||
| 1485 | let Some(View::Lobby(lobby)) = h.core.view() else { | ||
| 1486 | panic!("expected the lobby"); | ||
| 1487 | }; | ||
| 1488 | assert_eq!(lobby.user, None); | ||
| 1489 | } | ||
