Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen van Bergerem committed Aug 25, 2014
1 parent 2cb1bde commit f14e013
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 130 deletions.
14 changes: 12 additions & 2 deletions app/assets/javascripts/app/views/contacts_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ app.views.Contacts = Backbone.View.extend({
"click #change_aspect_name" : "showAspectNameForm",
"click .contact_remove-from-aspect" : "removeContactFromAspect",
"click .contact_add-to-aspect" : "addContactToAspect",
"focusin #contact_list_search" : "expandSearchInput",
"focusout #contact_list_search" : "shrinkSearchInput",
"keyup #contact_list_search" : "searchContactList"
},

Expand Down Expand Up @@ -65,7 +67,7 @@ app.views.Contacts = Backbone.View.extend({
.addClass("contact_remove-from_aspect").addClass("circled-cross")
.attr('title', Diaspora.I18n.t('contacts.add_contact'))
.tooltip()
.closest('.stream_element').removeClass('not_in_aspect');
.closest('.stream_element').addClass('in_aspect');
},
error: function(model,response){
alert("SAVE ERROR " + JSON.stringify(model));
Expand All @@ -88,14 +90,22 @@ app.views.Contacts = Backbone.View.extend({
.addClass("contact_add-to_aspect").addClass("circled-plus")
.attr('title', Diaspora.I18n.t('contacts.add_contact'))
.tooltip()
.closest('.stream_element').addClass('not_in_aspect');
.closest('.stream_element').removeClass('in_aspect');
},
error: function(model,response){
alert("DESTROY ERROR " + JSON.stringify(model));
}
});
},

expandSearchInput: function(){
$('#contact_list_search').animate({width: '250px'},100);
},

shrinkSearchInput: function(){
$('#contact_list_search').animate({width: '150px'},100);
},

searchContactList: function(e) {
var query = new RegExp($(e.target).val(),'i');

Expand Down
13 changes: 7 additions & 6 deletions app/assets/stylesheets/contacts.css.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#contacts_container {
#people_stream.contacts {
.header {
.header {
border-bottom: 1px solid $border-grey;
margin-top: 10px;
min-height: 53px;
#change_aspect_name { cursor: pointer; }
#aspect_name_form {
#aspect_name_form {
display: none;
form { margin: 0px; }
input {
input {
margin-bottom: 0px;
margin-top: 10px;
}
Expand All @@ -18,7 +18,7 @@
margin: 6px 30px 0 0;
width: 150px;
}
& > a, #aspect_controls > a {
& > a, #aspect_controls > a {
text-decoration: none;
margin-right: 25px;
}
Expand All @@ -42,9 +42,10 @@
&:hover { color: $black; }
}

&.not_in_aspect { background-color: $background-grey; }
&:not(.in_aspect) { border-left: 3px solid $white; }
&.in_aspect { border-left: 3px solid $green; }
}

.no_contacts {
text-align: center;
margin-top: 50px;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/people.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.btn-group.aspect_membership_dropdown { margin: 12px 0; }
.thats_you {
line-height: 50px;
margin-right: 20px;
margin-right: 10px;
}
.info { font-size: 11px; }
}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/aspects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def toggle_contact_visibility
@aspect.contacts_visible = true
end
@aspect.save
render :nothing => true
end

private
Expand Down
51 changes: 31 additions & 20 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,40 @@ def spotlight
private

def set_up_contacts
c = Contact.arel_table
@contacts = case params[:set]
when "only_sharing"
current_user.contacts.only_sharing.to_a.sort_by { |c| c.person.name }
type = params[:set].presence
type ||= "by_aspect" if params[:a_id].present?
type ||= "receiving"

@contacts = contacts_by_type(type)
@contacts_size = @contacts.length
end

def contacts_by_type(type)
contacts = case type
when "all"
current_user.contacts.to_a.sort_by { |c| c.person.name }
[current_user.contacts]
when "only_sharing"
[current_user.contacts.only_sharing]
when "receiving"
[current_user.contacts.receiving]
when "by_aspect"
@aspect = current_user.aspects.find(params[:a_id])
@contacts_in_aspect = @aspect.contacts
@contacts_not_in_aspect = current_user.contacts.where.not(contacts: {id: @contacts_in_aspect.pluck(:id) })
[@contacts_in_aspect, @contacts_not_in_aspect].map {|relation|
relation.includes(:aspect_memberships)
}
else
if params[:a_id]
@aspect = current_user.aspects.find(params[:a_id])
@contacts_in_aspect = @aspect.contacts.includes(:aspect_memberships, :person => :profile).to_a.sort_by { |c| c.person.name }
if @contacts_in_aspect.empty?
@contacts_not_in_aspect = current_user.contacts.includes(:aspect_memberships, :person => :profile).to_a.sort_by { |c| c.person.name }
else
@contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:aspect_memberships, :person => :profile).to_a.sort_by { |c| c.person.name }
end
@contacts_in_aspect + @contacts_not_in_aspect
else
current_user.contacts.receiving.to_a.sort_by { |c| c.person.name }
end
end
@contacts_size = @contacts.length
raise ArgumentError, "unknown type #{type}"
end

