Add shared live run graphs, debugging, editor choice and draft cleanup
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
)
|
||||
|
||||
func TestPipelineEditPickerHasTabNavigationFuzzySearchAndRetainedDraft(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
m := New(context.Background(), "ws://example/connect")
|
||||
m.width = 120
|
||||
m.height = 35
|
||||
m.keys.detail = true
|
||||
source := pipeline.Template([]string{"one"}, true)
|
||||
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{Name: "workflow", Version: 2}, LatestVersion: 4, Source: source}
|
||||
updated, _ := m.editPipeline()
|
||||
m = updated.(Model)
|
||||
if !m.editorOpen || m.editorDraft.baseVersion != 4 || m.editorDraft.source != pipeline.ExecutionSource(source) {
|
||||
t.Fatal("edit did not ask which editor or lost version guard")
|
||||
}
|
||||
if items, _ := draft.List(); len(items) != 0 {
|
||||
t.Fatal("opening/canceling picker should not create a draft")
|
||||
}
|
||||
if view := ansi.Strip(m.editorPickerView(30)); !strings.Contains(view, "nvim") || !strings.Contains(view, "OpenCode") {
|
||||
t.Fatal("editor options missing", view)
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyTab})
|
||||
m = updated.(Model)
|
||||
if m.editorIndex != 1 {
|
||||
t.Fatal("Tab did not select OpenCode")
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyShiftTab})
|
||||
m = updated.(Model)
|
||||
if m.editorIndex != 0 {
|
||||
t.Fatal("Shift+Tab did not select nvim")
|
||||
}
|
||||
m.editorInput.SetValue("ocd")
|
||||
if choices := m.editorChoices(); len(choices) != 1 || choices[0] != "OpenCode" {
|
||||
t.Fatal("fuzzy editor search failed", choices)
|
||||
}
|
||||
m.editorInput.SetValue("nv")
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd == nil || m.editorOpen {
|
||||
t.Fatal("editor selection did not launch")
|
||||
}
|
||||
items, err := draft.List()
|
||||
if err != nil || len(items) != 1 || items[0].BaseVersion != 4 || items[0].Server != m.url {
|
||||
t.Fatal("edit did not retain guarded draft", items, err)
|
||||
}
|
||||
if m.confirmOpen || m.submitID != "" {
|
||||
t.Fatal("editor selection bypassed explicit submission")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDraftCleanupRequiresConfirmationAndPreservesOtherDraft(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
a, _ := draft.Create("discard", "discard", "server", true, 0)
|
||||
b, _ := draft.Create("keep", "keep", "server", true, 0)
|
||||
m := New(context.Background(), "server")
|
||||
updated, _ := m.openDrafts()
|
||||
m = updated.(Model)
|
||||
for i, d := range m.draftItems {
|
||||
if d.Path == a.Path {
|
||||
m.draftIndex = i
|
||||
}
|
||||
}
|
||||
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})
|
||||
m = updated.(Model)
|
||||
if m.draftDeletingPath != a.Path {
|
||||
t.Fatal("delete confirmation not opened")
|
||||
}
|
||||
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyEsc})
|
||||
m = updated.(Model)
|
||||
if _, err := draft.Read(a.Path); err != nil {
|
||||
t.Fatal("cancel deleted draft", err)
|
||||
}
|
||||
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})
|
||||
m = updated.(Model)
|
||||
m.pendingDraft = &editedMsg{path: a.Path}
|
||||
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'y'}})
|
||||
m = updated.(Model)
|
||||
if m.pendingDraft != nil || m.draftDeletingPath != "" || len(m.draftItems) != 1 || m.draftItems[0].Path != b.Path {
|
||||
t.Fatal("cleanup did not clear selected draft/refresh browser")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user