From f98eddb675ffc01aa8fb7cfc01fc3cd20094a183 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 24 Aug 2015 22:55:56 +0800 Subject: [PATCH] FIX: Dirty edit can toggle to another edit. --- .../discourse/controllers/composer.js.es6 | 9 +++++++-- .../javascripts/discourse/models/composer.js.es6 | 2 +- test/javascripts/acceptance/composer-test.js.es6 | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index fcafb854d..8dfd77ba3 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -399,7 +399,7 @@ export default Ember.Controller.extend({ // If we're already open, we don't have to do anything if (composerModel.get('composeState') === Discourse.Composer.OPEN && composerModel.get('draftKey') === opts.draftKey && - composerModel.get('action') === opts.action ) { + self._isComposerReply(composerModel, opts)) { return resolve(); } @@ -407,7 +407,7 @@ export default Ember.Controller.extend({ if (composerModel.get('composeState') === Discourse.Composer.DRAFT && composerModel.get('draftKey') === opts.draftKey) { composerModel.set('composeState', Discourse.Composer.OPEN); - if (composerModel.get('action') === opts.action) return resolve(); + if (self._isComposerReply(composerModel, opts)) return resolve(); } // If it's a different draft, cancel it and try opening again. @@ -430,6 +430,11 @@ export default Ember.Controller.extend({ }); }, + _isComposerReply(composerModel, opts) { + return (composerModel.get('action') === Discourse.Composer.REPLY && + composerModel.get('action') === opts.action); + }, + // Given a potential instance and options, set the model for this composer. _setModel(composerModel, opts) { if (opts.draft) { diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 1156f51b1..9317bb183 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -371,7 +371,7 @@ const Composer = RestModel.extend({ const composer = this; if (!replyBlank && - ((opts.reply || opts.action === this.EDIT) && this.get('replyDirty'))) { + ((opts.reply || opts.action === EDIT) && this.get('replyDirty'))) { return; } diff --git a/test/javascripts/acceptance/composer-test.js.es6 b/test/javascripts/acceptance/composer-test.js.es6 index 1ebec24f2..835a34296 100644 --- a/test/javascripts/acceptance/composer-test.js.es6 +++ b/test/javascripts/acceptance/composer-test.js.es6 @@ -200,6 +200,21 @@ test("Composer can switch between edits", () => { }); }); +test("Composer with dirty edit can toggle to another edit", () => { + visit("/t/this-is-a-test-topic/9"); + + click('.topic-post:eq(0) button[data-action=edit]'); + fillIn('.wmd-input', 'This is a dirty reply'); + click('.topic-post:eq(1) button[data-action=edit]'); + andThen(() => { + ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); + }); + click('.modal-footer a:eq(0)'); + andThen(() => { + equal(find('.wmd-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text'); + }); +}); + test("Composer can toggle between edit and reply", () => { visit("/t/this-is-a-test-topic/9");