Add attachment replace workflow UI
This commit is contained in:
+61
-2
@@ -1015,6 +1015,19 @@ func TestUITemplateAndAttachmentActionsWorkThroughEditor(t *testing.T) {
|
||||
if err := u.addAttachmentAction(); err != nil {
|
||||
t.Fatalf("addAttachmentAction() error = %v", err)
|
||||
}
|
||||
if got := u.selectedAttachmentNames(); !slices.Equal(got, []string{"token.txt"}) {
|
||||
t.Fatalf("selectedAttachmentNames() = %v, want [token.txt]", got)
|
||||
}
|
||||
|
||||
replacementPath := filepath.Join(t.TempDir(), "token-replacement.txt")
|
||||
replacement := []byte("attachment-replacement")
|
||||
if err := os.WriteFile(replacementPath, replacement, 0o600); err != nil {
|
||||
t.Fatalf("WriteFile(replacementPath) error = %v", err)
|
||||
}
|
||||
u.attachmentPath.SetText(replacementPath)
|
||||
if err := u.replaceAttachmentAction(); err != nil {
|
||||
t.Fatalf("replaceAttachmentAction() error = %v", err)
|
||||
}
|
||||
|
||||
u.exportAttachmentPath.SetText(attachmentExportPath)
|
||||
if err := u.exportAttachmentAction(); err != nil {
|
||||
@@ -1025,8 +1038,8 @@ func TestUITemplateAndAttachmentActionsWorkThroughEditor(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile(exportAttachmentPath) error = %v", err)
|
||||
}
|
||||
if !bytes.Equal(exported, content) {
|
||||
t.Fatalf("exported attachment = %q, want %q", exported, content)
|
||||
if !bytes.Equal(exported, replacement) {
|
||||
t.Fatalf("exported attachment = %q, want %q", exported, replacement)
|
||||
}
|
||||
|
||||
if err := u.removeAttachmentAction(); err != nil {
|
||||
@@ -1152,6 +1165,52 @@ func TestUITemplatesCanBeBrowsedCreatedEditedDeletedAndInstantiated(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestUIAttachmentActionsRejectDuplicateMissingAndOversizeCases(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := newUIWithModel("desktop", vault.Model{
|
||||
Entries: []vault.Entry{
|
||||
{
|
||||
ID: "git-server",
|
||||
Title: "Git Server",
|
||||
Attachments: map[string][]byte{"token.txt": []byte("original")},
|
||||
Path: []string{"Root", "Internet"},
|
||||
},
|
||||
},
|
||||
})
|
||||
u.showEntriesSection()
|
||||
u.state.NavigateToPath([]string{"Root", "Internet"})
|
||||
u.filter()
|
||||
u.state.SelectedEntryID = "git-server"
|
||||
u.loadSelectedEntryIntoEditor()
|
||||
|
||||
addPath := filepath.Join(t.TempDir(), "token.txt")
|
||||
if err := os.WriteFile(addPath, []byte("duplicate"), 0o600); err != nil {
|
||||
t.Fatalf("WriteFile(addPath) error = %v", err)
|
||||
}
|
||||
u.attachmentName.SetText("token.txt")
|
||||
u.attachmentPath.SetText(addPath)
|
||||
if err := u.addAttachmentAction(); err == nil || !strings.Contains(err.Error(), "already exists") {
|
||||
t.Fatalf("addAttachmentAction() error = %v, want duplicate-name failure", err)
|
||||
}
|
||||
|
||||
u.attachmentName.SetText("missing.txt")
|
||||
if err := u.replaceAttachmentAction(); err == nil || !strings.Contains(err.Error(), "not found") {
|
||||
t.Fatalf("replaceAttachmentAction() error = %v, want missing-attachment failure", err)
|
||||
}
|
||||
|
||||
oversizePath := filepath.Join(t.TempDir(), "oversize.bin")
|
||||
oversizeContent := bytes.Repeat([]byte("a"), maxAttachmentBytes+1)
|
||||
if err := os.WriteFile(oversizePath, oversizeContent, 0o600); err != nil {
|
||||
t.Fatalf("WriteFile(oversizePath) error = %v", err)
|
||||
}
|
||||
u.attachmentName.SetText("oversize.bin")
|
||||
u.attachmentPath.SetText(oversizePath)
|
||||
if err := u.addAttachmentAction(); err == nil || !strings.Contains(err.Error(), "too large") {
|
||||
t.Fatalf("addAttachmentAction() oversize error = %v, want size failure", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUIRestoresSelectedEntryHistoryVersion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user