require 'spec_helper'

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

  subject { page }

  before(:all) do
    Capybara.javascript_driver = :poltergeist
    Capybara.current_driver = Capybara.javascript_driver
    Capybara.default_wait_time = 10
  end


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

  before(:each) do
    UserMailer.deliveries.clear
    sign_in_poltergeist user
    visit "/"
    find('h2', text: 'musicians')
    # open menu
    find('.userinfo').trigger(:click)
  end

  describe "Account Home link" do

    before(:each) do
      click_link 'Account Home'
    end

    it { should have_selector('h1',    text: 'my account') }
  end

  describe "Identity link" do

    before(:each) do
      click_link 'Identity'
    end

    it { should have_selector('h2',    text: 'identity:') }
  end

  describe "Profile link" do

    before(:each) do
      click_link 'Profile'
    end

    it { should have_selector('h2',    text: 'profile:') }
  end


  describe "Audio Gear link" do

    before(:each) do
      click_link 'Audio Gear'
    end

    it { should have_selector('h2',    text: 'audio profiles:') }
  end

  describe "Download App link" do

    before(:each) do
      click_link 'Download App'
    end

    it {
      # the download app link opens a new window
      page.driver.window_handles.last
      page.within_window page.driver.window_handles.last do
        should have_selector('h1',    text: 'Downloads')
      end
    }
  end

  describe "invite submenu" do
    before(:each) do
      click_link "Invite Friends"
    end

    describe "Email" do
      before(:each) do
        click_link "Email"
      end

      it {should have_selector('label',    text: 'Enter email address(es). If multiple addresses, separate with commas.')}
    end
  end

end
