▍ humdrum codex / glint v1.1.2
license AGPL-3.0
3.1 KB raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package app

import (
	"os"
	"path/filepath"
	"strings"
	"testing"

	"glint/internal/theme"

	tea "github.com/charmbracelet/bubbletea"
)

func TestHeaderTextIsBasenameWithoutExtension(t *testing.T) {
	a := newApp()
	a.path = "/tmp/notes/my-note.md"
	if got := a.headerText(); got != "my-note" {
		t.Errorf("headerText() = %q, want my-note", got)
	}
}

func TestHeaderTextMarksDirty(t *testing.T) {
	a := newApp()
	a.path = "/tmp/notes/my-note.md"
	a.editor.Dirty = true
	if got := a.headerText(); got != "my-note •" {
		t.Errorf("headerText() = %q, want 'my-note •'", got)
	}
}

func TestHeaderTextForPathlessBuffer(t *testing.T) {
	a := newApp()
	a.path = ""
	if got := a.headerText(); got != "Untitled" {
		t.Errorf("headerText() = %q, want Untitled", got)
	}
}

func TestHeaderIgnoresFrontmatterTitle(t *testing.T) {
	dir := t.TempDir()
	p := filepath.Join(dir, "on-disk.md")
	os.WriteFile(p, []byte("---\ntitle: Something Else\n---\n\nbody"), 0o644)

	a := newApp()
	if err := a.Load(p); err != nil {
		t.Fatal(err)
	}
	if got := a.headerText(); got != "on-disk" {
		t.Errorf("headerText() = %q, want on-disk (edit mode shows the file, not the title)", got)
	}
}

func TestHeaderBarAppearsInEditorView(t *testing.T) {
	dir := t.TempDir()
	p := filepath.Join(dir, "visible.md")
	os.WriteFile(p, []byte("body"), 0o644)

	a := newApp()
	a.theme = theme.FlexokiDark()
	a.editor.SetTheme(theme.FlexokiDark())
	a.Load(p)
	a.Update(tea.WindowSizeMsg{Width: 100, Height: 12})
	if !strings.Contains(a.View(), "visible") {
		t.Errorf("editor View() has no filename header:\n%s", a.View())
	}
}

func TestHeaderCostsNoTextRows(t *testing.T) {
	dir := t.TempDir()
	p := filepath.Join(dir, "rows.md")
	os.WriteFile(p, []byte("body"), 0o644)

	a := newApp()
	a.Load(p)
	a.Update(tea.WindowSizeMsg{Width: 100, Height: 20})
	gotW, gotH := a.editor.Width, a.editor.Height
	if gotH != 20-1-canvasTopPad {
		t.Errorf("editor height = %d, want %d (header must not steal a text row)", gotH, 20-1-canvasTopPad)
	}
	if gotW != a.contentWidth() {
		t.Errorf("editor width = %d, want %d", gotW, a.contentWidth())
	}
}

func TestViewIsExactlyHeightRows(t *testing.T) {
	dir := t.TempDir()
	p := filepath.Join(dir, "rows2.md")
	os.WriteFile(p, []byte("body"), 0o644)

	a := newApp()
	a.Load(p)
	a.Update(tea.WindowSizeMsg{Width: 100, Height: 14})
	if n := len(strings.Split(a.View(), "\n")); n != 14 {
		t.Errorf("View() = %d lines, want 14 (canvas height-1 + status bar)", n)
	}
}

func TestHeaderHiddenInPicker(t *testing.T) {
	a := newApp()
	a.path = "/tmp/notes/hidden.md"
	a.mode = ModePicker
	if a.showHeader() {
		t.Error("showHeader() = true in ModePicker, want false")
	}
}

func TestHeaderHiddenInPreviewAndHelp(t *testing.T) {
	a := newApp()
	a.path = "/tmp/notes/hidden.md"
	for _, m := range []Mode{ModePreview, ModeHelp} {
		a.mode = m
		if a.showHeader() {
			t.Errorf("showHeader() = true in mode %d, want false", m)
		}
	}
}

func TestHeaderShownInOverlayModes(t *testing.T) {
	a := newApp()
	a.path = "/tmp/notes/shown.md"
	for _, m := range []Mode{ModeEditor, ModeFind, ModeGotoLine, ModeSpell} {
		a.mode = m
		if !a.showHeader() {
			t.Errorf("showHeader() = false in mode %d, want true", m)
		}
	}
}