contacts.map {|relation|
relation.includes(:person => :profile).to_a.tap {|contacts|
contacts.sort_by! {|contact| contact.person.name }
}
}.inject(:+)
end

def set_up_contacts_mobile
@contacts = case params[:set]
when "only_sharing"
Expand Down
2 changes: 1 addition & 1 deletion app/views/contacts/_contact.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- membership = contact.aspect_memberships.where(:aspect_id => @aspect.id).first unless @aspect.nil?
.media.stream_element{:id => contact.person_id, :class => ("not_in_aspect" unless membership)}
.media.stream_element{:id => contact.person_id, :class => ("in_aspect" if membership)}
.pull-right
= contact_aspect_dropdown(contact)
.media-object.pull-left
Expand Down
2 changes: 1 addition & 1 deletion app/views/contacts/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-else
%i.entypo.lock.contacts-header-icon{:title => t('aspects.edit.aspect_list_is_not_visible')}

= link_to @aspect, method: "delete", data: { confirm: t('aspects.edit.confirm_remove_aspect') }, class: 'delete' do
= link_to @aspect, method: "delete", data: { confirm: t('aspects.edit.confirm_remove_aspect') }, class: 'delete', id: 'delete_aspect' do
%i.entypo.trash.contacts-header-icon{:title => t('delete')}
.pull-right
= search_field_tag :contact_search, "", id: "contact_list_search", placeholder: t('contacts.index.user_search')
Expand Down
4 changes: 1 addition & 3 deletions features/desktop/contacts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ Feature: show contacts
And I add the person to my "Unicorns" aspect
And I am on the contacts page
And I follow "Unicorns"
And I follow "Manage"
And I press the first "a.contact_visibility_link" in the modal window
And I press "Done" in the modal window
And I press the first "a#contacts_visibility_toggle"
And I sign out

And I sign in as "alice@alice.alice"
Expand Down
31 changes: 9 additions & 22 deletions features/desktop/manages_aspects.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,42 @@ Feature: User manages contacts
And I have an aspect called "People"
When I am on the contacts page
And I follow "People"
And I follow "add contacts to People"
And I press "Delete" in the modal window
And I click on selector "#delete_aspect"
And I confirm the alert
Then I should be on the contacts page
And I should not see "People" within "#aspects_list"
And I should not see "People" within "#aspect_nav"

Scenario: deleting an aspect from homepage
Given I am signed in
And I have an aspect called "People"
When I am on the aspects page
And I click on "People" aspect edit icon
And I follow "Delete" within "#aspect_controls"
And I click on selector "#delete_aspect"
And I confirm the alert
Then I should be on the contacts page
And I should not see "People" within "#aspects_list"
And I should not see "People" within "#aspect_nav"

Scenario: Editing the aspect memberships of a contact from the aspect edit facebox
Scenario: Editing the aspect memberships of a contact from the contacts page
Given I am signed in
And I have 2 contacts
And I have an aspect called "Cat People"
When I am on the contacts page
And I follow "Cat People"
And I follow "add contacts to Cat People"
And I check the first contact list button
And I add the first person to the aspect
Then I should have 1 contact in "Cat People"

When I uncheck the first contact list button
When I remove the first person from the aspect
Then I should have 0 contacts in "Cat People"

Scenario: Renaming an aspect
Given I am signed in
And I have an aspect called "Cat People"
When I am on the contacts page
And I follow "Cat People"
And I follow "Manage" within "#aspect_controls"
And I follow "rename"
And I click on selector "#change_aspect_name"
And I fill in "aspect_name" with "Unicorn People"
And I press "update"
Then I should see "Unicorn People" within "#aspect_name_title"

Scenario: infinite scroll on contacts index
Given I am signed in
And I resize my window to 800x600
And I have 30 contacts
And I am on the contacts page
Then I should see 25 contacts

When I scroll down
Then I should see 30 contacts
Then I should see "Unicorn People" within "#aspect_name"

Scenario: clicking on the contacts link in the header with zero contacts directs a user to the featured users page
Given I am signed in
Expand Down
5 changes: 2 additions & 3 deletions features/desktop/stops_following_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ Feature: Unfollowing

Then I should not see "is sharing with you."

