cat / 012
clone

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

cat/module-path
012 / internal / ui / notes_test.go
notes_test.go 2.1K
1package ui23import (4 "strings"5 "testing"67 tea "charm.land/bubbletea/v2"8)910func TestNoteEdit(t *testing.T) {11 m := newModel()12 press(t, m, "<right>", "12", "<enter>", "<up>", "<shift+f2>")13 if l := line(m, contextLine); !strings.HasPrefix(l, "Note on B1:") || m.indicator() != "NOTE" {14 t.Fatalf("prompt %q, %s", l, m.indicator())15 }16 press(t, m, "Checked", "<alt+enter>", "twice", "<enter>")17 if got := m.sheet.Note(addr("B1")); got != "Checked\ntwice" {18 t.Fatalf("note %q", got)19 }20 // The active cell's note is on the context line, and its cell has21 // the mark in its corner.22 if l := line(m, contextLine); !strings.Contains(l, "Note Checked ↵ twice") {23 t.Errorf("context line %q", l)24 }25 if row := line(m, gridTop); !strings.Contains(row, "12▝") {26 t.Errorf("no mark: %q", row)27 }28 // Editing starts from the note, line breaks shown as ↵.29 press(t, m, "<shift+f2>")30 if l := line(m, contextLine); !strings.Contains(l, "Checked↵twice") {31 t.Errorf("editing %q", l)32 }33 press(t, m, "<esc>")34 // Clearing the cell keeps the note; undo takes it away.35 press(t, m, "<delete>")36 if m.sheet.Note(addr("B1")) == "" {37 t.Error("Delete removed the note")38 }39 press(t, m, "<ctrl+z>", "<ctrl+z>")40 if m.sheet.Note(addr("B1")) != "" {41 t.Errorf("undo left %q", m.sheet.Note(addr("B1")))42 }43 press(t, m, "<ctrl+y>")44 m.runCommand("note.delete")45 if m.sheet.Note(addr("B1")) != "" || !strings.Contains(line(m, contextLine), "Deleted 1 note") {46 t.Errorf("delete: %q, %q", m.sheet.Note(addr("B1")), line(m, contextLine))47 }48}4950func TestNoteHover(t *testing.T) {51 m := newModel()52 m.sheet.SetNote(addr("B2"), "A long note that wraps over more than one line in its box")53 send(m, tea.MouseMotionMsg{X: cellX(1), Y: gridTop + 1})54 s := screen(m)55 if !strings.Contains(s, "┌─ Note ─") || !strings.Contains(s, "A long note that wraps over") || !strings.Contains(s, "more than one line in its box") {56 t.Errorf("no hover box:\n%s", s)57 }58 send(m, tea.MouseMotionMsg{X: cellX(3), Y: gridTop + 1})59 if strings.Contains(screen(m), "Note") {60 t.Errorf("box stays after leaving the cell:\n%s", screen(m))61 }62}