Add Segment 6 entry editor coverage
This commit is contained in:
@@ -609,6 +609,39 @@ func TestDuplicateSelectedEntryCreatesCopyAndSelectsIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveSelectedEntryMovesEntryToNewPathAndMarksDirty(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
sess := &mutableStubSession{model: vault.Model{
|
||||
Entries: []vault.Entry{
|
||||
{ID: "vault-console", Title: "Vault Console", Path: []string{"Root", "Internet"}},
|
||||
},
|
||||
}}
|
||||
state := State{
|
||||
Session: sess,
|
||||
CurrentPath: []string{"Root", "Internet"},
|
||||
SelectedEntryID: "vault-console",
|
||||
}
|
||||
|
||||
if err := state.MoveSelectedEntry([]string{"Root", "Infrastructure"}); err != nil {
|
||||
t.Fatalf("MoveSelectedEntry() error = %v", err)
|
||||
}
|
||||
|
||||
oldPath := sess.model.EntriesInPath([]string{"Root", "Internet"})
|
||||
if len(oldPath) != 0 {
|
||||
t.Fatalf("EntriesInPath(Root/Internet) = %#v, want empty after move", oldPath)
|
||||
}
|
||||
|
||||
newPath := sess.model.EntriesInPath([]string{"Root", "Infrastructure"})
|
||||
if len(newPath) != 1 || newPath[0].ID != "vault-console" {
|
||||
t.Fatalf("EntriesInPath(Root/Infrastructure) = %#v, want moved vault-console entry", newPath)
|
||||
}
|
||||
|
||||
if !state.Dirty {
|
||||
t.Fatal("Dirty = false, want true after move")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreSelectedEntryVersionReplacesCurrentVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -677,6 +677,98 @@ func TestUISavesDuplicatesDeletesAndRestoresEntriesFromTheEditor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUICreatesEntryWithAllSupportedEditorFields(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := newUIWithModel("desktop", vault.Model{})
|
||||
u.showEntriesSection()
|
||||
u.currentPath = []string{"Root", "Internet"}
|
||||
u.filter()
|
||||
|
||||
u.entryID.SetText("bellagio")
|
||||
u.entryTitle.SetText("Bellagio")
|
||||
u.entryUsername.SetText("rustyryan")
|
||||
u.entryPassword.SetText("token-1")
|
||||
u.entryURL.SetText("https://bellagio.example.invalid")
|
||||
u.entryNotes.SetText("Registrar account")
|
||||
u.entryTags.SetText("dns, registrar")
|
||||
u.entryPath.SetText("Root / Internet")
|
||||
u.entryFields.SetText("Environment=prod\nAccount ID=12345")
|
||||
|
||||
if err := u.saveEntryAction(); err != nil {
|
||||
t.Fatalf("saveEntryAction() create error = %v", err)
|
||||
}
|
||||
|
||||
u.filter()
|
||||
if got := u.filteredTitles(); !slices.Equal(got, []string{"Bellagio"}) {
|
||||
t.Fatalf("filteredTitles() = %v, want [Bellagio]", got)
|
||||
}
|
||||
|
||||
item, ok := u.selectedEntry()
|
||||
if !ok {
|
||||
t.Fatal("selectedEntry() ok = false, want created entry")
|
||||
}
|
||||
if item.Title != "Bellagio" || item.Username != "rustyryan" || item.Password != "token-1" || item.URL != "https://bellagio.example.invalid" {
|
||||
t.Fatalf("selectedEntry() = %#v, want created Bellagio credentials", item)
|
||||
}
|
||||
if item.Notes != "Registrar account" {
|
||||
t.Fatalf("selectedEntry().Notes = %q, want %q", item.Notes, "Registrar account")
|
||||
}
|
||||
if !slices.Equal(item.Tags, []string{"dns", "registrar"}) {
|
||||
t.Fatalf("selectedEntry().Tags = %v, want [dns registrar]", item.Tags)
|
||||
}
|
||||
if item.Fields["Environment"] != "prod" || item.Fields["Account ID"] != "12345" {
|
||||
t.Fatalf("selectedEntry().Fields = %#v, want parsed custom fields", item.Fields)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUIEditingEntryPathMovesEntryBetweenGroups(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := newUIWithModel("desktop", vault.Model{
|
||||
Entries: []vault.Entry{
|
||||
{
|
||||
ID: "vault-console",
|
||||
Title: "Vault Console",
|
||||
Username: "dannyocean",
|
||||
Password: "token-1",
|
||||
URL: "https://vault.crew.example.invalid",
|
||||
Path: []string{"Root", "Internet"},
|
||||
},
|
||||
},
|
||||
})
|
||||
u.showEntriesSection()
|
||||
u.currentPath = []string{"Root", "Internet"}
|
||||
u.filter()
|
||||
u.state.SelectedEntryID = "vault-console"
|
||||
u.loadSelectedEntryIntoEditor()
|
||||
u.entryPath.SetText("Root / Infrastructure")
|
||||
|
||||
if err := u.saveEntryAction(); err != nil {
|
||||
t.Fatalf("saveEntryAction() move error = %v", err)
|
||||
}
|
||||
|
||||
u.currentPath = []string{"Root", "Internet"}
|
||||
u.filter()
|
||||
if got := u.filteredTitles(); len(got) != 0 {
|
||||
t.Fatalf("filteredTitles() in old path = %v, want empty after move", got)
|
||||
}
|
||||
|
||||
u.currentPath = []string{"Root", "Infrastructure"}
|
||||
u.filter()
|
||||
if got := u.filteredTitles(); !slices.Equal(got, []string{"Vault Console"}) {
|
||||
t.Fatalf("filteredTitles() in new path = %v, want [Vault Console]", got)
|
||||
}
|
||||
|
||||
item, ok := u.selectedEntry()
|
||||
if !ok {
|
||||
t.Fatal("selectedEntry() ok = false, want moved entry")
|
||||
}
|
||||
if !slices.Equal(item.Path, []string{"Root", "Infrastructure"}) {
|
||||
t.Fatalf("selectedEntry().Path = %v, want [Root Infrastructure]", item.Path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUITemplateAndAttachmentActionsWorkThroughEditor(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user