diff --git a/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py b/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py new file mode 100644 index 00000000..ed1318d0 --- /dev/null +++ b/nix/tests/vm/lib/komorebi_vm/core/scenarios/resize_commands.py @@ -0,0 +1,43 @@ +"""The resize commands move an edge of the focused window, with no pointer.""" + +from komorebi_vm.core.checks import Checks +from komorebi_vm.core.platform import Client, Platform +from komorebi_vm.core.scenarios.support import focus_agrees + +# how much wider the window must get for the command to have done something +MIN_STEP = 10 + + +def run(platform: Platform, checks: Checks, clients: list[Client]) -> None: + """Resizes the first of `clients`, which are tiled windows of the first workspace, with + `resize-axis horizontal increase` and `decrease`.""" + target = clients[0] + platform.activate(target) + platform.wait_for(lambda: focus_agrees(platform, clients, target.title)) + + def width() -> int: + window = platform.os_window(target) + return window.frame.w if window is not None else 0 + + def clear() -> bool: + frames = [w.frame for c in clients if (w := platform.os_window(c)) is not None] + area = platform.work_area() + return all(f.inside(area) for f in frames) and not any( + a.overlaps(b) for i, a in enumerate(frames) for b in frames[i + 1 :] + ) + + before = width() + platform.komorebic("resize-axis", "horizontal", "increase") + checks.check( + f"after 'resize-axis horizontal increase' {target.title} is wider", + platform.wait_for(lambda: width() >= before + MIN_STEP, timeout=20), + ) + print(f" width {before} -> {width()}") + checks.check("... and every window is inside the work area, none over another", clear()) + + platform.komorebic("resize-axis", "horizontal", "decrease") + checks.check( + "after 'decrease' it has the width it had", + platform.wait_for(lambda: abs(width() - before) <= platform.tolerance, timeout=20), + ) + checks.check("... and every window is inside the work area, none over another", clear()) diff --git a/nix/tests/vm/lib/tests/fake_platform.py b/nix/tests/vm/lib/tests/fake_platform.py index 2f8a3b82..273da51f 100644 --- a/nix/tests/vm/lib/tests/fake_platform.py +++ b/nix/tests/vm/lib/tests/fake_platform.py @@ -403,6 +403,13 @@ class FakePlatform: self._relayout() case ("toggle-maximize",): self.maximized = None if self.maximized else self.containers[self.focus][0] + case ("resize-axis", "horizontal", way): + d = 50 if way == "increase" else -50 + i = self.focus + if n > 1 and i < n - 1: + a, b = self.tiles[i], self.tiles[i + 1] + self.tiles[i] = Rect(a.x, a.y, a.w + d, a.h) + self.tiles[i + 1] = Rect(b.x + d, b.y, b.w - d, b.h) case ("toggle-float",): if self.floats: self.containers.insert(self.focus, [self.floats.pop()]) diff --git a/nix/tests/vm/lib/tests/test_focus_moving.py b/nix/tests/vm/lib/tests/test_focus_moving.py index 9041f187..f5724ceb 100644 --- a/nix/tests/vm/lib/tests/test_focus_moving.py +++ b/nix/tests/vm/lib/tests/test_focus_moving.py @@ -18,6 +18,7 @@ from komorebi_vm.core.scenarios import ( padding, placement, resize, + resize_commands, rules, stacks, startup_rules, @@ -273,6 +274,27 @@ def test_a_daemon_that_does_not_follow_the_window_fails_workspace_moves() -> Non assert checks.failed > 0 +def test_a_daemon_that_is_right_passes_resize_commands() -> None: + platform = FakePlatform() + checks = Checks() + clients = opened(platform, checks) + resize_commands.run(platform, checks, clients) + assert checks.failed == 0, checks.failures + assert checks.passed > 3 + + +def test_a_daemon_that_does_not_resize_fails_resize_commands() -> None: + class Stubborn(FakePlatform): + def komorebic(self, *args: str) -> str: + return "" if args[0] == "resize-axis" else super().komorebic(*args) + + platform = Stubborn() + checks = Checks() + clients = opened(platform, checks) + resize_commands.run(platform, checks, clients) + assert checks.failed > 0 + + def test_a_command_the_port_lacks_is_skipped_by_name() -> None: platform = FakePlatform() checks = Checks() diff --git a/nix/tests/vm/suites/core-e2e/test.py b/nix/tests/vm/suites/core-e2e/test.py index 6bb774bf..66ac33e9 100644 --- a/nix/tests/vm/suites/core-e2e/test.py +++ b/nix/tests/vm/suites/core-e2e/test.py @@ -27,6 +27,7 @@ from komorebi_vm.core.scenarios import ( moving, padding, placement, + resize_commands, rules, stacks, startup_rules, @@ -458,6 +459,7 @@ layouts.run(platform, checks, neutral) floating.run(platform, checks, neutral) minimizing.run(platform, checks, neutral) maximizing.run(platform, checks, neutral) +resize_commands.run(platform, checks, neutral) padding.run(platform, checks, neutral) monocle.run(platform, checks, neutral) workspace_moves.run(platform, checks, neutral)