From 74c433185abc91ebd5c190d16f06b9a050ba584e Mon Sep 17 00:00:00 2001 From: Jerry Kingsbury Date: Tue, 13 May 2025 17:37:57 -0500 Subject: [PATCH] test(wm): switch focus to non-existent monitor Created a test for focusing on a monitor that doesn't exist, which ensures that we receive an error and that we are still focused on the current monitor when attempting to focus a non-existent monitor. --- komorebi/src/window_manager.rs | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 35e39cc3..8b0e7309 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -4292,6 +4292,44 @@ mod tests { assert_eq!(current_monitor_idx, 0); } + #[test] + fn test_switch_focus_to_nonexistent_monitor() { + let (mut wm, _test_context) = setup_window_manager(); + + { + // Create a first monitor + let m = monitor::new( + 0, + Rect::default(), + Rect::default(), + "TestMonitor".to_string(), + "TestDevice".to_string(), + "TestDeviceID".to_string(), + Some("TestMonitorID".to_string()), + ); + + // monitor should have a single workspace + assert_eq!(m.workspaces().len(), 1); + + // add the monitor to the window manager + wm.monitors_mut().push_back(m); + } + + // Should have 1 monitor and the monitor index should be 0 + assert_eq!(wm.monitors().len(), 1); + assert_eq!(wm.focused_monitor_idx(), 0); + + // Should receive an error when trying to focus a non-existent monitor + let result = wm.focus_monitor(1); + assert!( + result.is_err(), + "Expected an error when focusing a non-existent monitor" + ); + + // Should still be focused on the first monitor + assert_eq!(wm.focused_monitor_idx(), 0); + } + #[test] fn test_focused_monitor_size() { let (mut wm, _test_context) = setup_window_manager();