Scenario: stop following someone while on the aspect edit page
Scenario: stop following someone while on the contacts page
When I go to the home page
And I go to the contacts page

And I follow "Besties"
And I follow "Manage"

And I press the first ".added" within "#facebox .contact_list ul > li:first-child"
And I remove the first person from the aspect

When I follow "My Contacts"
Then I should have 0 contacts in "Besties"
Expand Down
15 changes: 8 additions & 7 deletions features/step_definitions/aspects_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ def aspect_dropdown_visible?
step %Q(I should see "#{aspect_name}" aspect selected)
end

When /^I check the first contact list button$/ do
find(".contact_list .btn", match: :first).tap do |button|
When /^I add the first person to the aspect$/ do
find(".contact_add-to-aspect", match: :first).tap do |button|
button.click
button.parent.should have_css ".added"
button.should have_css ".contact_remove-from-aspect"
end
end

When /^I uncheck the first contact list button$/ do
find(".contact_list .btn", match: :first).tap do |button|
When /^I remove the first person from the aspect$/ do
find(".contact_remove-from-aspect", match: :first).tap do |button|
button.click
button.parent.should have_css ".add"
sleep 1 # The expectation above should wait for the request to finsh, but that doesn't work for some reason
button.should have_css ".contact_add-to-aspect"
# let's see if it works without that step
#sleep 1 # The expectation above should wait for the request to finsh, but that doesn't work for some reason
end
end

Expand Down
49 changes: 2 additions & 47 deletions spec/controllers/aspects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,65 +112,20 @@
end
end

describe '#edit' do
before do
eve.profile.first_name = eve.profile.last_name = nil
eve.profile.save
eve.save

@zed = FactoryGirl.create(:user_with_aspect, :username => "zed")
@zed.profile.first_name = "zed"
@zed.profile.save
@zed.save
@katz = FactoryGirl.create(:user_with_aspect, :username => "katz")
@katz.profile.first_name = "katz"
@katz.profile.save
@katz.save

connect_users(alice, @alices_aspect_2, eve, eve.aspects.first)
connect_users(alice, @alices_aspect_2, @zed, @zed.aspects.first)
connect_users(alice, @alices_aspect_1, @katz, @katz.aspects.first)
end

it 'renders' do
get :edit, :id => @alices_aspect_1.id
response.should be_success
end

it 'assigns the contacts in alphabetical order with people in aspects first' do
get :edit, :id => @alices_aspect_2.id
assigns[:contacts].map(&:id).should == [alice.contact_for(eve.person), alice.contact_for(@zed.person), alice.contact_for(bob.person), alice.contact_for(@katz.person)].map(&:id)
end

it 'assigns all the contacts if noone is there' do
alices_aspect_3 = alice.aspects.create(:name => "aspect 3")

get :edit, :id => alices_aspect_3.id
assigns[:contacts].map(&:id).should == [alice.contact_for(bob.person), alice.contact_for(eve.person), alice.contact_for(@katz.person), alice.contact_for(@zed.person)].map(&:id)
end

it 'eager loads the aspect memberships for all the contacts' do
get :edit, :id => @alices_aspect_2.id
assigns[:contacts].each do |c|
c.aspect_memberships.loaded?.should be_true
end
end
end

describe "#toggle_contact_visibility" do
it 'sets contacts visible' do
@alices_aspect_1.contacts_visible = false
@alices_aspect_1.save

xhr :get, :toggle_contact_visibility, :format => 'js', :aspect_id => @alices_aspect_1.id
xhr :get, :toggle_contact_visibility, :aspect_id => @alices_aspect_1.id
@alices_aspect_1.reload.contacts_visible.should be_true
end

it 'sets contacts hidden' do
@alices_aspect_1.contacts_visible = true
@alices_aspect_1.save

xhr :get, :toggle_contact_visibility, :format => 'js', :aspect_id => @alices_aspect_1.id
xhr :get, :toggle_contact_visibility, :aspect_id => @alices_aspect_1.id
@alices_aspect_1.reload.contacts_visible.should be_false
end
end
Expand Down
17 changes: 0 additions & 17 deletions spec/controllers/contacts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@
@controller.stub(:current_user).and_return(bob)
end

describe '#sharing' do
it "succeeds" do
get :sharing
response.should be_success
end

it 'eager loads the aspects' do
get :sharing
assigns[:contacts].first.aspect_memberships.loaded?.should be_true
end

it "assigns only the people sharing with you with 'share_with' flag" do
get :sharing, :id => 'share_with'
assigns[:contacts].to_set.should == bob.contacts.sharing.to_set
end
end

describe '#index' do
context 'format mobile' do
it "succeeds" do
Expand Down

0 comments on commit f14e013

Please sign in to comment.