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) } } }