content update wip

This commit is contained in:
Dan Hansen 2011-05-08 15:18:02 -05:00
parent fc25c9bedb
commit 50e67524c1
5 changed files with 62 additions and 19 deletions

View file

@ -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();
}
}
};

View file

@ -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) {

View file

@ -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

View file

@ -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);
});
});
});

View file

@ -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.