cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Set up and check the fill handle test with helpers

Dami committed ea9feab
TestFillHandleDrag had cognitive complexity 32; entering the cells and
checking the handle shows move into fillModel and hoverFillHandle.
commit
ea9feab6ba4bcdb0a1a7422fae4054a952b5a1eb
parent
a9bf9c233ffd678a1054682ceed7fadb2df115a0
author
Dami <dami.etoile@gmail.com>
1 file changed, +30 -17
Minternal/ui/data_test.go47+++++++++++++++++++-----------
M internal/ui/data_test.go +30 -17
@@ -27,28 +27,16 @@ func TestFillHandleDrag(t *testing.T) {
2727 }2828 for _, tt := range tests {2929 t.Run(tt.name, func(t *testing.T) {30- m := newModel()31- for i, in := range tt.cells {32- m.sheet.Set(sheet.Addr{Row: i}, in)33- }34- m.sheet.ClearHistory()35- m.cur, m.ext = addr("A1"), sheet.Addr{Row: len(tt.cells) - 1}36- m.selecting = len(tt.cells) > 130+ m := fillModel(tt.cells)3731 y := gridTop + len(tt.cells) - 138- // Hovering the corner cell shows the handle.39- send(m, tea.MouseMotionMsg{X: cellX(0), Y: y})40- if !strings.Contains(line(m, y), "▟") {41- t.Fatalf("no handle: %q", line(m, y))42- }43- if h := m.hitTest(handleX(0), y); h.kind != hitFillHandle {44- t.Fatalf("hit %+v", h)45- }32+ hoverFillHandle(t, m, y)4633 send(m, tea.MouseClickMsg(leftAt(handleX(0), y)))47- send(m, tea.MouseMotionMsg(leftAt(cellX(tt.to.Col), gridTop+tt.to.Row)))34+ to := leftAt(cellX(tt.to.Col), gridTop+tt.to.Row)35+ send(m, tea.MouseMotionMsg(to))4836 if tt.sel != "A1" && !strings.Contains(line(m, contextLine), "Fill "+tt.sel) {4937 t.Errorf("context line %q", line(m, contextLine))5038 }51- send(m, tea.MouseReleaseMsg(leftAt(cellX(tt.to.Col), gridTop+tt.to.Row)))39+ send(m, tea.MouseReleaseMsg(to))5240 for a, in := range tt.want {5341 if got := input(m, a); got != in {5442 t.Errorf("%s = %q, want %q", a, got, in)
@@ -67,6 +55,31 @@ func TestFillHandleDrag(t *testing.T) {
6755 }6856 }6957 58+// fillModel has cells entered from A1 down and selected.59+func fillModel(cells []string) *Model {60+ m := newModel()61+ for i, in := range cells {62+ m.sheet.Set(sheet.Addr{Row: i}, in)63+ }64+ m.sheet.ClearHistory()65+ m.cur, m.ext = addr("A1"), sheet.Addr{Row: len(cells) - 1}66+ m.selecting = len(cells) > 167+ return m68+}69+70+// hoverFillHandle hovers the corner cell on line y and checks that the71+// fill handle shows there.72+func hoverFillHandle(t *testing.T, m *Model, y int) {73+ t.Helper()74+ send(m, tea.MouseMotionMsg{X: cellX(0), Y: y})75+ if !strings.Contains(line(m, y), "▟") {76+ t.Fatalf("no handle: %q", line(m, y))77+ }78+ if h := m.hitTest(handleX(0), y); h.kind != hitFillHandle {79+ t.Fatalf("hit %+v", h)80+ }81+}82+7083 func TestFillHandleEscCancels(t *testing.T) {7184 m := newModel()7285 press(t, m, "1", "<enter>", "<up>")