Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Lib/v2/WindowManager.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ MakeFullscreen(winTitle) {
MaximizeWindow(winTitle)
}

WaitForWindow(winTitle, timeout := 30) {
try {
WinWait(winTitle, , timeout)
return true
} catch TimeoutError {
return false
}
WaitForWindow(winTitle, timeout := 30, api := "") {
if !api
api := SystemWindowAPI()

return api.WinWait(winTitle, , timeout) != 0
Comment on lines +36 to +40
}

WaitForProcess(processName, timeout := 30) {
Expand Down Expand Up @@ -93,6 +91,7 @@ RestoreWindowBorders(winTitle) {
}

class SystemWindowAPI {
WinWait(winTitle, winText?, timeout?) => WinWait(winTitle, winText?, timeout?)
WinGetStyle(winTitle) => WinGetStyle(winTitle)
WinSetStyle(style, winTitle) => WinSetStyle(style, winTitle)
WinMove(x, y, w, h, winTitle) => WinMove(x, y, w, h, winTitle)
Expand Down
43 changes: 43 additions & 0 deletions ahk/test_WindowManager.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class MockWindowAPI {
this.monitors := []
}

WinWait(winTitle, winText:="", timeout:="") {
this.calls.Push({method: "WinWait", args: [winTitle, winText, timeout]})
return 0 ; Simulate timeout
}

WinGetStyle(winTitle) {
this.calls.Push({method: "WinGetStyle", args: [winTitle]})
return this.mockStyle
Expand Down Expand Up @@ -149,12 +154,50 @@ TestGetMonitorAtPos_MultipleMonitors() {
return true
}


TestWaitForWindow_Timeout() {
mockApi := MockWindowAPI()

res := WaitForWindow("FakeWindow", 0.1, mockApi)

; Verify result
if (res != false) {
FileOpen("*", "w `n").Write("Fail: Expected false, got " res "`n")
return false
}

; Verify calls
if (mockApi.calls.Length != 1) {
FileOpen("*", "w `n").Write("Fail: Expected 1 call, got " mockApi.calls.Length "`n")
return false
}

if (mockApi.calls[1].method != "WinWait") {
FileOpen("*", "w `n").Write("Fail: First call was not WinWait`n")
return false
}

if (mockApi.calls[1].args[1] != "FakeWindow") {
FileOpen("*", "w `n").Write("Fail: Expected winTitle 'FakeWindow', got '" mockApi.calls[1].args[1] "'`n")
return false
}

if (mockApi.calls[1].args[3] != 0.1) {
FileOpen("*", "w `n").Write("Fail: Expected timeout 0.1, got '" mockApi.calls[1].args[3] "'`n")
return false
}

FileOpen("*", "w `n").Write("Pass: WaitForWindow_Timeout`n")
return true
}

TestToggleFakeFullscreen_MakeFullscreen()
TestToggleFakeFullscreen_RestoreWindow()

TestGetMonitorAtPos_InsideMonitor()
TestGetMonitorAtPos_OutsideMonitors()
TestGetMonitorAtPos_MultipleMonitors()
TestWaitForWindow_Timeout()
Comment on lines 194 to +200
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test runner in this script does not verify the return values of the test functions. If a test fails (returns false), the script will still proceed to print "All tests complete." and exit with a success code (0). This makes the tests ineffective for CI environments where a non-zero exit code is required to signal failure. Since this PR adds a new test, it's a good opportunity to ensure failures are correctly propagated.

if !TestToggleFakeFullscreen_MakeFullscreen()
    ExitApp(1)
if !TestToggleFakeFullscreen_RestoreWindow()
    ExitApp(1)

if !TestGetMonitorAtPos_InsideMonitor()
    ExitApp(1)
if !TestGetMonitorAtPos_OutsideMonitors()
    ExitApp(1)
if !TestGetMonitorAtPos_MultipleMonitors()
    ExitApp(1)
if !TestWaitForWindow_Timeout()
    ExitApp(1)


FileOpen("*", "w `n").Write("All tests complete.`n")
ExitApp
Comment on lines 194 to 203
Loading