From 1ba1c57ba0fa232fceb92464d67ed14b0db455f9 Mon Sep 17 00:00:00 2001 From: Jerry Kingsbury Date: Sun, 16 Mar 2025 19:11:16 -0500 Subject: [PATCH] test(wm): add cycle window tests Added a test for the cycle_window_in_direction function. The function is tested by creating 3 windows and cycling in both the next a previous direction. The test will ensure that the windows were cycled by checking the window index to ensure it is the expected window. Created a test for cycling the window by index. This test is similar to the other cycle window test and performs the same steps as that one, except it uses the test_cycle_container_index_in_direction function instead. --- komorebi/src/window_manager.rs | 141 +++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index fd353800..f42eaca3 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -4312,6 +4312,147 @@ mod tests { } } + #[test] + fn cycle_container_window_in_direction() { + 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()), + ); + + let workspace = m.focused_workspace_mut().unwrap(); + + { + let mut container = Container::default(); + + for i in 0..3 { + container.windows_mut().push_back(Window::from(i)); + } + + // Should have 3 windows in the container + assert_eq!(container.windows().len(), 3); + + // Add container to workspace + workspace.add_container_to_back(container); + } + + // Add monitor to the window manager + wm.monitors_mut().push_back(m); + } + + // Cycle to the next window + wm.cycle_container_window_in_direction(CycleDirection::Next) + .ok(); + + { + // Should be on Window 1 + let workspace = wm.focused_workspace_mut().unwrap(); + let container = workspace.focused_container_mut().unwrap(); + println!("Window: {:?}", container.focused_window()); + assert_eq!(container.focused_window_idx(), 1); + } + + // Cycle to the next window + wm.cycle_container_window_in_direction(CycleDirection::Next) + .ok(); + + { + // Should be on Window 2 + let workspace = wm.focused_workspace_mut().unwrap(); + let container = workspace.focused_container_mut().unwrap(); + println!("Window: {:?}", container.focused_window()); + assert_eq!(container.focused_window_idx(), 2); + } + + // Cycle to the previous window + wm.cycle_container_window_in_direction(CycleDirection::Previous) + .ok(); + + { + // Should be on Window 1 + let workspace = wm.focused_workspace_mut().unwrap(); + let container = workspace.focused_container_mut().unwrap(); + println!("Window: {:?}", container.focused_window()); + assert_eq!(container.focused_window_idx(), 1); + } + } + + #[test] + fn test_cycle_container_window_index_in_direction() { + 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()), + ); + + let workspace = m.focused_workspace_mut().unwrap(); + + { + let mut container = Container::default(); + + for i in 0..3 { + container.windows_mut().push_back(Window::from(i)); + } + + // Should have 3 windows in the container + assert_eq!(container.windows().len(), 3); + + // Add container to workspace + workspace.add_container_to_back(container); + } + + // Add monitor to the window manager + wm.monitors_mut().push_back(m); + } + + // Cycle to the next window + wm.cycle_container_window_index_in_direction(CycleDirection::Next) + .ok(); + + { + // Should be on Window 1 + let workspace = wm.focused_workspace_mut().unwrap(); + let container = workspace.focused_container_mut().unwrap(); + assert_eq!(container.focused_window_idx(), 1); + } + + // Cycle to the next window + wm.cycle_container_window_index_in_direction(CycleDirection::Next) + .ok(); + + { + // Should be on Window 2 + let workspace = wm.focused_workspace_mut().unwrap(); + let container = workspace.focused_container_mut().unwrap(); + assert_eq!(container.focused_window_idx(), 2); + } + + // Cycle to the Previous window + wm.cycle_container_window_index_in_direction(CycleDirection::Previous) + .ok(); + + { + // Should be on Window 1 + let workspace = wm.focused_workspace_mut().unwrap(); + let container = workspace.focused_container_mut().unwrap(); + assert_eq!(container.focused_window_idx(), 1); + } + } + #[test] fn test_swap_containers() { let (mut wm, _context) = setup_window_manager();