FIX: Destroy draft when clicking the Discard button (#28552)

This commit is contained in:
Jan Cernik 2024-08-26 10:49:26 -05:00 committed by GitHub
parent 58d687a92e
commit b0f6d074be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 4 deletions

View File

@ -1405,6 +1405,8 @@ export default class ComposerService extends Service {
composerModel.setProperties({ unlistTopic: false, whisper: false });
}
await this._setModel(composerModel, opts);
// we need a draft sequence for the composer to work
if (opts.draftSequence === undefined) {
let data = await Draft.get(opts.draftKey);
@ -1417,8 +1419,6 @@ export default class ComposerService extends Service {
opts.draft ||= data.draft;
opts.draftSequence = data.draft_sequence;
await this._setModel(composerModel, opts);
return;
}
@ -1433,8 +1433,6 @@ export default class ComposerService extends Service {
await this.open(opts);
}
}
await this._setModel(composerModel, opts);
} finally {
this.skipAutoSave = false;
this.appEvents.trigger("composer:open", { model: this.model });

View File

@ -68,4 +68,31 @@ describe "Composer - discard draft modal", type: :system do
expect(composer).to be_opened
end
end
context "when clicking abandon draft" do
let(:dialog) { PageObjects::Components::Dialog.new }
before { Jobs.run_immediately! }
it "destroys draft" do
visit "/new-topic"
composer.fill_content("a b c d e f g")
composer.close
expect(discard_draft_modal).to be_open
discard_draft_modal.click_save
wait_for(timeout: 5) { Draft.last != nil }
draft_key = Draft.last.draft_key
visit "/new-topic"
expect(dialog).to be_open
expect(page).to have_content(I18n.t("js.drafts.abandon.confirm"))
dialog.click_danger
wait_for(timeout: 5) { Draft.find_by(draft_key: draft_key) == nil }
end
end
end

View File

@ -11,6 +11,10 @@ module PageObjects
def closed?
has_no_css?(".modal.d-modal#{MODAL_SELECTOR}")
end
def click_save
footer.find("button.save-draft").click
end
end
end
end