require 'spec_helper'

describe "Profile Menu", :js => true, :type => :feature, :capybara_feature => true  do

  subject { page }

  let(:user) { FactoryGirl.create(:user) }
  let(:user2) { FactoryGirl.create(:user) }

  before(:each) do
    UserMailer.deliveries.clear
    sign_in_poltergeist user
    visit "/client"
    find('h2', text: 'musicians')
  end

  describe "Invite more Users" do

    before(:each) do
      find('.sidebar .invite-friend-row').hover
      find('.sidebar .invitation-button-holder')
    end

    it { should have_selector('.friend-name',    text: 'Invite More Friends') }

    describe "try to invite" do
      before(:each) do
        find('.sidebar .btn-email-invitation').trigger(:click)
      end
      it {should have_selector('label',    text: 'Enter email address(es). If multiple addresses, separate with commas.')}
    end
  end

  describe "panel behavior" do
    it "search, then click notifications" do

      user.reload
      
      notification = Notification.send_text_message("text message", user2, user)
      notification.errors.any?.should be false

      site_search(user2.name, validate: user2)

      open_notifications

      find("#sidebar-notification-list li[notification-id='#{notification.id}']")
    end
  end


end
