diff --git a/src/ui/draw_blocks/mod.rs b/src/ui/draw_blocks/mod.rs index 17d6aad..ec06c61 100644 --- a/src/ui/draw_blocks/mod.rs +++ b/src/ui/draw_blocks/mod.rs @@ -127,8 +127,9 @@ pub mod tests { use crate::{ app_data::{AppData, ContainerId, ContainerImage, ContainerName, ContainerPorts}, + app_error::AppError, tests::{gen_appdata, gen_containers}, - ui::{GuiState, Rerender, draw_frame}, + ui::{GuiState, Rerender, Status, draw_frame}, }; use super::FrameData; @@ -422,4 +423,128 @@ pub mod tests { assert_snapshot!(setup.terminal.backend()); } + + #[test] + /// Check that the whole layout is drawn with the help panel visible + fn test_draw_blocks_whole_layout_help_panel() { + let mut setup = test_setup(160, 40, true, true); + + insert_chart_data(&setup); + insert_logs(&setup); + setup.app_data.lock().containers.items[0] + .ports + .push(ContainerPorts { + ip: Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))), + private: 8003, + public: Some(8003), + }); + let colors = setup.app_data.lock().config.app_colors; + let keymap = setup.app_data.lock().config.keymap.clone(); + + setup.gui_state.lock().status_push(Status::Help); + + let fd = FrameData::from((&setup.app_data, &setup.gui_state)); + setup + .terminal + .draw(|f| { + draw_frame(&setup.app_data, colors, &keymap, f, &fd, &setup.gui_state); + }) + .unwrap(); + + assert_snapshot!(setup.terminal.backend()); + } + + #[test] + /// Check that the whole layout is drawn with the error box is visible + fn test_draw_blocks_whole_layout_error() { + let mut setup = test_setup(160, 40, true, true); + + insert_chart_data(&setup); + insert_logs(&setup); + setup.app_data.lock().containers.items[0] + .ports + .push(ContainerPorts { + ip: Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))), + private: 8003, + public: Some(8003), + }); + let colors = setup.app_data.lock().config.app_colors; + let keymap = setup.app_data.lock().config.keymap.clone(); + + setup.app_data.lock().set_error( + AppError::DockerCommand(crate::app_data::DockerCommand::Pause), + &setup.gui_state, + Status::Error, + ); + + let fd = FrameData::from((&setup.app_data, &setup.gui_state)); + setup + .terminal + .draw(|f| { + draw_frame(&setup.app_data, colors, &keymap, f, &fd, &setup.gui_state); + }) + .unwrap(); + + assert_snapshot!(setup.terminal.backend()); + } + + #[test] + /// Check that the whole layout is drawn with the delete box is visible + fn test_draw_blocks_whole_layout_delete() { + let mut setup = test_setup(160, 40, true, true); + + insert_chart_data(&setup); + insert_logs(&setup); + setup.app_data.lock().containers.items[0] + .ports + .push(ContainerPorts { + ip: Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))), + private: 8003, + public: Some(8003), + }); + let colors = setup.app_data.lock().config.app_colors; + let keymap = setup.app_data.lock().config.keymap.clone(); + setup + .gui_state + .lock() + .set_delete_container(setup.app_data.lock().get_selected_container_id()); + + let fd = FrameData::from((&setup.app_data, &setup.gui_state)); + setup + .terminal + .draw(|f| { + draw_frame(&setup.app_data, colors, &keymap, f, &fd, &setup.gui_state); + }) + .unwrap(); + + assert_snapshot!(setup.terminal.backend()); + } + + #[test] + /// Check that the whole layout is drawn with the info box is visible + fn test_draw_blocks_whole_layout_info_box() { + let mut setup = test_setup(160, 40, true, true); + + insert_chart_data(&setup); + insert_logs(&setup); + setup.app_data.lock().containers.items[0] + .ports + .push(ContainerPorts { + ip: Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))), + private: 8003, + public: Some(8003), + }); + let colors = setup.app_data.lock().config.app_colors; + let keymap = setup.app_data.lock().config.keymap.clone(); + setup.gui_state.lock().set_info_box("This is a test"); + let fd = FrameData::from((&setup.app_data, &setup.gui_state)); + setup + .terminal + .draw(|f| { + draw_frame(&setup.app_data, colors, &keymap, f, &fd, &setup.gui_state); + }) + .unwrap(); + + assert_snapshot!(setup.terminal.backend()); + } } diff --git a/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_delete.snap b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_delete.snap new file mode 100644 index 0000000..37af4fd --- /dev/null +++ b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_delete.snap @@ -0,0 +1,44 @@ +--- +source: src/ui/draw_blocks/mod.rs +expression: setup.terminal.backend() +--- +" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help " +"╭ Containers 1/3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭──────────────╮" +"│⚪ container_1 ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 image_1 0.00 kB 0.00 kB ││▶ pause │" Hidden by multi-width symbols: [(2, " ")] +"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │" +"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │" +"│ ││ delete │" +"│ ││ │" +"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯╰──────────────╯" +"╭ Logs 3/3 - container_1 - image_1 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮" +"│ line 1 │" +"│ line 2 │" +"│▶ line 3 │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ ╭──────────────────────── Confirm Delete ────────────────────────╮ │" +"│ │ │ │" +"│ │ Are you sure you want to delete container: container_1 │ │" +"│ │ │ │" +"│ │ ╭─────────────────────╮ ╭─────────────────────╮ │ │" +"│ │ │ ( n ) no │ │ ( y ) yes │ │ │" +"│ │ ╰─────────────────────╯ ╰─────────────────────╯ │ │" +"│ ╰────────────────────────────────────────────────────────────────╯ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +"╭───────────────────────── cpu 03.00% ──────────────────────────╮╭─────────────────────── memory 30.00 kB ───────────────────────╮╭────────── ports ───────────╮" +"│10.00%│ •• ││100.00 kB│ •• ││ ip private public│" +"│ │ • • ││ │ •• ││ 8001 │" +"│ │ •• • ││ │ •• • ││127.0.0.1 8003 8003│" +"│ │ • • ││ │ • • ││ │" +"│ │ •• • • ││ │ •• • • ││ │" +"│ │• •• ││ │• •• ││ │" +"│ │• • ││ │• • ││ │" +"│ │ ││ │ ││ │" +"╰───────────────────────────────────────────────────────────────╯╰───────────────────────────────────────────────────────────────╯╰────────────────────────────╯" diff --git a/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_error.snap b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_error.snap new file mode 100644 index 0000000..49919e8 --- /dev/null +++ b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_error.snap @@ -0,0 +1,44 @@ +--- +source: src/ui/draw_blocks/mod.rs +expression: setup.terminal.backend() +--- +" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help " +"╭ Containers 1/3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭──────────────╮" +"│⚪ container_1 ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 image_1 0.00 kB 0.00 kB ││▶ pause │" Hidden by multi-width symbols: [(2, " ")] +"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │" +"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │" +"│ ││ delete │" +"│ ││ │" +"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯╰──────────────╯" +"╭ Logs 3/3 - container_1 - image_1 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮" +"│ line 1 │" +"│ line 2 │" +"│▶ line 3 │" +"│ │" +"│ │" +"│ │" +"│ ╭──────────── Error ─────────────╮ │" +"│ │ │ │" +"│ │ Unable to pause container │ │" +"│ │ │ │" +"│ │ ( c ) clear error │ │" +"│ │ │ │" +"│ │ ( q ) quit oxker │ │" +"│ │ │ │" +"│ │ │ │" +"│ ╰────────────────────────────────╯ │" +"│ │" +"│ │" +"│ │" +"│ │" +"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +"╭───────────────────────── cpu 03.00% ──────────────────────────╮╭─────────────────────── memory 30.00 kB ───────────────────────╮╭────────── ports ───────────╮" +"│10.00%│ •• ││100.00 kB│ •• ││ ip private public│" +"│ │ • • ││ │ •• ││ 8001 │" +"│ │ •• • ││ │ •• • ││127.0.0.1 8003 8003│" +"│ │ • • ││ │ • • ││ │" +"│ │ •• • • ││ │ •• • • ││ │" +"│ │• •• ││ │• •• ││ │" +"│ │• • ││ │• • ││ │" +"│ │ ││ │ ││ │" +"╰───────────────────────────────────────────────────────────────╯╰───────────────────────────────────────────────────────────────╯╰────────────────────────────╯" diff --git a/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_help_panel.snap b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_help_panel.snap new file mode 100644 index 0000000..ed89388 --- /dev/null +++ b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_help_panel.snap @@ -0,0 +1,44 @@ +--- +source: src/ui/draw_blocks/mod.rs +expression: setup.terminal.backend() +--- +" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) exit help " +"╭ Containers 1/3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭──────────────╮" +"│⚪ container_1 ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 image_1 0.00 kB 0.00 kB ││▶ pause │" Hidden by multi-width symbols: [(2, " ")] +"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │" +"│ container_3 ✓ running Up 3 ho╭ 0.00.000 ──────────────────────────────────────────────────────────────────────────╮ ││ stop │" +"│ │ │ ││ delete │" +"│ │ 88 │ ││ │" +"╰────────────────────────────────────│ 88 │────────────────────╯╰──────────────╯" +"╭ Logs 3/3 - container_1 - image_1 ──│ 88 │────────────────────────────────────╮" +"│ line 1 │ ,adPPYba, 8b, ,d8 88 ,d8 ,adPPYba, 8b,dPPYba, │ │" +"│ line 2 │ a8" "8a `Y8, ,8P' 88 ,a8" a8P_____88 88P' "Y8 │ │" +"│▶ line 3 │ 8b d8 )888( 8888[ 8PP""""""" 88 │ │" +"│ │ "8a, ,a8" ,d8" "8b, 88`"Yba, "8b, ,aa 88 │ │" +"│ │ `"YbbdP"' 8P' `Y8 88 `Y8a `"Ybbd8"' 88 │ │" +"│ │ │ │" +"│ │ A simple tui to view & control docker containers │ │" +"│ │ │ │" +"│ │ ( tab ) or ( shift+tab ) change panels │ │" +"│ │ ( ↑ ↓ ) or ( j k ) or ( PgUp PgDown ) or ( Home End ) change selected line │ │" +"│ │ ( enter ) send docker container command │ │" +"│ │ ( e ) exec into a container │ │" +"│ │ ( h ) toggle this help information - or click heading │ │" +"│ │ ( s ) save logs to file │ │" +"│ │ ( m ) toggle mouse capture - if disabled, text on screen can be selected & copied │ │" +"│ │ ( F1 ) or ( / ) enter filter mode │ │" +"│ │ ( 0 ) stop sort │ │" +"│ │ ( 1 - 9 ) sort by header - or click header │ │" +"│ │ ( - = ) change log section height │ │" +"│ │ ( \ ) toggle log section visibility │ │" +"╰────────────────────────────────────│ ( esc ) close dialog │────────────────────────────────────╯" +"╭───────────────────────── cpu 03.00%│ ( q ) quit at any time │──────╮╭────────── ports ───────────╮" +"│10.00%│ •• │ │ ││ ip private public│" +"│ │ • • │ currently an early work in progress, all and any input appreciated │ ││ 8001 │" +"│ │ •• • │ https://github.com/mrjackwills/oxker │ ││127.0.0.1 8003 8003│" +"│ │ • • │ │ ││ │" +"│ │ •• • • ╰────────────────────────────────────────────────────────────────────────────────────╯ ││ │" +"│ │• •• ││ │• •• ││ │" +"│ │• • ││ │• • ││ │" +"│ │ ││ │ ││ │" +"╰───────────────────────────────────────────────────────────────╯╰───────────────────────────────────────────────────────────────╯╰────────────────────────────╯" diff --git a/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_info_box.snap b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_info_box.snap new file mode 100644 index 0000000..a9abbf8 --- /dev/null +++ b/src/ui/draw_blocks/snapshots/oxker__ui__draw_blocks__tests__draw_blocks_whole_layout_info_box.snap @@ -0,0 +1,44 @@ +--- +source: src/ui/draw_blocks/mod.rs +expression: setup.terminal.backend() +--- +" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help " +"╭ Containers 1/3 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮╭──────────────╮" +"│⚪ container_1 ✓ running Up 1 hour 03.00% 30.00 kB / 30.00 kB 1 image_1 0.00 kB 0.00 kB ││▶ pause │" Hidden by multi-width symbols: [(2, " ")] +"│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB ││ restart │" +"│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB ││ stop │" +"│ ││ delete │" +"│ ││ │" +"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯╰──────────────╯" +"╭ Logs 3/3 - container_1 - image_1 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮" +"│ line 1 │" +"│ line 2 │" +"│▶ line 3 │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"│ │" +"╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" +"╭───────────────────────── cpu 03.00% ──────────────────────────╮╭─────────────────────── memory 30.00 kB ───────────────────────╮╭────────── ports ───────────╮" +"│10.00%│ •• ││100.00 kB│ •• ││ ip private public│" +"│ │ • • ││ │ •• ││ 8001 │" +"│ │ •• • ││ │ •• • ││127.0.0.1 8003 8003│" +"│ │ • • ││ │ • • ││ │" +"│ │ •• • • ││ │ •• • • ││ │" +"│ │• •• ││ │• •• ││ " +"│ │• • ││ │• • ││ This is a test " +"│ │ ││ │ ││ " +"╰───────────────────────────────────────────────────────────────╯╰───────────────────────────────────────────────────────────────╯╰─────── "