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

View file

@ -4,8 +4,8 @@
*/ */
(function() { (function() {
var InfiniteScroll = function() { var InfiniteScroll = function() { };
this.options = { InfiniteScroll.prototype.options = {
navSelector : "#pagination", navSelector : "#pagination",
nextSelector : ".paginate", nextSelector : ".paginate",
itemSelector : ".stream_element", itemSelector : ".stream_element",
@ -21,15 +21,17 @@
loadingImg: '/images/ajax-loader.gif' loadingImg: '/images/ajax-loader.gif'
}; };
this.start = function() { InfiniteScroll.prototype.initialize = function(){
Diaspora.widgets.subscribe("stream/reloaded", InfiniteScroll.initialize);
$('#main_stream').infinitescroll(this.options, function() { $('#main_stream').infinitescroll(this.options, function() {
Diaspora.widgets.publish("stream/scrolled"); Diaspora.widgets.publish("stream/scrolled");
}); });
}; };
InfiniteScroll.prototype.start = function() {
Diaspora.widgets.subscribe("stream/reloaded", this.initialize);
this.initialize();
}; };
Diaspora.widgets.add("infinitescroll", InfiniteScroll) Diaspora.widgets.add("infinitescroll", InfiniteScroll);
})(); })();

View file

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