diff options
Diffstat (limited to 'tests/client_core.rs')
| -rw-r--r-- | tests/client_core.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs index 79b3dd8..c298ab7 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs | |||
| @@ -386,3 +386,92 @@ fn prompt_cursor_tracks_the_input() { | |||
| 386 | assert_eq!(h.screen.prompt, ""); | 386 | assert_eq!(h.screen.prompt, ""); |
| 387 | assert_eq!(h.screen.prompt_cursor, 2); | 387 | assert_eq!(h.screen.prompt_cursor, 2); |
| 388 | } | 388 | } |
| 389 | |||
| 390 | #[test] | ||
| 391 | fn info_shows_the_host_and_the_server_fields() { | ||
| 392 | let mut h = Harness::new(); | ||
| 393 | h.core.set_host_info( | ||
| 394 | Some("127.0.0.1:11525".to_string()), | ||
| 395 | Some("deadbeef".to_string()), | ||
| 396 | ); | ||
| 397 | |||
| 398 | h.line("info"); | ||
| 399 | assert!(h | ||
| 400 | .screen | ||
| 401 | .lines | ||
| 402 | .iter() | ||
| 403 | .any(|line| line.contains("Connected to: 127.0.0.1:11525"))); | ||
| 404 | assert!(h | ||
| 405 | .screen | ||
| 406 | .lines | ||
| 407 | .iter() | ||
| 408 | .any(|line| line.contains("Fingerprint: deadbeef"))); | ||
| 409 | |||
| 410 | h.reply("INFO alice 42 1234"); | ||
| 411 | |||
| 412 | assert!(h.screen.lines.iter().any(|line| line == "User: alice")); | ||
| 413 | assert!(h.screen.lines.iter().any(|line| line == "Account: 42")); | ||
| 414 | assert!(h | ||
| 415 | .screen | ||
| 416 | .lines | ||
| 417 | .iter() | ||
| 418 | .any(|line| line == "Balance: 1234 PLN")); | ||
| 419 | } | ||
| 420 | |||
| 421 | #[test] | ||
| 422 | fn info_without_a_connection_does_not_send() { | ||
| 423 | let mut h = Harness::new(); | ||
| 424 | h.core.set_connected(false); | ||
| 425 | |||
| 426 | h.line("info"); | ||
| 427 | |||
| 428 | assert!(h | ||
| 429 | .screen | ||
| 430 | .lines | ||
| 431 | .iter() | ||
| 432 | .any(|line| line.contains("Not connected to any host"))); | ||
| 433 | assert!(h.sent.is_empty()); | ||
| 434 | } | ||
| 435 | |||
| 436 | #[test] | ||
| 437 | fn ping_prints_pong() { | ||
| 438 | let mut h = Harness::new(); | ||
| 439 | h.line("ping"); | ||
| 440 | assert_eq!(h.sent.last().map(String::as_str), Some("PING")); | ||
| 441 | |||
| 442 | h.reply("PONG"); | ||
| 443 | |||
| 444 | assert!(h.screen.lines.iter().any(|line| line == "Pong")); | ||
| 445 | } | ||
| 446 | |||
| 447 | #[test] | ||
| 448 | fn send_prints_the_echo() { | ||
| 449 | let mut h = Harness::new(); | ||
| 450 | h.line("send hello"); | ||
| 451 | h.reply("hello"); | ||
| 452 | |||
| 453 | assert!(h | ||
| 454 | .screen | ||
| 455 | .lines | ||
| 456 | .iter() | ||
| 457 | .any(|line| line == "Echo: hello")); | ||
| 458 | } | ||
| 459 | |||
| 460 | #[test] | ||
| 461 | fn disconnect_clears_connection_state() { | ||
| 462 | let mut h = Harness::new(); | ||
| 463 | h.line("disconnect"); | ||
| 464 | |||
| 465 | assert!(h | ||
| 466 | .screen | ||
| 467 | .lines | ||
| 468 | .iter() | ||
| 469 | .any(|line| line == "Disconnected")); | ||
| 470 | |||
| 471 | h.line("play slots"); | ||
| 472 | assert!(h | ||
| 473 | .screen | ||
| 474 | .lines | ||
| 475 | .iter() | ||
| 476 | .any(|line| line.contains("Not connected"))); | ||
| 477 | } | ||
