Skip to content

Commit 80bb728

Browse files
SaucePacketsLGUG2Z
authored andcommitted
test(wm): transfer window to nonexistent monitor
Created a test for the transfer_window function. The tests attempts to transfer a window to a monitor that doesn't exist, and checks to see if we return an error. The test successfully gets an error but there is a bug where the window isn't in the contiainer after a failed transfer. I wrote a note comment to explain the bug just in case we need to reference back to it.
1 parent 76c833f commit 80bb728

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

komorebi/src/window_manager.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4471,6 +4471,64 @@ mod tests {
44714471
}
44724472
}
44734473

4474+
#[test]
4475+
fn test_transfer_window_to_nonexistent_monitor() {
4476+
// NOTE: transfer_window is primarily used when a window is being dragged by a mouse. The
4477+
// transfer_window function does return an error when the target monitor doesn't exist but
4478+
// there is a bug where the window isn't in the container after the window fails to
4479+
// transfer. The test will test for the result of the transfer_window function but not if
4480+
// the window is in the container after the transfer fails.
4481+
4482+
let (mut wm, _context) = setup_window_manager();
4483+
4484+
{
4485+
// Create a first monitor
4486+
let mut m = monitor::new(
4487+
0,
4488+
Rect::default(),
4489+
Rect::default(),
4490+
"TestMonitor".to_string(),
4491+
"TestDevice".to_string(),
4492+
"TestDeviceID".to_string(),
4493+
Some("TestMonitorID".to_string()),
4494+
);
4495+
4496+
// Create a container
4497+
let workspace = m.focused_workspace_mut().unwrap();
4498+
let mut container = Container::default();
4499+
4500+
// Add a window to the container
4501+
container.windows_mut().push_back(Window::from(0));
4502+
workspace.add_container_to_back(container);
4503+
4504+
// Should contain 1 container
4505+
assert_eq!(workspace.containers().len(), 1);
4506+
4507+
wm.monitors_mut().push_back(m);
4508+
}
4509+
4510+
{
4511+
// Monitor 0, Workspace 0, Window 0
4512+
let origin = (0, 0, 0);
4513+
4514+
// Monitor 1, Workspace 0, Window 0
4515+
//
4516+
let target = (1, 0, 0);
4517+
4518+
// Attempt to transfer the window from monitor 0 to a non-existent monitor
4519+
let result = wm.transfer_window(origin, target);
4520+
4521+
// Result should be an error since the monitor doesn't exist
4522+
assert!(
4523+
result.is_err(),
4524+
"Expected an error when transferring to a non-existent monitor"
4525+
);
4526+
4527+
assert_eq!(wm.focused_container_idx().unwrap(), 0);
4528+
assert_eq!(wm.focused_workspace_idx().unwrap(), 0);
4529+
}
4530+
}
4531+
44744532
#[test]
44754533
fn test_transfer_container() {
44764534
let (mut wm, _context) = setup_window_manager();

0 commit comments

Comments
 (0)