From 71bb346c89878e69af41075372646313b737c4f5 Mon Sep 17 00:00:00 2001 From: Jerry Kingsbury Date: Tue, 13 May 2025 17:18:58 -0500 Subject: [PATCH] test(wm): swap workspace with non-existent monitor Created a test for swapping workspaces with a monitor that doesn't exist, which ensures that we receive an error and that none of the workspaces were moved when attempting to swap workspaces with a monitor that doesn't exist. --- komorebi/src/window_manager.rs | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 5768c890..35e39cc3 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -5008,6 +5008,52 @@ mod tests { } } + #[test] + fn test_swap_workspace_with_nonexistent_monitor() { + let (mut wm, _context) = setup_window_manager(); + + { + let mut m = monitor::new( + 0, + Rect::default(), + Rect::default(), + "TestMonitor".to_string(), + "TestDevice".to_string(), + "TestDeviceID".to_string(), + Some("TestMonitorID".to_string()), + ); + + // Add another workspace + let new_workspace_index = m.new_workspace_idx(); + m.focus_workspace(new_workspace_index).unwrap(); + + // Should have 2 workspaces + assert_eq!(m.workspaces().len(), 2); + + // Add monitor to window manager + wm.monitors_mut().push_back(m); + } + + // Should be an error since Monitor 1 does not exist + let result = wm.swap_monitor_workspaces(1, 0); + assert!( + result.is_err(), + "Expected an error when swapping with a non-existent monitor" + ); + + { + // Should still have 2 workspaces in Monitor 0 + let monitor = wm.monitors().front().unwrap(); + let workspaces = monitor.workspaces(); + assert_eq!( + workspaces.len(), + 2, + "Expected 2 workspaces after swap attempt" + ); + assert_eq!(wm.focused_monitor_idx(), 0); + } + } + #[test] fn test_move_workspace_to_monitor() { let (mut wm, _context) = setup_window_manager();