diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/client_ui.rs | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/tests/client_ui.rs b/tests/client_ui.rs index 44febde..7969139 100644 --- a/tests/client_ui.rs +++ b/tests/client_ui.rs | |||
| @@ -2,7 +2,7 @@ use std::time::Duration; | |||
| 2 | use zagan_bet::client::ui::{ | 2 | use zagan_bet::client::ui::{ |
| 3 | command_names, completion_lines, display_width, first_contact_lines, format_pong, help_lines, | 3 | command_names, completion_lines, display_width, first_contact_lines, format_pong, help_lines, |
| 4 | host_lines, input_cursor_column, lines_to_move_up, parse_bet_arg, record_history, | 4 | host_lines, input_cursor_column, lines_to_move_up, parse_bet_arg, record_history, |
| 5 | visual_line_count, | 5 | terminal_too_small, visual_line_count, MIN_COLUMNS, MIN_ROWS, |
| 6 | }; | 6 | }; |
| 7 | 7 | ||
| 8 | #[test] | 8 | #[test] |
| @@ -255,3 +255,53 @@ fn hosts_without_a_fingerprint_are_never_merged() { | |||
| 255 | 2 | 255 | 2 |
| 256 | ); | 256 | ); |
| 257 | } | 257 | } |
| 258 | |||
| 259 | #[test] | ||
| 260 | fn a_terminal_smaller_than_every_game_needs_is_refused() { | ||
| 261 | assert!(terminal_too_small(80, 24).is_none()); | ||
| 262 | assert!(terminal_too_small(120, 40).is_none()); | ||
| 263 | |||
| 264 | assert!(terminal_too_small(79, 24).is_some()); | ||
| 265 | assert!(terminal_too_small(80, 23).is_some()); | ||
| 266 | |||
| 267 | let message = terminal_too_small(40, 10).unwrap(); | ||
| 268 | assert!(message.contains("80x24")); | ||
| 269 | assert!(message.contains("40x10")); | ||
| 270 | } | ||
| 271 | |||
| 272 | #[test] | ||
| 273 | fn the_roulette_felt_fits_the_minimum_terminal() { | ||
| 274 | use zagan_bet::client::games::roulette::{Cursor, RouletteGame, ROULETTE_BOARD_LINES}; | ||
| 275 | use zagan_bet::client::games::traits::{Game, GamePhase, GameState}; | ||
| 276 | use zagan_bet::roulette::Bets; | ||
| 277 | use std::collections::HashMap; | ||
| 278 | |||
| 279 | let mut data = HashMap::new(); | ||
| 280 | data.insert("balance".to_string(), "1000".to_string()); | ||
| 281 | data.insert("chip".to_string(), "10".to_string()); | ||
| 282 | data.insert("status".to_string(), "place".to_string()); | ||
| 283 | data.insert("bets".to_string(), Bets::default().to_json()); | ||
| 284 | data.insert("cursor".to_string(), Cursor::Zero.encoded()); | ||
| 285 | let state = GameState { | ||
| 286 | game_type: "roulette".to_string(), | ||
| 287 | bet_amount: 0, | ||
| 288 | phase: GamePhase::WaitingToStart, | ||
| 289 | data, | ||
| 290 | }; | ||
| 291 | |||
| 292 | let board = RouletteGame::new().render(&state); | ||
| 293 | let lines: Vec<&str> = board.split("\r\n").collect(); | ||
| 294 | assert_eq!(lines.len(), ROULETTE_BOARD_LINES); | ||
| 295 | assert_eq!(RouletteGame::new().render_lines(&state), ROULETTE_BOARD_LINES); | ||
| 296 | for line in lines { | ||
| 297 | assert!( | ||
| 298 | display_width(line) <= MIN_COLUMNS as usize, | ||
| 299 | "roulette line is {} wide: {line:?}", | ||
| 300 | display_width(line) | ||
| 301 | ); | ||
| 302 | } | ||
| 303 | assert!( | ||
| 304 | ROULETTE_BOARD_LINES + 4 <= MIN_ROWS as usize, | ||
| 305 | "the board must leave room for the prompt and a few transcript lines" | ||
| 306 | ); | ||
| 307 | } | ||
