fix(webmail): Discard really discards the draft

The button was a link to the inbox, so the autosaved draft stayed in Drafts.
It now removes the stored draft for good (not into Trash), stops the autosave,
and cleans up a save that was already in flight.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Sonnet 5.5 committed 2026-10-22 16:02:27 -03:00
1 parent d283ff6f8d
commit 657a43d612
8 files changed
+132 -8

No files matched your search

@@ -402,6 +402,28 @@ func TestDeleteFromTrashExpunges(t *testing.T) {
}
}
// "Discard" in the composer promises the draft is gone. Delete would leave it
// in Trash, so discarding removes it outright - and only ever from Drafts.
func TestDiscardingADraftRemovesItForGood(t *testing.T) {
mailboxID := uuid.New()
repo := &stubWebmailRepo{mailboxID: mailboxID.String()}
uc := &WebmailUseCase{
repo: repo,
auth: &stubAuthRepo{account: &port.MailboxAuth{ID: mailboxID, EmailAddress: "me@example.test"}},
localHost: "mail.example.test",
}
if err := uc.DiscardDraft(context.Background(), "me@example.test", 9); err != nil {
t.Fatalf("discard: %v", err)
}
if len(repo.expunged) != 1 || repo.expunged[0] != 9 {
t.Errorf("the draft was not expunged: %v", repo.expunged)
}
if len(repo.moved) != 0 {
t.Errorf("a discarded draft was moved instead of removed: %v", repo.moved)
}
}
// --- moving between folders ---------------------------------------------
// Filing a message somewhere else is the one ordinary mail action the webmail