diff --git a/public/javascripts/widgets/comment-stream.js b/public/javascripts/widgets/comment-stream.js index ab4cbdf64..76d20eaec 100644 --- a/public/javascripts/widgets/comment-stream.js +++ b/public/javascripts/widgets/comment-stream.js @@ -39,7 +39,10 @@ $.get(self.commentToggler.attr("href"), function(data) { self.commentToggler.html(Diaspora.I18n.t("comments.hide")); - self.commentsList.html(data); + self.commentsList + .html(data) + .addClass("loaded") + .removeClass("hidden"); self.instantiateCommentWidgets(); }); diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 3dc102999..4d12999ca 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -86,7 +86,7 @@ describe AspectsController do it 'generates a jasmine fixture with posts', :fixture => true do bob.post(:status_message, :text => "Is anyone out there?", :to => @bob.aspects.first.id) message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id) - 3.times { bob.comment("what", :post => message) } + 5.times { bob.comment("what", :post => message) } get :index save_fixture(html_for("body"), "aspects_index_with_posts") end diff --git a/spec/javascripts/widgets/comment-stream-spec.js b/spec/javascripts/widgets/comment-stream-spec.js index 1a2432119..b367c558b 100644 --- a/spec/javascripts/widgets/comment-stream-spec.js +++ b/spec/javascripts/widgets/comment-stream-spec.js @@ -11,12 +11,9 @@ describe("Diaspora.Widgets.CommentStream", function() { commentStream = Diaspora.BaseWidget.instantiate("CommentStream", $(".stream_element:first .comment_stream")); }); - describe("hideComments", function() { - - }); - describe("toggling comments", function() { it("toggles class hidden on the comments ul", function () { + spyOn($, "ajax"); expect($("ul.comments:first")).not.toHaveClass("hidden"); @@ -28,6 +25,7 @@ describe("Diaspora.Widgets.CommentStream", function() { commentStream.showComments($.Event()); + $.ajax.mostRecentCall.args[0].success("comment response"); jasmine.Clock.tick(200); expect($("ul.comments:first")).not.toHaveClass("hidden"); @@ -53,5 +51,23 @@ describe("Diaspora.Widgets.CommentStream", function() { expect(link.text()).toEqual("show comments translation"); }); + + it("only requests the comments when the loaded class is not present", function() { + spyOn($, "ajax"); + + expect(commentStream.commentsList).not.toHaveClass("loaded"); + + commentStream.showComments($.Event()); + + $.ajax.mostRecentCall.args[0].success("comment response"); + + expect($.ajax.callCount).toEqual(1); + expect(commentStream.commentsList).toHaveClass("loaded"); + + commentStream.showComments($.Event()); + + expect($.ajax.callCount).toEqual(1); + expect(commentStream.commentsList).toHaveClass("loaded"); + }); }); }); \ No newline at end of file