From 8f886b3fe47d3057eb210fb740e71dc86d3a5183 Mon Sep 17 00:00:00 2001 From: Jerry Kingsbury Date: Fri, 2 May 2025 17:15:34 -0500 Subject: [PATCH] test(monitor): move container to a nonexistent workspace Created a test for moving a container to a workspace that doesn't exist. The test ensures when a container is moved to a workspace that doesn't exist, the workspace is created and that the workspace contains the container. It also checks that there are N workspaces available where N is the largest workspace number. --- komorebi/src/monitor.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 0a5223f8..ac0efbc7 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -757,6 +757,46 @@ mod tests { assert_eq!(m.focused_workspace().unwrap().containers().len(), 2); } + #[test] + fn test_move_container_to_nonexistent_workspace() { + let mut m = Monitor::new( + 0, + Rect::default(), + Rect::default(), + "TestMonitor".to_string(), + "TestDevice".to_string(), + "TestDeviceID".to_string(), + Some("TestMonitorID".to_string()), + ); + + { + // Create workspace 1 and add 3 containers + let workspace = m.focused_workspace_mut().unwrap(); + for _ in 0..3 { + let container = Container::default(); + workspace.add_container_to_back(container); + } + + // Should have 3 containers in workspace 1 + assert_eq!(m.focused_workspace().unwrap().containers().len(), 3); + } + + // Should only have 1 workspace + assert_eq!(m.workspaces().len(), 1); + + // Try to move a container to a workspace that doesn't exist + m.move_container_to_workspace(8, true, None).unwrap(); + + // Should have 9 workspaces now + assert_eq!(m.workspaces().len(), 9); + + // Should be focused on workspace 8 + assert_eq!(m.focused_workspace_idx(), 8); + + // Should have 1 container in workspace 8 + assert_eq!(m.focused_workspace().unwrap().containers().len(), 1); + } + #[test] fn test_ensure_workspace_count_workspace_contains_two_workspaces() { let mut m = Monitor::new(