diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index a838848c..c58df0fe 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -5263,4 +5263,75 @@ mod tests { assert_eq!(*maximized_window, None); } } + + #[test] + fn test_monocle_on_and_monocle_off() { + let (mut wm, _context) = setup_window_manager(); + + { + // Create a monitor + let mut m = monitor::new( + 0, + Rect::default(), + Rect::default(), + "TestMonitor".to_string(), + "TestDevice".to_string(), + "TestDeviceID".to_string(), + Some("TestMonitorID".to_string()), + ); + + // Create a container + let mut container = Container::default(); + + // Add a window to the container + container.windows_mut().push_back(Window::from(1)); + + // Should have 1 window in the container + assert_eq!(container.windows().len(), 1); + + // Add the container to the workspace + let workspace = m.focused_workspace_mut().unwrap(); + workspace.add_container_to_back(container); + + // Add monitor to the window manager + wm.monitors_mut().push_back(m); + } + + // Move container to monocle container + wm.monocle_on().ok(); + + { + // Container should be a monocle container + let monocle_container = wm + .focused_workspace() + .unwrap() + .monocle_container() + .as_ref() + .unwrap(); + assert_eq!(monocle_container.windows().len(), 1); + assert_eq!(monocle_container.windows()[0].hwnd, 1); + } + + { + // Should not have any containers + let container = wm.focused_workspace().unwrap(); + assert_eq!(container.containers().len(), 0); + } + + // Move monocle container to regular container + wm.monocle_off().ok(); + + { + // Should have 1 container in the workspace + let container = wm.focused_workspace().unwrap(); + assert_eq!(container.containers().len(), 1); + assert_eq!(container.containers()[0].windows()[0].hwnd, 1); + } + + { + // No windows should be in the monocle container + let monocle_container = wm.focused_workspace().unwrap().monocle_container(); + assert_eq!(*monocle_container, None); + } + } }