From 90b379b110a9abbfe5416deffb78c2c65d49e427 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Mon, 30 Jan 2017 13:31:16 +0100 Subject: [PATCH] Drop useless data attribute for message text in publisher --- .../app/views/publisher/mention_view.js | 15 ------ .../javascripts/app/views/publisher_view.js | 2 +- .../app/views/publisher_mention_view_spec.js | 52 ------------------- 3 files changed, 1 insertion(+), 68 deletions(-) diff --git a/app/assets/javascripts/app/views/publisher/mention_view.js b/app/assets/javascripts/app/views/publisher/mention_view.js index 55efafbe2..d1c98b829 100644 --- a/app/assets/javascripts/app/views/publisher/mention_view.js +++ b/app/assets/javascripts/app/views/publisher/mention_view.js @@ -14,8 +14,6 @@ app.views.PublisherMention = app.views.SearchBase.extend({ initialize: function() { this.mentionedPeople = []; - - // has a data-messageText attribute with the original text this.inputBox = this.$("#status_message_text"); this.typeaheadInput = this.$(".typeahead-mention-box"); this.bindTypeaheadEvents(); @@ -67,18 +65,11 @@ app.views.PublisherMention = app.views.SearchBase.extend({ messageText = messageText.substring(0, triggerCharPosition) + mentionText + messageText.substring(caretPosition); this.inputBox.val(messageText); - this.updateMessageTexts(); - this.inputBox.focus(); var newCaretPosition = triggerCharPosition + mentionText.length; this.inputBox[0].setSelectionRange(newCaretPosition, newCaretPosition); }, - updateMessageTexts: function() { - var messageText = this.inputBox.val(); - this.inputBox.data("messageText", messageText); - }, - updateTypeaheadInput: function() { var messageText = this.inputBox.val(); var caretPosition = this.inputBox[0].selectionStart; @@ -107,7 +98,6 @@ app.views.PublisherMention = app.views.SearchBase.extend({ text = this.inputBox.val() + " " + text; } this.inputBox.val(text); - this.updateMessageTexts(); }, this); }, @@ -133,7 +123,6 @@ app.views.PublisherMention = app.views.SearchBase.extend({ */ onInputBoxInput: function() { this.cleanMentionedPeople(); - this.updateMessageTexts(); this.updateTypeaheadInput(); }, @@ -189,9 +178,5 @@ app.views.PublisherMention = app.views.SearchBase.extend({ isVisible: function() { return this.$(".tt-menu").is(":visible"); - }, - - getTextForSubmit: function() { - return this.mentionedPeople.length ? this.inputBox.data("messageText") : this.inputBox.val(); } }); diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index 7d789f998..a06ac3387 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -324,7 +324,7 @@ app.views.Publisher = Backbone.View.extend({ this.handleTextchange(); var serializedForm = $("#new_status_message").serializeObject(); - var text = this.mention.getTextForSubmit(); + var text = serializedForm["status_message[text]"]; var photos = this.getUploadedPhotos(); var mentionedPeople = this.mention.mentionedPeople; var poll = this.getPollData(serializedForm); diff --git a/spec/javascripts/app/views/publisher_mention_view_spec.js b/spec/javascripts/app/views/publisher_mention_view_spec.js index 7ab98fe78..4cd9e5ae6 100644 --- a/spec/javascripts/app/views/publisher_mention_view_spec.js +++ b/spec/javascripts/app/views/publisher_mention_view_spec.js @@ -177,12 +177,6 @@ describe("app.views.PublisherMention", function() { expect(this.view.inputBox.val()).toBe("@{user1@pod.tld} 123 user2 @{user2@pod.tld} 456 @{user3@pod.tld} 789"); }); - it("calls updateMessageTexts", function() { - spyOn(this.view, "updateMessageTexts"); - this.view.onSuggestionSelection({name: "user1337", handle: "user1@pod.tld"}); - expect(this.view.updateMessageTexts).toHaveBeenCalled(); - }); - it("places the caret at the right position", function() { this.view.onSuggestionSelection({"name": "user1WithLongName", "handle": "user1@pod.tld"}); var expectedCaretPosition = ("@user1337 Text before @{user1@pod.tld}").length; @@ -190,19 +184,6 @@ describe("app.views.PublisherMention", function() { }); }); - describe("updateMessageTexts", function() { - beforeEach(function() { - this.view = new app.views.PublisherMention({ el: "#publisher" }); - this.view.inputBox.val("@user1 Text before @{user1@pod.tld}\ntext after"); - this.view.mentionedPeople.push({"name": "user1", "handle": "user1@pod.tld"}); - }); - - it("sets the correct messageText", function() { - this.view.updateMessageTexts(); - expect(this.view.inputBox.data("messageText")).toBe("@user1 Text before @{user1@pod.tld}\ntext after"); - }); - }); - describe("updateTypeaheadInput", function() { beforeEach(function() { this.view = new app.views.PublisherMention({ el: "#publisher" }); @@ -254,13 +235,11 @@ describe("app.views.PublisherMention", function() { beforeEach(function() { this.view = new app.views.PublisherMention({ el: "#publisher" }); spyOn(this.view, "addPersonToMentions"); - spyOn(this.view, "updateMessageTexts"); }); it("prefills one mention", function() { this.view.prefillMention([{"name": "user1", "handle": "user1@pod.tld"}]); expect(this.view.addPersonToMentions).toHaveBeenCalledWith({"name": "user1", "handle": "user1@pod.tld"}); - expect(this.view.updateMessageTexts).toHaveBeenCalled(); expect(this.view.inputBox.val()).toBe("@{user1@pod.tld}"); }); @@ -272,7 +251,6 @@ describe("app.views.PublisherMention", function() { expect(this.view.addPersonToMentions).toHaveBeenCalledWith({"name": "user1", "handle": "user1@pod.tld"}); expect(this.view.addPersonToMentions).toHaveBeenCalledWith({"name": "user2", "handle": "user2@pod.tld"}); - expect(this.view.updateMessageTexts).toHaveBeenCalled(); expect(this.view.inputBox.val()).toBe("@{user1@pod.tld} @{user2@pod.tld}"); }); }); @@ -380,12 +358,6 @@ describe("app.views.PublisherMention", function() { expect(this.view.cleanMentionedPeople).toHaveBeenCalled(); }); - it("calls 'updateMessageTexts'", function() { - spyOn(this.view, "updateMessageTexts"); - this.view.onInputBoxInput(); - expect(this.view.updateMessageTexts).toHaveBeenCalled(); - }); - it("calls 'updateTypeaheadInput'", function() { spyOn(this.view, "updateTypeaheadInput"); this.view.onInputBoxInput(); @@ -450,28 +422,4 @@ describe("app.views.PublisherMention", function() { expect(this.view.typeaheadInput.val()).toBe(""); }); }); - - describe("getTextForSubmit", function() { - beforeEach(function() { - this.view = new app.views.PublisherMention({ el: "#publisher" }); - this.view.bloodhound.add([ - {person: true, name: "user1", handle: "user1@pod.tld"} - ]); - }); - - it("returns text with mention if someone has been mentioned", function() { - this.view.inputBox.val("@user"); - this.view.inputBox[0].setSelectionRange(5, 5); - this.view.typeaheadInput.typeahead("val", "user"); - this.view.typeaheadInput.typeahead("open"); - this.view.$(".tt-suggestion").first().click(); - expect(this.view.getTextForSubmit()).toBe("@{user1@pod.tld}"); - }); - - it("returns normal text if nobody has been mentioned", function() { - this.view.inputBox.data("messageText", "Bad text"); - this.view.inputBox.val("Good text"); - expect(this.view.getTextForSubmit()).toBe("Good text"); - }); - }); });