summaryrefslogtreecommitdiffstats
path: root/tests/client_core.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/client_core.rs111
1 files changed, 99 insertions, 12 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs
index 695dcb1..0a2cb7b 100644
--- a/tests/client_core.rs
+++ b/tests/client_core.rs
@@ -12,7 +12,7 @@ use zagan_bet::client::games::response::{
12}; 12};
13use zagan_bet::client::games::roulette::{Cursor, Direction}; 13use zagan_bet::client::games::roulette::{Cursor, Direction};
14use zagan_bet::client::ui::command_names; 14use zagan_bet::client::ui::command_names;
15use zagan_bet::client::view::{Command, RoulettePhase, View}; 15use zagan_bet::client::view::{Command, RoulettePhase, SlotsPhase, View};
16use zagan_bet::roulette::BetTarget; 16use zagan_bet::roulette::BetTarget;
17use zagan_bet::crash::CrashState; 17use zagan_bet::crash::CrashState;
18 18
@@ -1209,7 +1209,7 @@ fn the_roulette_view_reflects_the_cursor_and_bets() {
1209 let mut h = Harness::new(); 1209 let mut h = Harness::new();
1210 h.enter_roulette(); 1210 h.enter_roulette();
1211 1211
1212 let View::Roulette(view) = h.core.view() else { 1212 let Some(View::Roulette(view)) = h.core.view() else {
1213 panic!("expected a roulette view"); 1213 panic!("expected a roulette view");
1214 }; 1214 };
1215 assert_eq!(view.cursor, Cursor::Lattice { x: 1, y: 5 }); 1215 assert_eq!(view.cursor, Cursor::Lattice { x: 1, y: 5 });
@@ -1226,7 +1226,7 @@ fn the_roulette_view_reflects_the_cursor_and_bets() {
1226 let effects = h.core.command(Command::PlaceBet); 1226 let effects = h.core.command(Command::PlaceBet);
1227 h.apply(effects); 1227 h.apply(effects);
1228 1228
1229 let View::Roulette(view) = h.core.view() else { 1229 let Some(View::Roulette(view)) = h.core.view() else {
1230 panic!("expected a roulette view"); 1230 panic!("expected a roulette view");
1231 }; 1231 };
1232 assert_eq!( 1232 assert_eq!(
@@ -1248,7 +1248,7 @@ fn clicking_a_bet_target_does_not_move_the_cursor() {
1248 let effects = h.core.command(Command::PlaceBetAt(BetTarget::Split { a: 1, b: 4 })); 1248 let effects = h.core.command(Command::PlaceBetAt(BetTarget::Split { a: 1, b: 4 }));
1249 h.apply(effects); 1249 h.apply(effects);
1250 1250
1251 let View::Roulette(view) = h.core.view() else { 1251 let Some(View::Roulette(view)) = h.core.view() else {
1252 panic!("expected a roulette view"); 1252 panic!("expected a roulette view");
1253 }; 1253 };
1254 assert_eq!(view.bets.amount_on(&BetTarget::Split { a: 1, b: 4 }), 10); 1254 assert_eq!(view.bets.amount_on(&BetTarget::Split { a: 1, b: 4 }), 10);
@@ -1269,7 +1269,7 @@ fn the_roulette_view_reports_the_result() {
1269 let bets = r#"{"chips":[{"target":{"bet":"straight","number":1},"amount":10}]}"#; 1269 let bets = r#"{"chips":[{"target":{"bet":"straight","number":1},"amount":10}]}"#;
1270 h.reply(&format!("ROULETTE_RESULT s1 360 10 1350 1 red {bets}")); 1270 h.reply(&format!("ROULETTE_RESULT s1 360 10 1350 1 red {bets}"));
1271 1271
1272 let View::Roulette(view) = h.core.view() else { 1272 let Some(View::Roulette(view)) = h.core.view() else {
1273 panic!("expected a roulette view"); 1273 panic!("expected a roulette view");
1274 }; 1274 };
1275 assert_eq!(view.phase, RoulettePhase::Result); 1275 assert_eq!(view.phase, RoulettePhase::Result);
@@ -1286,27 +1286,31 @@ fn the_chip_size_is_a_command() {
1286 h.enter_roulette(); 1286 h.enter_roulette();
1287 1287
1288 h.core.command(Command::AdjustChip(10)); 1288 h.core.command(Command::AdjustChip(10));
1289 let View::Roulette(view) = h.core.view() else { 1289 let Some(View::Roulette(view)) = h.core.view() else {
1290 panic!("expected a roulette view"); 1290 panic!("expected a roulette view");
1291 }; 1291 };
1292 assert_eq!(view.chip, 20); 1292 assert_eq!(view.chip, 20);
1293 1293
1294 h.core.command(Command::SetChip(5)); 1294 h.core.command(Command::SetChip(5));
1295 let View::Roulette(view) = h.core.view() else { 1295 let Some(View::Roulette(view)) = h.core.view() else {
1296 panic!("expected a roulette view"); 1296 panic!("expected a roulette view");
1297 }; 1297 };
1298 assert_eq!(view.chip, 10, "the chip never goes below 10"); 1298 assert_eq!(view.chip, 10, "the chip never goes below 10");
1299} 1299}
1300 1300
1301#[test] 1301#[test]
1302fn unported_games_still_reach_the_frontend_as_text() { 1302fn slots_reach_the_frontend_as_a_structured_view() {
1303 let mut h = Harness::new(); 1303 let mut h = Harness::new();
1304 h.enter_slots("10"); 1304 h.enter_slots("10");
1305 h.key(Key::Char(' '));
1305 1306
1306 match h.core.view() { 1307 let view = h.core.view().expect("a slots view");
1307 View::Text(lines) => assert_eq!(lines.len(), 10), 1308 let View::Slots(view) = view else {
1308 other => panic!("expected the text bridge, got {other:?}"), 1309 panic!("expected a slots view");
1309 } 1310 };
1311 assert_eq!(view.bet, 10);
1312 assert_eq!(view.phase, SlotsPhase::Spinning);
1313 assert_eq!(h.board().len(), 10);
1310} 1314}
1311 1315
1312#[test] 1316#[test]
@@ -1320,3 +1324,86 @@ fn leaving_through_a_command_clears_the_screen() {
1320 assert!(!h.core.is_in_game()); 1324 assert!(!h.core.is_in_game());
1321 assert!(h.screen.lines.iter().any(|line| line == "Game exited.")); 1325 assert!(h.screen.lines.iter().any(|line| line == "Game exited."));
1322} 1326}
1327
1328#[test]
1329fn the_slots_view_carries_the_result() {
1330 let mut h = Harness::new();
1331 h.enter_slots("10");
1332 h.key(Key::Char(' '));
1333 h.reply(&format!(
1334 "GAME_RESULT s1 20 10 1010 {WIN3} win 1 0,3,6"
1335 ));
1336
1337 let Some(View::Slots(view)) = h.core.view() else {
1338 panic!("expected a slots view");
1339 };
1340 assert_eq!(view.phase, SlotsPhase::Result);
1341 assert_eq!(view.winnings, Some(20));
1342 assert_eq!(view.win_type, "win");
1343 assert_eq!(view.win_lines, vec![1]);
1344 assert_eq!(view.win_cells, vec![0, 3, 6]);
1345 assert_eq!(view.reels.len(), 15);
1346}
1347
1348#[test]
1349fn the_blackjack_view_carries_the_hand_and_legal_actions() {
1350 let mut h = Harness::new();
1351 h.enter_blackjack();
1352 h.key(Key::Char(' '));
1353
1354 let player = bj_state(
1355 "bj1",
1356 "player",
1357 &["10S", "6H"],
1358 &["9D", "?"],
1359 16,
1360 9,
1361 10,
1362 10,
1363 990,
1364 &["hit", "stand", "double"],
1365 "playing",
1366 0,
1367 );
1368 h.reply(&format!(
1369 "BLACKJACK_STATE {}",
1370 serde_json::to_string(&player).unwrap()
1371 ));
1372
1373 let Some(View::Blackjack(view)) = h.core.view() else {
1374 panic!("expected a blackjack view");
1375 };
1376 assert_eq!(view.status, "player");
1377 assert_eq!(view.bet, 10);
1378 let hand = view.hand.expect("the hand is part of the view");
1379 assert_eq!(hand.player_total, 16);
1380 assert_eq!(hand.actions, vec!["hit", "stand", "double"]);
1381 assert_eq!(hand.session_id, "bj1");
1382}
1383
1384#[test]
1385fn the_crash_view_follows_the_round() {
1386 let mut h = Harness::new();
1387 h.enter_crash();
1388 h.key(Key::Char(' '));
1389
1390 let running = crash_state("running", 1.0, None, 0, 990);
1391 h.reply(&crash_line("CRASH_START", &running));
1392
1393 let Some(View::Crash(view)) = h.core.view() else {
1394 panic!("expected a crash view");
1395 };
1396 assert_eq!(view.status, "running");
1397 assert_eq!(view.bet, 10);
1398 assert_eq!(view.balance, Some(990));
1399 assert!((view.multiplier - 1.0).abs() < 1e-9);
1400 assert_eq!(view.potential, 10);
1401 assert_eq!(view.crash_point, None);
1402
1403 h.tick(Duration::from_secs(5));
1404 let Some(View::Crash(view)) = h.core.view() else {
1405 panic!("expected a crash view");
1406 };
1407 assert!((view.multiplier - 2.0).abs() < 1e-6);
1408 assert_eq!(view.potential, 20);
1409}