From 50e67524c1b49f5afa836ee3435f7727a632e8ec Mon Sep 17 00:00:00 2001 From: Dan Hansen Date: Sun, 8 May 2011 15:18:02 -0500 Subject: [PATCH] content update wip --- public/javascripts/content-updates.js | 26 +++++++++++++++++ public/javascripts/web-socket-receiver.js | 20 +------------ spec/controllers/aspects_controller_spec.rb | 2 ++ spec/javascripts/content-updates-spec.js | 32 +++++++++++++++++++++ spec/javascripts/support/jasmine.yml | 1 + 5 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 public/javascripts/content-updates.js create mode 100644 spec/javascripts/content-updates-spec.js diff --git a/public/javascripts/content-updates.js b/public/javascripts/content-updates.js new file mode 100644 index 000000000..55eca2422 --- /dev/null +++ b/public/javascripts/content-updates.js @@ -0,0 +1,26 @@ +/* Copyright (c) 2010, Diaspora Inc. This file is +* licensed under the Affero General Public License version 3 or later. See +* the COPYRIGHT file. +*/ + +var ContentUpdates = { + addPostToStream: function(postId, html) { + if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) { + var streamElement = $(html); + + if($("#no_posts").length) { + $("#no_posts").detach(); + } + + streamElement.prependTo("#main_stream:not('.show')").fadeIn("fast", function() { + streamElement.find("label").inFieldLabels(); + }); + + + Diaspora.widgets.publish("stream/postAdded", [postId]); + + Diaspora.widgets.timeago.updateTimeAgo(); + Diaspora.widgets.directionDetector.updateBinds(); + } + } +}; \ No newline at end of file diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index 505afadfb..64e4c6ba8 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -133,25 +133,7 @@ var WebSocketReceiver = { }, addPostToStream: function(postId, html) { - if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) { - var streamElement = $(html); - - var showMessage = function() { - $("#main_stream:not('.show')").prepend( - streamElement.fadeIn("fast", function() { - streamElement.find("label").inFieldLabels(); - }) - ); - }; - - if( $("#no_posts").is(":visible") ) { - $("#no_posts").fadeOut(400, showMessage()).hide(); - } else { - showMessage(); - } - Diaspora.widgets.timeago.updateTimeAgo(); - Diaspora.widgets.directionDetector.updateBinds(); - } + }, onPageForClass: function(className) { diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 9923d99e8..95d65af7a 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -68,6 +68,8 @@ describe AspectsController do bob.comment("what", :on => message) get :index save_fixture(html_for("body"), "aspects_index_with_posts") + + save_fixture(html_for(".stream_element:first"), "status_message_in_stream") end context 'with getting_started = true' do diff --git a/spec/javascripts/content-updates-spec.js b/spec/javascripts/content-updates-spec.js new file mode 100644 index 000000000..eea6abecf --- /dev/null +++ b/spec/javascripts/content-updates-spec.js @@ -0,0 +1,32 @@ +/* Copyright (c) 2010, Diaspora Inc. This file is +* licensed under the Affero General Public License version 3 or later. See +* the COPYRIGHT file. +*/ +describe("ContentUpdates", function() { + describe("addPostToStream", function() { + beforeEach(function() { + $("#jasmine_content").empty(); + spec.loadFixture("aspects_index_with_posts"); + }); + + it("adds a post to the stream", function() { + var originalPostCount = $(".stream_element").length; + ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); + expect($(".stream_element").length).toBeGreaterThan(originalPostCount); + }); + + it("does not add duplicate posts", function() { + ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); + var originalPostCount = $(".stream_element").length; + ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); + expect($(".stream_element").length).toEqual(originalPostCount); + }); + + it("removes the div that says you have no posts if it exists", function() { + spec.loadFixture("aspects_index"); + expect($("#no_posts").length).toEqual(1); + ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream")); + expect($("#no_posts").length).toEqual(0); + }); + }); +}); diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index dd353c96f..9f56fb62b 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -40,6 +40,7 @@ src_files: - public/javascripts/validation.js - public/javascripts/rails.js - public/javascripts/aspect-filters.js + - public/javascripts/content-updates.js # stylesheets # # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.