Red feature for infinite scroll after changing aspects

This commit is contained in:
Raphael Sofaer 2011-04-26 17:28:42 -07:00
parent 24ea518b6f
commit 2517653d34
6 changed files with 79 additions and 25 deletions

View file

@ -0,0 +1,24 @@
@javascript
Feature: infinite scroll
In order to browse without disruption
As medium-sized internet grazing animal
I want the stream to infinite scroll
Background:
Given many posts from bob and alice
Scenario: on the main stream
When I sign in as "bob@bob.bob"
Then I should see 15 posts
When I scroll down
And I wait for the ajax to finish
Then I should see 30 posts
When I follow "generic"
And I wait for the ajax to finish
Then I should see 15 posts
When I scroll down
And I wait for the ajax to finish
Then I should see 30 posts

View file

@ -188,3 +188,11 @@ Then /^the "([^"]*)" field(?: within "([^"]*)")? should be filled with "([^"]*)"
end
end
end
Then /^I should see (\d+) posts$/ do |n_posts|
evaluate_script("$('#main_stream .stream_element').length").should == n_posts.to_i
end
And /^I scroll down$/ do
visit('#footer_nav')
end

View file

@ -139,3 +139,19 @@ Given /^there is a user "([^\"]*)" who's tagged "([^\"]*)"$/ do |full_name, tag|
user.profile.build_tags
user.profile.save!
end
Given /^many posts from bob and alice$/ do
alice = Factory(:user_with_aspect, :username => 'alice', :email => 'alice@alice.alice', :password => 'password', :getting_started => false)
bob = Factory(:user_with_aspect, :username => 'bob', :email => 'bob@bob.bob', :password => 'password', :getting_started => false)
connect_users_with_aspects(alice, bob)
time_interval = 1000
(1..20).each do |n|
[alice, bob].each do |u|
post = u.post :status_message, :text => "#{u.username} - #{n} - #seeded", :to => u.aspects.first.id
post.created_at = post.created_at - time_interval
post.updated_at = post.updated_at - time_interval
post.save
time_interval += 1000
end
end
end

View file

@ -43,6 +43,7 @@ require File.join(File.dirname(__FILE__), "database_cleaner_patches")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_redis")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods")
include HelperMethods
Before do
@ -52,6 +53,8 @@ end
silence_warnings do
SERVICES['facebook'] = {'app_id' => :fake}
end
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_resque")
module Resque
def enqueue(klass, *args)
klass.send(:perform, *args)

View file

@ -4,32 +4,34 @@
*/
(function() {
var InfiniteScroll = function() {
this.options = {
navSelector : "#pagination",
nextSelector : ".paginate",
itemSelector : ".stream_element",
pathParse : function( pathStr, nextPage ){
var newPath = pathStr.replace("?", "?only_posts=true&");
var last_time = $('#main_stream .stream_element').last().find('.time').attr('integer');
return newPath.replace( /max_time=\d+/, 'max_time=' + last_time);
},
bufferPx: 500,
debug: false,
donetext: Diaspora.widgets.i18n.t("infinite_scroll.no_more"),
loadingText: "",
loadingImg: '/images/ajax-loader.gif'
};
this.start = function() {
Diaspora.widgets.subscribe("stream/reloaded", InfiniteScroll.initialize);
$('#main_stream').infinitescroll(this.options, function() {
Diaspora.widgets.publish("stream/scrolled");
});
};
var InfiniteScroll = function() { };
InfiniteScroll.prototype.options = {
navSelector : "#pagination",
nextSelector : ".paginate",
itemSelector : ".stream_element",
pathParse : function( pathStr, nextPage ){
var newPath = pathStr.replace("?", "?only_posts=true&");
var last_time = $('#main_stream .stream_element').last().find('.time').attr('integer');
return newPath.replace( /max_time=\d+/, 'max_time=' + last_time);
},
bufferPx: 500,
debug: false,
donetext: Diaspora.widgets.i18n.t("infinite_scroll.no_more"),
loadingText: "",
loadingImg: '/images/ajax-loader.gif'
};
Diaspora.widgets.add("infinitescroll", InfiniteScroll)
InfiniteScroll.prototype.initialize = function(){
$('#main_stream').infinitescroll(this.options, function() {
Diaspora.widgets.publish("stream/scrolled");
});
};
InfiniteScroll.prototype.start = function() {
Diaspora.widgets.subscribe("stream/reloaded", this.initialize);
this.initialize();
};
Diaspora.widgets.add("infinitescroll", InfiniteScroll);
})();

View file

@ -7,6 +7,7 @@ Diaspora.widgets.add("timeago", function() {
this.selector = "abbr.timeago";
this.start = function() {
Diaspora.widgets.subscribe("stream/scrolled", this.updateTimeAgo);
Diaspora.widgets.subscribe("stream/reloaded", this.updateTimeAgo);
if(Diaspora.widgets.i18n.language !== "en") {
$.each($.timeago.settings.strings, function(index, element) {