cat / 012
clone

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

main
012 / e2e / layout_test.go
layout_test.go 3.0K
1package e2e23import (4 "strings"5 "testing"67 ghostty "go.mitchellh.com/libghostty"8)910// The trip plan's layout draws as a table, the notes wrapped over their11// rows, and comes back from its file as it was.12func TestLayoutDrawsAndSurvivesSave(t *testing.T) {13 t.Parallel()14 dir := t.TempDir()15 s := start(t, dir)16 tripPlan(s)17 checkTrip := func(s *session) {18 s.t.Helper()19 // The grid may still be drawing its last rows.20 for _, want := range []string{"Trip to Lisbon", "┏━━━━━━━━━┯", "┣━════════╪", "│Tram 28 ┃", "┃Total │", "┗━━━━━━━━━┷"} {21 s.waitFor(want)22 }23 }24 checkTrip(s)25 s.keys("<ctrl+s>", "trip", "<enter>")26 s.eventually("saved", func() bool { return s.title() == "012 - trip.012" })27 s.keys("<ctrl+q>")28 s.waitExit()2930 r := start(t, dir, "trip.012")31 r.waitFor("Trip to Lisbon")32 checkTrip(r)33 // The merged title is one cell: clicking its middle selects A1, and34 // Right leaves it at D1.35 r.click(ghostty.MouseButtonLeft, 6+10+4, gridRow1)36 r.waitForBar("A1", "Trip to Lisbon")37 r.keys("<right>")38 r.waitForName("D1")39}4041// A merged cell takes an entry as wide as it and can't be frozen42// through; the total's middle alignment and the blue outline survive a43// save.44func TestMergeEntryAndAlignment(t *testing.T) {45 t.Parallel()46 dir := t.TempDir()47 s := start(t, dir)48 coloredPlan(s)49 s.keys("<ctrl+home>", "A title as wide as the merge")50 s.waitFor("A title as wide as the merge")51 s.keys("<esc>", "<ctrl+g>", "E2:E4", "<enter>")52 palette(s, "merge all")53 s.waitFor("Merged E2:E4")54 s.keys("<ctrl+g>", "F3", "<enter>")55 palette(s, "freeze up to current row")56 s.waitFor("Can't freeze through the merged cells E2:E4")57 s.keys("<esc>", "<ctrl+s>", "plan", "<enter>")58 s.eventually("saved", func() bool { return s.title() == "012 - plan.012" })59 s.keys("<ctrl+q>")60 s.waitExit()6162 r := start(t, dir, "plan.012")63 r.waitFor("Trip to Lisbon")64 lines := strings.Split(r.screen(), "\n")65 for i, l := range lines {66 if strings.Contains(l, "┃Total │ 225 │") {67 if i+1 >= len(lines) || !strings.Contains(lines[i+1], " 6 ┃") {68 t.Errorf("Total isn't in the middle of its row:\n%s", r.screen())69 }70 return71 }72 }73 t.Errorf("no total:\n%s", r.screen())74}7576// Dragging a row number's corner makes the row taller; double-clicking77// it fits the row again.78func TestDragRowHeight(t *testing.T) {79 t.Parallel()80 s := start(t, "")81 s.keys("Tall", "<enter>")82 s.mouse(ghostty.MouseActionMotion, ghostty.MouseButtonUnknown, 5, gridRow1, 0)83 s.waitFor("▄")84 s.mouse(ghostty.MouseActionPress, ghostty.MouseButtonLeft, 5, gridRow1, 0)85 s.mouse(ghostty.MouseActionMotion, ghostty.MouseButtonLeft, 5, gridRow1+2, 0)86 s.waitFor("Row 1 height 3 lines")87 s.mouse(ghostty.MouseActionRelease, ghostty.MouseButtonLeft, 5, gridRow1+2, 0)88 // The value sits on the row's last line, beside its number.89 s.waitForLine(gridRow1+2, " 1 Tall")90 s.waitForLine(gridRow1+3, " 2")91 s.click(ghostty.MouseButtonLeft, 5, gridRow1+2)92 s.click(ghostty.MouseButtonLeft, 5, gridRow1+2)93 s.waitForLine(gridRow1, " 1 Tall")94}