A platform for community discussion. Free, open, simple.
FIX: Avoid draft conflicts when creating a topic with the `c` shortcut
Régis Hanol2db7d1e48d2b
diff --git a/frontend/discourse/app/services/keyboard-shortcuts.js b/frontend/discourse/app/services/keyboard-shortcuts.jsindex 9421417a20e..fe879f38fa4 100644--- a/frontend/discourse/app/services/keyboard-shortcuts.js+++ b/frontend/discourse/app/services/keyboard-shortcuts.js@@ -575,10 +575,7 @@ export default class KeyboardShortcutLib extends Service {}// create new topic: default action- this.composer.open({- action: Composer.CREATE_TOPIC,- draftKey: Composer.NEW_TOPIC_KEY,- });+ this.composer.openNewTopic();}focusComposer(event) {diff --git a/frontend/discourse/tests/acceptance/keyboard-shortcuts-test.js b/frontend/discourse/tests/acceptance/keyboard-shortcuts-test.jsindex 5d0187b6717..f0e43c130cb 100644--- a/frontend/discourse/tests/acceptance/keyboard-shortcuts-test.js+++ b/frontend/discourse/tests/acceptance/keyboard-shortcuts-test.js@@ -303,6 +303,25 @@ acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {);});+ test("C key opens composer with a fresh draft in new topic mode from a regular topic", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await triggerKeyEvent(document, "keypress", "C");++ assert+ .dom(".composer-action-create-topic")+ .exists("opens the composer in new topic mode");+ const composerModel = this.owner.lookup("service:composer").model;+ assert.true(+ /^new_topic_\d+$/.test(composerModel.draftKey),+ "uses a unique draft key"+ );+ assert.strictEqual(+ composerModel.draftSequence,+ 0,+ "starts a fresh draft sequence"+ );+ });+test("C key opens composer in new PM mode from messages list", async function (assert) {await visit("/my/messages");await triggerKeyEvent(document, "keypress", "C");diff --git a/spec/system/composer/drafts_spec.rb b/spec/system/composer/drafts_spec.rbindex ee2fe35c7e5..e837d673d1f 100644--- a/spec/system/composer/drafts_spec.rb+++ b/spec/system/composer/drafts_spec.rb@@ -70,6 +70,36 @@ describe "Composer - Drafts" doendend+ context "when starting a topic with the keyboard shortcut on a topic page" do+ let(:dialog) { PageObjects::Components::Dialog.new }+ let(:drafts_page) { PageObjects::Pages::UserActivityDrafts.new }++ it "lets the user save a new topic draft next to an older one" do+ # an older topic draft on the shared key, whose sequence has moved on+ DraftSequence.next!(current_user, Draft::NEW_TOPIC)+ Draft.set(+ current_user,+ Draft::NEW_TOPIC,+ 1,+ { title: "An older topic draft", reply: "Started before the new one" }.to_json,+ )++ topic_page.visit_topic(topic)+ send_keys("c")++ expect(composer).to be_opened+ composer.fill_title("A new topic started from a topic page")+ composer.fill_content("This draft must not conflict with the older one")+ composer.close++ expect(toasts).to have_success(I18n.t("js.composer.draft_saved"))+ expect(dialog).to be_closed++ drafts_page.visit(current_user)+ expect(drafts_page).to have_drafts(count: 2)+ end+ end+context "when clicking discard" dolet(:dialog) { PageObjects::Components::Dialog.new }