Prompt for unnamed drafts directly before publication
This commit is contained in:
@@ -27,7 +27,7 @@ func TestRetainedDraftBrowserValidatesAndExplicitlySubmits(t *testing.T) {
|
||||
srv := httptest.NewServer(server.Handler(ctx, store))
|
||||
defer srv.Close()
|
||||
url := "ws" + strings.TrimPrefix(srv.URL, "http") + "/connect"
|
||||
d, err := draft.Create("CLI-created draft", pipeline.Template([]string{"worker"}, true), url, true, 0)
|
||||
d, err := draft.Create("", pipeline.Template([]string{"worker"}, true), url, true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestRetainedDraftBrowserValidatesAndExplicitlySubmits(t *testing.T) {
|
||||
m = updated.(Model)
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'d'}})
|
||||
m = updated.(Model)
|
||||
if !m.draftOpen || len(m.draftItems) != 1 || m.draftItems[0].Path != d.Path || !strings.Contains(m.View(), "CLI-created draft") {
|
||||
if !m.draftOpen || len(m.draftItems) != 1 || m.draftItems[0].Path != d.Path || !strings.Contains(m.View(), "Unnamed draft") {
|
||||
t.Fatal("retained draft not visible")
|
||||
}
|
||||
updated, validate := m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'v'}})
|
||||
@@ -56,6 +56,22 @@ func TestRetainedDraftBrowserValidatesAndExplicitlySubmits(t *testing.T) {
|
||||
if send != nil || !m.confirmOpen || len(items) != 0 {
|
||||
t.Fatal("draft selection published without confirmation")
|
||||
}
|
||||
if !strings.Contains(m.View(), "Name this pipeline") {
|
||||
t.Fatal("missing name prompt")
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("CLI-created draft")})
|
||||
m = updated.(Model)
|
||||
updated, send = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
items, _ = store.List(ctx)
|
||||
d.Name = "CLI-created draft"
|
||||
retained, err := draft.Load(d.Path)
|
||||
if err != nil || retained.Name != d.Name || retained.Server != url || !retained.CreateOnly || retained.BaseVersion != 0 || send != nil || len(items) != 0 || !m.confirmOpen {
|
||||
t.Fatal("naming lost metadata or published without confirmation", retained, err)
|
||||
}
|
||||
if source, err := draft.Read(d.Path); err != nil || source != pipeline.Template([]string{"worker"}, true) {
|
||||
t.Fatal("naming changed source", err)
|
||||
}
|
||||
updated, send = m.updateConfirm(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if send == nil {
|
||||
@@ -113,6 +129,46 @@ func TestRetainedDraftBrowserValidatesAndExplicitlySubmits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDraftNamePromptCancelAndInvalidName(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
d, err := draft.Create("", "source", "", true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := New(context.Background(), "ws://this-server")
|
||||
updated, _ := m.openDrafts()
|
||||
m = updated.(Model)
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'s'}})
|
||||
m = updated.(Model)
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if !m.confirmOpen || m.pendingDraft.name != "" || m.submitNotice == "" {
|
||||
t.Fatal("blank name accepted")
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(strings.Repeat("é", 101))})
|
||||
m = updated.(Model)
|
||||
updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd != nil || m.pendingDraft.name != "" {
|
||||
t.Fatal("oversized byte name accepted")
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEsc})
|
||||
m = updated.(Model)
|
||||
retained, err := draft.Load(d.Path)
|
||||
if err != nil || retained.Name != "" || m.confirmOpen || !m.draftOpen {
|
||||
t.Fatal("cancel modified draft", retained, err)
|
||||
}
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'s'}})
|
||||
m = updated.(Model)
|
||||
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("new name")})
|
||||
m = updated.(Model)
|
||||
updated, cmd = m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd != nil || m.pendingDraft.name != "new name" {
|
||||
t.Fatal("canceled input leaked into next prompt")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDraftBrowserRejectsWrongServerAndKeepsUnnamedDraft(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
d, err := draft.Create("wrong", "source", "ws://another-server", true, 0)
|
||||
@@ -131,7 +187,7 @@ func TestDraftBrowserRejectsWrongServerAndKeepsUnnamedDraft(t *testing.T) {
|
||||
m.confirmOpen = true
|
||||
updated, cmd = m.updateConfirm(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if cmd != nil || !strings.Contains(m.submitNotice, "needs a name") {
|
||||
if cmd != nil || !strings.Contains(m.submitNotice, "Name must") || !strings.Contains(m.confirmView(20), "Name this pipeline") {
|
||||
t.Fatal("unnamed draft submitted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user