diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index c6374a30185ca542a06ee2a0a3340437c821a306..ec3f126c15ea46ecdd5342ebddf97efed7fac206 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -9,8 +9,8 @@ app.views.CommentStream = app.views.Base.extend({ events: { "keydown .comment_box": "keyDownOnCommentBox", "submit form": "createComment", - "focus .comment_box": "commentTextareaFocused", - "click .toggle_post_comments": "expandComments" + "click .toggle_post_comments": "expandComments", + "click form": "openForm" }, initialize: function() { @@ -21,6 +21,7 @@ app.views.CommentStream = app.views.Base.extend({ setupBindings: function() { this.model.comments.bind("add", this.appendComment, this); this.model.comments.bind("remove", this.removeComment, this); + $(document.body).click(this.onFormBlur.bind(this)); }, postRenderTemplate : function() { @@ -28,6 +29,13 @@ app.views.CommentStream = app.views.Base.extend({ this.commentBox = this.$(".comment_box"); this.commentSubmitButton = this.$("input[name='commit']"); new app.views.CommentMention({el: this.$el, postId: this.model.get("id")}); + + this.mdEditor = new Diaspora.MarkdownEditor(this.$(".comment_box"), { + onPreview: function($mdInstance) { + return "<div class='preview-content'>" + app.helpers.textFormatter($mdInstance.getContent()) + "</div>"; + }, + onFocus: this.openForm.bind(this) + }); }, presenter: function(){ @@ -53,11 +61,14 @@ app.views.CommentStream = app.views.Base.extend({ success: function() { this.commentBox.val(""); this.enableCommentBox(); + this.mdEditor.hidePreview(); + this.closeForm(); autosize.update(this.commentBox); }.bind(this), error: function() { this.enableCommentBox(); - this.commentBox.focus(); + this.mdEditor.hidePreview(); + this.openForm(); }.bind(this) }); }, @@ -122,10 +133,6 @@ app.views.CommentStream = app.views.Base.extend({ this.$("#" + comment.get("guid")).closest(".comment.media").remove(); }, - commentTextareaFocused: function(){ - this.$("form").removeClass('hidden').addClass("open"); - }, - expandComments: function(evt){ this.$(".loading-comments").removeClass("hidden"); if(evt){ evt.preventDefault(); } @@ -135,6 +142,29 @@ app.views.CommentStream = app.views.Base.extend({ this.$(".loading-comments").addClass("hidden"); }.bind(this) }); + }, + + openForm: function() { + this.$("form").addClass("open"); + this.$(".md-editor").addClass("active"); + }, + + closeForm: function() { + this.$("form").removeClass("open"); + this.$(".md-editor").removeClass("active"); + autosize.update(this.commentBox); + }, + + onFormBlur: function(evt) { + if (this.mdEditor !== undefined && this.mdEditor.isPreviewOrTexareaNotEmpty()) { + return; + } + + var $target = $(evt.target); + var isForm = $target.hasClass("new-comment") || $target.parents(".new-comment").length !== 0; + if (!isForm && !$target.hasClass("focus_comment_textarea")) { + this.closeForm(); + } } }); // @license-end diff --git a/app/assets/javascripts/app/views/conversations_form_view.js b/app/assets/javascripts/app/views/conversations_form_view.js index e3b553b7a6d69de5ef9e10504db47ef6a7a5b92d..54cb86435f90f8a0160c953010ec73012e649f1d 100644 --- a/app/assets/javascripts/app/views/conversations_form_view.js +++ b/app/assets/javascripts/app/views/conversations_form_view.js @@ -24,6 +24,14 @@ app.views.ConversationsForm = app.views.Base.extend({ remoteRoute: {url: "/contacts", extraParameters: "mutual=true"} }); + this.newConversationMdEditor = this.renderMarkdownEditor("#new-message-text"); + + // Creates another markdown editor in case of displaying conversation + var responseTextarea = $("#conversation-show .conversation-message-text"); + if (responseTextarea.length === 1) { + this.renderMarkdownEditor(responseTextarea); + } + this.bindTypeaheadEvents(); this.tagListElement.empty(); @@ -31,10 +39,18 @@ app.views.ConversationsForm = app.views.Base.extend({ this.prefill(opts.prefill); } - this.$("form#new-conversation").on("ajax:success", this.conversationCreateSuccess); + this.$("form#new-conversation").on("ajax:success", this.conversationCreateSuccess.bind(this)); this.$("form#new-conversation").on("ajax:error", this.conversationCreateError); }, + renderMarkdownEditor: function(element) { + return new Diaspora.MarkdownEditor($(element), { + onPreview: function($mdInstance) { + return "<div class='preview-content'>" + app.helpers.textFormatter($mdInstance.getContent()) + "</div>"; + } + }); + }, + addRecipient: function(person) { this.conversationRecipients.push(person); this.updateContactIdsListInput(); @@ -84,6 +100,7 @@ app.views.ConversationsForm = app.views.Base.extend({ }, conversationCreateSuccess: function(evt, data) { + this.newConversationMdEditor.hidePreview(); app._changeLocation(Routes.conversation(data.id)); }, diff --git a/app/assets/javascripts/app/views/conversations_inbox_view.js b/app/assets/javascripts/app/views/conversations_inbox_view.js index 67292cc75ab164b9de6b62638c0d8ba89c741933..bf8a323e2ef9b24406a9b2fec8011d39ab318709 100644 --- a/app/assets/javascripts/app/views/conversations_inbox_view.js +++ b/app/assets/javascripts/app/views/conversations_inbox_view.js @@ -9,7 +9,7 @@ app.views.ConversationsInbox = app.views.Base.extend({ }, initialize: function() { - new app.views.ConversationsForm(); + this.conversationForm = new app.views.ConversationsForm(); this.setupConversation(); }, @@ -23,6 +23,7 @@ app.views.ConversationsInbox = app.views.Base.extend({ self.$el.find("#conversation-show").removeClass("hidden").html(data); self.selectConversation(conversationId); self.setupConversation(); + self.conversationForm.renderMarkdownEditor("#conversation-show .conversation-message-text"); } }); }, diff --git a/app/assets/javascripts/helpers/markdown_editor.js b/app/assets/javascripts/helpers/markdown_editor.js index 5706888a1d5d9cee9bb8de044ba14916c73330be..5de028fecbba1294ddfacaec24f3ca08e810e44a 100644 --- a/app/assets/javascripts/helpers/markdown_editor.js +++ b/app/assets/javascripts/helpers/markdown_editor.js @@ -130,6 +130,13 @@ Diaspora.MarkdownEditor.prototype = { } }, + isPreviewOrTexareaNotEmpty: function() { + if (this.instance === undefined) { + return false; + } + return (this.instance.$editor.find(".md-preview").length > 0) || (this.instance.getContent().length > 0); + }, + localize: function() { var locale = Diaspora.I18n.language; diff --git a/app/assets/javascripts/mobile/mobile_comments.js b/app/assets/javascripts/mobile/mobile_comments.js index 49858bc1c08a590547b141f534e94129f8798265..0dbfa662fe85987e830b3380f5c5a48623cec12b 100644 --- a/app/assets/javascripts/mobile/mobile_comments.js +++ b/app/assets/javascripts/mobile/mobile_comments.js @@ -35,7 +35,7 @@ self.scrollToOffset(commentContainer); }); - this.stream().on("submit", ".new_comment", this.submitComment); + this.stream().on("submit", ".new-comment", this.submitComment); }, submitComment: function(evt){ diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss index 4fae714a7a8abdf2bd12370cbca96966891df2f2..1c111d57f4bcdb782d0177eec1fcfada6a062ed9 100644 --- a/app/assets/stylesheets/comments.scss +++ b/app/assets/stylesheets/comments.scss @@ -52,7 +52,6 @@ float: right; } padding-left: 12px; - display: none; } .comment_box { height: 35px; @@ -60,8 +59,6 @@ } textarea.comment_box:focus, textarea.comment_box:valid, textarea.comment_box:active { border-color: $border-dark-grey; - ~ .submit-button { display: block; } - min-height: 35px; box-shadow: none; } @@ -73,3 +70,16 @@ // scss-lint:enable ImportantRule } } + +.new-comment { + &:not(.open) .submit-button, + &:not(.open) .md-header { + display: none; + } + + // The rule for .md-preview is required until we switch to the newer release of bootstrap-markdown with + // the following commit in: + // https://github.com/toopay/bootstrap-markdown/commit/14a21c3837140144b27efc19c795d1a37fad70fb + .md-preview, + &.open .md-editor textarea { min-height: 70px; } +} diff --git a/app/assets/stylesheets/conversations.scss b/app/assets/stylesheets/conversations.scss index 7c0bf90c5c8cb78c1896517959191598221bcd12..f627e8059bbaab0c152a539737ca83f2a5c4b94a 100644 --- a/app/assets/stylesheets/conversations.scss +++ b/app/assets/stylesheets/conversations.scss @@ -238,3 +238,9 @@ } .new-conversation.form-horizontal .form-group:last-of-type { margin-bottom: 0; } + +// This rule is required until we switch to the newer release of bootstrap-markdown with +// the following commit in: https://github.com/toopay/bootstrap-markdown/commit/14a21c3837140144b27efc19c795d1a37fad70fb +.conversations-form-container .md-preview { + min-height: 105px; +} diff --git a/app/assets/stylesheets/markdown-editor.scss b/app/assets/stylesheets/markdown-editor.scss index b077a7b44567d06c4e3b7b7dd903d6dbe382503b..462ab2b31cc262e0d48ce7d22e371af4e6c61d2f 100644 --- a/app/assets/stylesheets/markdown-editor.scss +++ b/app/assets/stylesheets/markdown-editor.scss @@ -1,3 +1,18 @@ +.md-editor { + border: 1px solid $border-grey; + border-radius: $border-radius-small; + overflow: hidden; + + &.active { border: 1px solid $border-dark-grey; } + + textarea, + textarea:focus { + border: 0; + box-shadow: none; + margin: 0; + } +} + .md-footer, .md-header { background: $white; @@ -83,7 +98,6 @@ // scss-lint:disable ImportantRule height: auto !important; // scss-lint:enable ImportantRule - min-height: 90px; overflow: auto; position: relative; // !important is needed to override the CSS rules dynamically added to the element @@ -91,6 +105,8 @@ width: 100% !important; // scss-lint:enable ImportantRule z-index: 10; + + .preview-content { padding: 10px; } } .md-controls { diff --git a/app/assets/stylesheets/publisher.scss b/app/assets/stylesheets/publisher.scss index 83be3b0155f726258990211e225e8ac002fedb5b..5887a76c45e81ab7ce58108376e9dc099bd8626d 100644 --- a/app/assets/stylesheets/publisher.scss +++ b/app/assets/stylesheets/publisher.scss @@ -78,9 +78,7 @@ textarea { background: transparent; border: 0 solid $light-grey; - box-shadow: none; height: 50px; - margin: 0; resize: none; } @@ -193,6 +191,16 @@ margin-bottom: 0; } } + + .md-editor, + .md-editor.active { + border: 0; + } + + // This rule is required until we switch to the newer release of bootstrap-markdown with + // the following commit in: + // https://github.com/toopay/bootstrap-markdown/commit/14a21c3837140144b27efc19c795d1a37fad70fb + .md-preview { min-height: 90px; } } .publisher-textarea-wrapper { diff --git a/app/assets/templates/comment-stream_tpl.jst.hbs b/app/assets/templates/comment-stream_tpl.jst.hbs index cf3bb465215213413651a25a4af7875395af9328..592cf408bca83023c65fc23c0ff3687785849d6f 100644 --- a/app/assets/templates/comment-stream_tpl.jst.hbs +++ b/app/assets/templates/comment-stream_tpl.jst.hbs @@ -25,7 +25,8 @@ {{/with}} <div class="bd"> - <form accept-charset="UTF-8" action="/posts/{{id}}/comments" class="new_comment" id="new_comment_on_{{id}}" method="post"> + <form accept-charset="UTF-8" action="/posts/{{id}}/comments" + class="new-comment" id="new-comment-on-{{id}}" method="post"> <textarea class="comment_box form-control mention-textarea" id="comment_text_on_{{id}}" name="text" rows="1" required placeholder="{{t "stream.comment"}}" /> diff --git a/app/views/comments/_new_comment.mobile.haml b/app/views/comments/_new_comment.mobile.haml index 5cae5295029e576f63de43491c1898725943310c..d58bce9b21f5387bf396228d1d6e7b446e9a435c 100644 --- a/app/views/comments/_new_comment.mobile.haml +++ b/app/views/comments/_new_comment.mobile.haml @@ -5,7 +5,7 @@ .add_comment_bottom_link_container - if user_signed_in? = form_tag(post_comments_path(post_id), id: "new-comment-on-#{post_id}", - class: "new_comment", autocomplete: "off") do + class: "new-comment", autocomplete: "off") do %fieldset = hidden_field_tag :post_id, post_id, id: "post-id-on-#{post_id}" .form-group.clearfix diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index 753257d27c51c285873c88b954b0a8c06178c457..0679e7b3d1749ea8460fc177126192be58d3e555 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -3,12 +3,12 @@ When /^I focus the comment field$/ do end Then /^the first comment field should be open/ do - find("#main_stream .stream-element .new_comment").should be_visible + find("#main_stream .stream-element .new-comment").should be_visible end Then /^the first comment field should be closed$/ do page.should have_css(".stream-element .media") - page.should_not have_selector("#main_stream .stream-element .new_comment", match: :first) + page.should_not have_selector("#main_stream .stream-element .new-comment", match: :first) end When /^I make a show page comment "([^"]*)"$/ do |comment_text| diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index da6d562352e5ab704088fc1dcda88412e4e0ee0c..1dc25d098ed505212743af2aa433cdb284851bc2 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -19,6 +19,13 @@ describe("app.views.CommentStream", function(){ this.view.model.comments.pop(); expect(this.view.removeComment).toHaveBeenCalled(); }); + + it("calls onFormBlur when clicking outside the comment box", function() { + spyOn(app.views.CommentStream.prototype, "onFormBlur"); + this.view.setupBindings(); + $(document.body).click(); + expect(app.views.CommentStream.prototype.onFormBlur).toHaveBeenCalled(); + }); }); describe("postRenderTemplate", function() { @@ -57,6 +64,14 @@ describe("app.views.CommentStream", function(){ var call = app.views.CommentMention.prototype.initialize.calls.mostRecent(); expect(call.args[0]).toEqual({el: this.view.$el, postId: this.view.model.id}); }); + + it("creates the markdown editor", function() { + spyOn(Diaspora.MarkdownEditor.prototype, "initialize"); + this.view.mdEditor = undefined; + this.view.postRenderTemplate(); + expect(Diaspora.MarkdownEditor.prototype.initialize).toHaveBeenCalled(); + expect(this.view.mdEditor).toBeDefined(); + }); }); describe("createComment", function() { @@ -117,6 +132,18 @@ describe("app.views.CommentStream", function(){ this.request.respondWith({status: 200, responseText: "[]"}); expect(autosize.update).toHaveBeenCalledWith(this.view.commentBox); }); + + it("hides the markdown preview", function() { + spyOn(this.view.mdEditor, "hidePreview"); + this.request.respondWith({status: 200, responseText: "[]"}); + expect(this.view.mdEditor.hidePreview).toHaveBeenCalled(); + }); + + it("closes the form", function() { + spyOn(this.view, "closeForm"); + this.request.respondWith({status: 200, responseText: "[]"}); + expect(this.view.closeForm).toHaveBeenCalled(); + }); }); context("on error", function() { @@ -135,6 +162,18 @@ describe("app.views.CommentStream", function(){ this.request.respondWith({status: 500}); expect(this.view.enableCommentBox).toHaveBeenCalled(); }); + + it("hides the markdown preview", function() { + spyOn(this.view.mdEditor, "hidePreview"); + this.request.respondWith({status: 500, responseText: "[]"}); + expect(this.view.mdEditor.hidePreview).toHaveBeenCalled(); + }); + + it("opens the form", function() { + spyOn(this.view, "openForm"); + this.request.respondWith({status: 500, responseText: "[]"}); + expect(this.view.openForm).toHaveBeenCalled(); + }); }); }); }); @@ -283,6 +322,73 @@ describe("app.views.CommentStream", function(){ }); }); + describe("openForm", function() { + beforeEach(function() { + this.view.render(); + }); + + it("adds the 'open' class to form", function() { + this.view.$("form").removeClass("open"); + this.view.openForm(); + expect(this.view.$("form")).toHaveClass("open"); + }); + + it("adds the 'active' class to markdown editor", function() { + this.view.$(".md-editor").removeClass("active"); + this.view.openForm(); + expect(this.view.$(".md-editor")).toHaveClass("active"); + }); + }); + + describe("closeForm", function() { + beforeEach(function() { + this.view.render(); + }); + + it("removes the 'open' class to form", function() { + this.view.$("form").addClass("open"); + this.view.closeForm(); + expect(this.view.$("form")).not.toHaveClass("open"); + }); + + it("removes the 'active' class to markdown editor", function() { + this.view.$(".md-editor").addClass("active"); + this.view.closeForm(); + expect(this.view.$(".md-editor")).not.toHaveClass("active"); + }); + }); + + describe("onFormBlur", function() { + beforeEach(function() { + this.view.render(); + this.view.postRenderTemplate(); + spec.content().html("<div class='new-comment'/><div class='focus_comment_textarea'/>"); + }); + + it("does not call closeForm if markdown editor contains text or is in preview mode", function() { + spyOn(this.view, "closeForm"); + spyOn(this.view.mdEditor, "isPreviewOrTexareaNotEmpty").and.returnValue(true); + this.view.onFormBlur(); + expect(this.view.closeForm).not.toHaveBeenCalled(); + }); + + it("does not call closeForm when the form is clicked", function() { + spyOn(this.view, "closeForm"); + spyOn(this.view.mdEditor, "isPreviewOrTexareaNotEmpty").and.returnValue(false); + this.view.onFormBlur($.Event("click", {target: $(".new-comment")})); + expect(this.view.closeForm).not.toHaveBeenCalled(); + this.view.onFormBlur($.Event("click", {target: $(".focus_comment_textarea")})); + expect(this.view.closeForm).not.toHaveBeenCalled(); + }); + + it("calls closeForm when the user clicks outside of the form", function() { + spyOn(this.view, "closeForm"); + spyOn(this.view.mdEditor, "isPreviewOrTexareaNotEmpty").and.returnValue(false); + this.view.onFormBlur($.Event("click", {target: $("body")})); + expect(this.view.closeForm).toHaveBeenCalled(); + }); + }); + describe("pressing a key when typing on the new comment box", function(){ var submitCallback; diff --git a/spec/javascripts/app/views/conversations_form_view_spec.js b/spec/javascripts/app/views/conversations_form_view_spec.js index 232a7f7de21fd27f23e47b55a70c74e693de934d..50252d4cad9f48ad9a2bbe59838d37bfb242c914 100644 --- a/spec/javascripts/app/views/conversations_form_view_spec.js +++ b/spec/javascripts/app/views/conversations_form_view_spec.js @@ -35,6 +35,28 @@ describe("app.views.ConversationsForm", function() { this.target.initialize({prefill: {}}); expect(app.views.ConversationsForm.prototype.prefill).toHaveBeenCalledWith({}); }); + + it("creates markdown editor for new conversations", function() { + spyOn(this.target, "renderMarkdownEditor"); + this.target.initialize(); + expect(this.target.renderMarkdownEditor).toHaveBeenCalledWith("#new-message-text"); + }); + + it("creates markdown editor for an existing conversation", function() { + spyOn(this.target, "renderMarkdownEditor"); + this.target.initialize(); + expect(this.target.renderMarkdownEditor).toHaveBeenCalledWith( + $("#conversation-show .conversation-message-text")); + }); + }); + + describe("renderMarkdownEditor", function() { + it("creates MarkdownEditor", function() { + spec.content().html("<form><textarea id='new-message-text'/></form>"); + var mdEditor = this.target.renderMarkdownEditor("#new-message-text"); + expect(mdEditor).toEqual(jasmine.any(Diaspora.MarkdownEditor)); + expect($("#new-message-text")).toHaveClass("md-input"); + }); }); describe("addRecipient", function() { @@ -253,6 +275,12 @@ describe("app.views.ConversationsForm", function() { $("#new-conversation").trigger("ajax:success", [{id: 23}]); expect(app._changeLocation).toHaveBeenCalledWith(Routes.conversation(23)); }); + + it("hides the preview", function() { + spyOn(Diaspora.MarkdownEditor.prototype, "hidePreview"); + $("#new-conversation").trigger("ajax:success", [{id: 23}]); + expect(Diaspora.MarkdownEditor.prototype.hidePreview).toHaveBeenCalled(); + }); }); describe("conversationCreateError", function() { diff --git a/spec/javascripts/app/views/conversations_inbox_view_spec.js b/spec/javascripts/app/views/conversations_inbox_view_spec.js index 841f189f0507a80aa8687fe812db08436d0f5b07..9de43403b35b9701ab3f9771b75b8d14cab20bec 100644 --- a/spec/javascripts/app/views/conversations_inbox_view_spec.js +++ b/spec/javascripts/app/views/conversations_inbox_view_spec.js @@ -34,6 +34,7 @@ describe("app.views.ConversationsInbox", function() { spyOn($, "ajax").and.callThrough(); spyOn(app.views.ConversationsInbox.prototype, "selectConversation"); spyOn(app.views.ConversationsInbox.prototype, "setupConversation"); + spyOn(app.views.ConversationsForm.prototype, "renderMarkdownEditor"); this.target.renderConversation(this.conversationId); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, @@ -44,6 +45,7 @@ describe("app.views.ConversationsInbox", function() { expect(jasmine.Ajax.requests.mostRecent().url).toBe("/conversations/" + this.conversationId + "/raw"); expect(app.views.ConversationsInbox.prototype.selectConversation).toHaveBeenCalledWith(this.conversationId); expect(app.views.ConversationsInbox.prototype.setupConversation).toHaveBeenCalled(); + expect(app.views.ConversationsForm.prototype.renderMarkdownEditor).toHaveBeenCalled(); expect($("#conversation-new")).toHaveClass("hidden"); expect($("#conversation-show")).not.toHaveClass("hidden"); expect($("#conversation-show #fake-conversation-content").length).toBe(1); diff --git a/spec/javascripts/helpers/markdown_editor_spec.js b/spec/javascripts/helpers/markdown_editor_spec.js index 9c2ab4cff72d5e79640e39dd1ef676b6d2ab37bc..d834571b3bf42d4ee8e6fbbb0836b61449f3a52e 100644 --- a/spec/javascripts/helpers/markdown_editor_spec.js +++ b/spec/javascripts/helpers/markdown_editor_spec.js @@ -220,6 +220,27 @@ describe("Diaspora.MarkdownEditor", function() { }); }); + describe("isPreviewOrTexareaNotEmpty", function() { + beforeEach(function() { + this.target = new Diaspora.MarkdownEditor(this.$el, {onPreview: $.noop, onPostPreview: $.noop()}); + }); + + it("return false if editor is not visible yet", function() { + this.target.instance = undefined; + expect(this.target.isPreviewOrTexareaNotEmpty()).toBe(false); + }); + + it("returns true if editor is in preview mode", function() { + this.target.showPreview(); + expect(this.target.isPreviewOrTexareaNotEmpty()).toBe(true); + }); + + it("returns true if editor has content", function() { + $("textarea").text("Yolo"); + expect(this.target.isPreviewOrTexareaNotEmpty()).toBe(true); + }); + }); + describe("localize", function() { beforeEach(function() { this.target = new Diaspora.MarkdownEditor(this.$el, {}); diff --git a/spec/javascripts/mobile/mobile_comments_spec.js b/spec/javascripts/mobile/mobile_comments_spec.js index e87a81adcb1b7080e86f1457023eafaaf5b49822..af12f644ce1b4678f357f4f1459029dc8a2d7641 100644 --- a/spec/javascripts/mobile/mobile_comments_spec.js +++ b/spec/javascripts/mobile/mobile_comments_spec.js @@ -10,7 +10,7 @@ describe("Diaspora.Mobile.Comments", function(){ spyOn(Diaspora.Mobile.Comments, "submitComment").and.returnValue(false); Diaspora.Mobile.Comments.initialize(); Diaspora.Mobile.Comments.showCommentBox($(".stream .comment-action").first()); - $(".stream .new_comment").first().submit(); + $(".stream .new-comment").first().submit(); expect(Diaspora.Mobile.Comments.submitComment).toHaveBeenCalled(); }); }); @@ -97,28 +97,28 @@ describe("Diaspora.Mobile.Comments", function(){ }); it("doesn't submit an empty comment", function() { - $(".stream .new_comment").first().submit(); + $(".stream .new-comment").first().submit(); expect(jasmine.Ajax.requests.count()).toBe(0); }); it("submits comments with text", function() { - $(".stream .new_comment textarea").val("comment text"); - $(".stream .new_comment").first().submit(); + $(".stream .new-comment textarea").val("comment text"); + $(".stream .new-comment").first().submit(); expect(jasmine.Ajax.requests.mostRecent().data().text).toEqual(["comment text"]); }); it("calls updateStream on success", function() { spyOn(Diaspora.Mobile.Comments, "updateStream"); - $(".stream .new_comment textarea").val("comment text"); - $(".stream .new_comment").first().submit(); + $(".stream .new-comment textarea").val("comment text"); + $(".stream .new-comment").first().submit(); jasmine.Ajax.requests.mostRecent().respondWith({status: 200, responseText: "foo"}); - expect(Diaspora.Mobile.Comments.updateStream).toHaveBeenCalledWith($(".stream .new_comment").first(), "foo"); + expect(Diaspora.Mobile.Comments.updateStream).toHaveBeenCalledWith($(".stream .new-comment").first(), "foo"); }); it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); - $(".stream .new_comment textarea").val("comment text"); - $(".stream .new_comment").first().submit(); + $(".stream .new-comment textarea").val("comment text"); + $(".stream .new-comment").first().submit(); jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! comment failed!"}); expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled(); expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! comment failed!"); @@ -126,10 +126,10 @@ describe("Diaspora.Mobile.Comments", function(){ it("calls resetCommentBox on errors", function() { spyOn(Diaspora.Mobile.Comments, "resetCommentBox"); - $(".stream .new_comment textarea").val("comment text"); - $(".stream .new_comment").first().submit(); + $(".stream .new-comment textarea").val("comment text"); + $(".stream .new-comment").first().submit(); jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! comment failed!"}); - expect(Diaspora.Mobile.Comments.resetCommentBox).toHaveBeenCalledWith($(".stream .new_comment").first()); + expect(Diaspora.Mobile.Comments.resetCommentBox).toHaveBeenCalledWith($(".stream .new-comment").first()); }); });