From 25f9abeb4c69024f8d9dceb472ba33c03e00daa0 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 28 Oct 2026 22:36:07 +0100 Subject: v0.2.5: fix terminal width, ping timing and output formatting --- tests/client_core.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'tests/client_core.rs') 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() { assert_eq!(h.screen.prompt, ""); assert_eq!(h.screen.prompt_cursor, 2); } + +#[test] +fn info_shows_the_host_and_the_server_fields() { + let mut h = Harness::new(); + h.core.set_host_info( + Some("127.0.0.1:11525".to_string()), + Some("deadbeef".to_string()), + ); + + h.line("info"); + assert!(h + .screen + .lines + .iter() + .any(|line| line.contains("Connected to: 127.0.0.1:11525"))); + assert!(h + .screen + .lines + .iter() + .any(|line| line.contains("Fingerprint: deadbeef"))); + + h.reply("INFO alice 42 1234"); + + assert!(h.screen.lines.iter().any(|line| line == "User: alice")); + assert!(h.screen.lines.iter().any(|line| line == "Account: 42")); + assert!(h + .screen + .lines + .iter() + .any(|line| line == "Balance: 1234 PLN")); +} + +#[test] +fn info_without_a_connection_does_not_send() { + let mut h = Harness::new(); + h.core.set_connected(false); + + h.line("info"); + + assert!(h + .screen + .lines + .iter() + .any(|line| line.contains("Not connected to any host"))); + assert!(h.sent.is_empty()); +} + +#[test] +fn ping_prints_pong() { + let mut h = Harness::new(); + h.line("ping"); + assert_eq!(h.sent.last().map(String::as_str), Some("PING")); + + h.reply("PONG"); + + assert!(h.screen.lines.iter().any(|line| line == "Pong")); +} + +#[test] +fn send_prints_the_echo() { + let mut h = Harness::new(); + h.line("send hello"); + h.reply("hello"); + + assert!(h + .screen + .lines + .iter() + .any(|line| line == "Echo: hello")); +} + +#[test] +fn disconnect_clears_connection_state() { + let mut h = Harness::new(); + h.line("disconnect"); + + assert!(h + .screen + .lines + .iter() + .any(|line| line == "Disconnected")); + + h.line("play slots"); + assert!(h + .screen + .lines + .iter() + .any(|line| line.contains("Not connected"))); +} -- cgit v1.2.3