From 0873ad5828dd515ea01adb67647dc749d51b348c Mon Sep 17 00:00:00 2001 From: Raphael Sofaer <raphael@joindiaspora.com> Date: Fri, 29 Jul 2011 17:01:45 -0700 Subject: [PATCH] Test and fix contacts index page --- features/manages_aspects.feature | 11 ++++++++ features/step_definitions/custom_web_steps.rb | 6 ++++- features/step_definitions/user_steps.rb | 25 +++++++++++++++++++ public/javascripts/widgets/infinite-scroll.js | 25 +++++++++++-------- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/features/manages_aspects.feature b/features/manages_aspects.feature index af918bf471..aaec948271 100644 --- a/features/manages_aspects.feature +++ b/features/manages_aspects.feature @@ -35,3 +35,14 @@ Feature: User manages contacts And I wait for the ajax to finish Then I should have 0 contacts in "Cat People" + Scenario: scrolling through contacts index + Given I am signed in + And I have 60 contacts + And I am on the contacts page + Then I should see 25 contacts + + When I scroll down + Then I should see 50 contacts + + When I scroll down + Then I should see 60 contacts diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 8233da35e8..bf895dff91 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -167,6 +167,10 @@ Then /^I should see (\d+) posts$/ do |n_posts| wait_until(10) { all("#main_stream .stream_element").length == n_posts.to_i } end +Then /^I should see (\d+) contacts$/ do |n_posts| + wait_until(10) { all("#people_stream .stream_element").length == n_posts.to_i } +end + And /^I scroll down$/ do evaluate_script("window.scrollBy(0,3000000)") sleep 1 @@ -189,4 +193,4 @@ When /^I resize my window to 800x600$/ do page.execute_script <<-JS window.resizeTo(800,600); JS -end \ No newline at end of file +end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 797ea99e95..6666a54a68 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -167,3 +167,28 @@ end Then /^my "([^\"]*)" should be "([^\"]*)"$/ do |field, value| @me.reload.send(field).should == value end + +Given /^I have (\d+) contacts$/ do |n| + count = n.to_i - @me.contacts.count + + people = [] + contacts = [] + aspect_memberships = [] + + count.times do + person = Factory.create(:person) + people << person + end + + people.each do |person| + contacts << Contact.new(:person_id => person.id, :user_id => @me.id, :sharing => true, :receiving => true) + end + Contact.import(contacts) + contacts = @me.contacts.limit(n.to_i) + + aspect_id = @me.aspects.first.id + contacts.each do |contact| + aspect_memberships << AspectMembership.new(:contact_id => contact.id, :aspect_id => @me.aspects.first.id) + end + AspectMembership.import(aspect_memberships) +end diff --git a/public/javascripts/widgets/infinite-scroll.js b/public/javascripts/widgets/infinite-scroll.js index 86e0548c70..721c547583 100644 --- a/public/javascripts/widgets/infinite-scroll.js +++ b/public/javascripts/widgets/infinite-scroll.js @@ -29,21 +29,24 @@ this.reInitialize = function() { self.clear(); - self.initialize(); + self.initialize(); }; this.initialize = function() { if($('#main_stream').length !== 0){ - $('#main_stream').infinitescroll(this.options, function() { - Diaspora.widgets.publish("stream/scrolled"); - }); - } else if($('#people_stream.contacts').length !== 0){ - $("#people_stream.contacts").infinitescroll($.extend(self.options, { - navSelector : ".pagination", - nextSelector : ".next_page", - }), function() { - Diaspora.widgets.publish("stream/scrolled"); - }); + $('#main_stream').infinitescroll(this.options, function() { + Diaspora.widgets.publish("stream/scrolled"); + }); + } else if($('#people_stream').length !== 0){ + $("#people_stream").infinitescroll($.extend(self.options, { + navSelector : ".pagination", + nextSelector : ".next_page", + pathParse : function( pathStr, nextPage){ + return pathStr.replace("page=2", "page=" + nextPage); + } + }), function() { + Diaspora.widgets.publish("stream/scrolled"); + }); } }; -- GitLab