From 5be6eaaad5562fe7e6c1d179a58d4017073e12db Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 31 May 2026 14:34:40 +0530 Subject: [PATCH] test(mock): add FocusedWindowApp with foreground mirroring --- internal/driver/mock/mock.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/internal/driver/mock/mock.go b/internal/driver/mock/mock.go index 5751c89..bafca5a 100644 --- a/internal/driver/mock/mock.go +++ b/internal/driver/mock/mock.go @@ -61,6 +61,15 @@ type Driver struct { // app-scope guard so tests that don't care are unaffected. ForegroundResults []string foregroundIndex int + + // FocusedWindowResults is consumed one entry per FocusedWindowApp call + // (the last entry repeats). When empty, FocusedWindowApp mirrors the + // last ForegroundApp result, so the startup gate treats the window as + // already drawn and tests that don't care are unaffected. + FocusedWindowResults []string + focusedWindowIndex int + focusedWindowCalls int + lastForeground string } func New() *Driver { @@ -106,6 +115,7 @@ func (d *Driver) ForegroundApp(_ context.Context) (string, error) { d.mutex.Lock() defer d.mutex.Unlock() if len(d.ForegroundResults) == 0 { + d.lastForeground = "" return "", nil } index := d.foregroundIndex @@ -113,7 +123,30 @@ func (d *Driver) ForegroundApp(_ context.Context) (string, error) { index = len(d.ForegroundResults) - 1 } d.foregroundIndex++ - return d.ForegroundResults[index], nil + d.lastForeground = d.ForegroundResults[index] + return d.lastForeground, nil +} + +func (d *Driver) FocusedWindowApp(_ context.Context) (string, error) { + d.mutex.Lock() + defer d.mutex.Unlock() + d.focusedWindowCalls++ + if len(d.FocusedWindowResults) == 0 { + return d.lastForeground, nil + } + index := d.focusedWindowIndex + if index >= len(d.FocusedWindowResults) { + index = len(d.FocusedWindowResults) - 1 + } + d.focusedWindowIndex++ + return d.FocusedWindowResults[index], nil +} + +// FocusedWindowCalls reports how many times FocusedWindowApp has been called. +func (d *Driver) FocusedWindowCalls() int { + d.mutex.Lock() + defer d.mutex.Unlock() + return d.focusedWindowCalls } func (d *Driver) Terminate(ctx context.Context) error {