mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-03 01:14:14 +02:00
test(workspace): add more workspace tests
Added tests for the focus_container_by_window and contains_managed_window functions. test_focus_container_by_window crates two containers with different distinct windows. The test checks to see if we are focused on the expected container and window. test_contains_managed_window creates two containers and checks to ensure that when calling the function returns the expected result when checking if a window is available in one of the containers. Added a test for adding a new floating window. The test creates a container with three windows and attempts to add one of the windows to the list of floating windows, then checks to see if the first window in the container was added to the floating window list and also checks the list of windows and floating windows to ensure we get the expected result.
This commit is contained in:
@@ -2262,4 +2262,99 @@ mod tests {
|
||||
assert!(workspace.contains_window(0));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_focus_container_by_window() {
|
||||
let mut workspace = Workspace::default();
|
||||
|
||||
{
|
||||
// Container with 3 windows
|
||||
let mut container = Container::default();
|
||||
for i in 0..3 {
|
||||
container.windows_mut().push_back(Window::from(i));
|
||||
}
|
||||
workspace.add_container_to_back(container);
|
||||
}
|
||||
|
||||
{
|
||||
// Container with 1 window
|
||||
let mut container = Container::default();
|
||||
container.windows_mut().push_back(Window::from(4));
|
||||
workspace.add_container_to_back(container);
|
||||
}
|
||||
|
||||
// Focus container by window
|
||||
workspace.focus_container_by_window(1).unwrap();
|
||||
|
||||
// Should be focused on workspace 0
|
||||
assert_eq!(workspace.focused_container_idx(), 0);
|
||||
|
||||
// Should be focused on window 1 and hwnd should be 1
|
||||
let focused_container = workspace.focused_container_mut().unwrap();
|
||||
assert_eq!(
|
||||
focused_container.focused_window(),
|
||||
Some(&Window { hwnd: 1 })
|
||||
);
|
||||
assert_eq!(focused_container.focused_window_idx(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains_managed_window() {
|
||||
let mut workspace = Workspace::default();
|
||||
|
||||
{
|
||||
// Container with 3 windows
|
||||
let mut container = Container::default();
|
||||
for i in 0..3 {
|
||||
container.windows_mut().push_back(Window::from(i));
|
||||
}
|
||||
workspace.add_container_to_back(container);
|
||||
}
|
||||
|
||||
{
|
||||
// Container with 1 window
|
||||
let mut container = Container::default();
|
||||
container.windows_mut().push_back(Window::from(4));
|
||||
workspace.add_container_to_back(container);
|
||||
}
|
||||
|
||||
// Should return true, window is in container 1
|
||||
assert!(workspace.contains_managed_window(4));
|
||||
|
||||
// Should return true, all the windows are in container 0
|
||||
for i in 0..3 {
|
||||
assert!(workspace.contains_managed_window(i));
|
||||
}
|
||||
|
||||
// Should return false since window was never added
|
||||
assert!(!workspace.contains_managed_window(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_floating_window() {
|
||||
let mut workspace = Workspace::default();
|
||||
|
||||
{
|
||||
// Container with 3 windows
|
||||
let mut container = Container::default();
|
||||
for i in 0..3 {
|
||||
container.windows_mut().push_back(Window::from(i));
|
||||
}
|
||||
workspace.add_container_to_back(container);
|
||||
}
|
||||
|
||||
// Add window to floating_windows
|
||||
workspace.new_floating_window().ok();
|
||||
|
||||
// Should have 1 floating window
|
||||
assert_eq!(workspace.floating_windows().len(), 1);
|
||||
|
||||
// Should have only 2 windows now
|
||||
let container = workspace.focused_container_mut().unwrap();
|
||||
assert_eq!(container.windows().len(), 2);
|
||||
|
||||
// Should contain hwnd 0 since this is the first window in the container
|
||||
let floating_windows = workspace.floating_windows_mut();
|
||||
assert!(floating_windows.contains(&Window { hwnd: 0 }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user