Skip to content

Commit 2275018

Browse files
committed
Improve toast cursor overlay test setup
1 parent a79d22e commit 2275018

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

internal/app/app_view_cursor_overlay_test.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"strings"
55
"testing"
66

7-
"charm.land/lipgloss/v2"
8-
97
"github.com/andyrewlee/amux/internal/ui/common"
108
)
119

@@ -84,15 +82,35 @@ func TestViewHidesTerminalCursorWhenToastCoversIt(t *testing.T) {
8482
}
8583

8684
_ = h.app.toast.ShowInfo("copy complete")
87-
toastView := h.app.toast.View()
88-
if toastView == "" {
89-
t.Fatal("expected visible toast")
90-
}
91-
toastWidth := lipgloss.Width(toastView)
92-
toastX := (h.app.width - toastWidth) / 2
93-
toastY := h.app.height - 2
94-
h.tabs[0].Terminal.CursorX = toastX
95-
h.tabs[0].Terminal.CursorY = toastY
85+
covered := false
86+
for width := 48; width <= 96 && !covered; width++ {
87+
for height := 8; height <= 18 && !covered; height++ {
88+
h.app.width = width
89+
h.app.height = height
90+
h.app.layout.Resize(width, height)
91+
h.app.updateLayout()
92+
93+
termOffsetX, termOffsetY, termW, termH := h.app.center.TerminalViewport()
94+
centerX := h.app.layout.LeftGutter() + h.app.layout.DashboardWidth() + h.app.layout.GapX()
95+
termX := centerX + termOffsetX
96+
termY := h.app.layout.TopGutter() + termOffsetY
97+
98+
for y := 0; y < termH && !covered; y++ {
99+
for x := 0; x < termW; x++ {
100+
if !h.app.toastCoversPoint(termX+x, termY+y) {
101+
continue
102+
}
103+
h.tabs[0].Terminal.CursorX = x
104+
h.tabs[0].Terminal.CursorY = y
105+
covered = true
106+
break
107+
}
108+
}
109+
}
110+
}
111+
if !covered {
112+
t.Fatal("expected a toast-covered point within the terminal viewport in test setup")
113+
}
96114

97115
view := h.Render()
98116
if view.Cursor != nil {

0 commit comments

Comments
 (0)