From 1bf53b89af318a9978152200b7f114a53da30524 Mon Sep 17 00:00:00 2001 From: Jerry Kingsbury Date: Wed, 16 Apr 2025 19:21:49 -0500 Subject: [PATCH] test(wm): ensure named workspace for monitor test Created a test for the ensure_named_workspace_for_monitor function. The test creates two monitors and holds a list of workspace names. When calling the ensure_named_workspace_for_monitor_function the test checks to ensure that the the the monitor contains the length of the list workspaces and that the workspaces uses the name in the list. The test adds more names to the list and repeats the check on the other monitor. --- komorebi/src/window_manager.rs | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 3c9faeb7..116f9a17 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -5461,4 +5461,77 @@ mod tests { assert_eq!(*monocle_container, None); } } + + #[test] + fn test_ensure_named_workspace_for_monitor() { + let (mut wm, _context) = setup_window_manager(); + + { + // Create a monitor + let m = monitor::new( + 0, + Rect::default(), + Rect::default(), + "TestMonitor".to_string(), + "TestDevice".to_string(), + "TestDeviceID".to_string(), + Some("TestMonitorID".to_string()), + ); + + // Add the monitor to the window manager + wm.monitors_mut().push_back(m); + } + + { + // Create a monitor + let m = monitor::new( + 1, + Rect::default(), + Rect::default(), + "TestMonitor1".to_string(), + "TestDevice1".to_string(), + "TestDeviceID1".to_string(), + Some("TestMonitorID1".to_string()), + ); + + // Add the monitor to the window manager + wm.monitors_mut().push_back(m); + } + + // Workspace names list + let mut workspace_names = vec!["Workspace".to_string(), "Workspace1".to_string()]; + + // Ensure workspaces for monitor 1 + wm.ensure_named_workspaces_for_monitor(1, &workspace_names) + .ok(); + + { + // Monitor 1 should have 2 workspaces with names "Workspace" and "Workspace1" + let monitor = wm.monitors().get(1).unwrap(); + let workspaces = monitor.workspaces(); + assert_eq!(workspaces.len(), workspace_names.len()); + for (i, workspace) in workspaces.iter().enumerate() { + assert_eq!(workspace.name(), &Some(workspace_names[i].clone())); + } + } + + // Add more workspaces to list + workspace_names.push("Workspace2".to_string()); + workspace_names.push("Workspace3".to_string()); + + // Ensure workspaces for monitor 0 + wm.ensure_named_workspaces_for_monitor(0, &workspace_names) + .ok(); + + { + // Monitor 0 should have 4 workspaces with names "Workspace", "Workspace1", + // "Workspace2" and "Workspace3" + let monitor = wm.monitors().front().unwrap(); + let workspaces = monitor.workspaces(); + assert_eq!(workspaces.len(), workspace_names.len()); + for (i, workspace) in workspaces.iter().enumerate() { + assert_eq!(workspace.name(), &Some(workspace_names[i].clone())); + } + } + } }