require 'spec_helper'

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

  subject { page }

  before(:all) do
    Capybara.default_max_wait_time = 15
  end

  let(:fan) { FactoryGirl.create(:fan) }
  let(:user) { FactoryGirl.create(:user) }
  let(:finder) { FactoryGirl.create(:user) }
  let(:claimed_recording) { FactoryGirl.create(:claimed_recording) }

  before(:each) do
    UserMailer.deliveries.clear
  end

  def navigate_musician_setup login=user
    sign_in_poltergeist(login) if current_url == 'about:blank'
    find('div.homecard.profile').trigger(:click)  
  end

  it "Basic Test" do
    navigate_musician_setup
    #save_screenshot("setup.png")
    expect(page).to have_selector('#user-profile', visible: true)
    expect(page).to have_selector('.no-samples', visible: true)
  end


  it "shows Online Presence" do

    OnlinePresence.create!({:player_id => user.id, :username => "myonlineusername", :service_type => "facebook"})
    OnlinePresence.create!({:player_id => user.id, :username => "myonlineusername", :service_type => "twitter"})
    OnlinePresence.create!({:player_id => user.id, :username => "myonlineusername", :service_type => "soundcloud"})

    navigate_musician_setup
    expect(page).to have_selector('.no-samples', visible: true)
    expect(page).to have_selector('.facebook-presence', visible: true)
    expect(page).to have_selector('.soundcloud-presence', visible: true)
    expect(page).to have_selector('.twitter-presence', visible: true)

  end

  it "shows Performance Samples" do
    PerformanceSample.create!(:player_id => user.id, :service_type => "jamkazam", :claimed_recording_id => claimed_recording.id)
    PerformanceSample.create!(:player_id => user.id, :service_type => "soundcloud", :service_id => "67890")
    PerformanceSample.create!(:player_id => user.id, :service_type => "soundcloud", :service_id => "67891")

    navigate_musician_setup
    expect(page).to have_selector('.jamkazam-playable', count: 1)
    expect(page).to have_selector('.twitter-playable', count: 0)
    expect(page).to have_selector('.sound-cloud-playable', count: 2)

    expect(page).to have_selector('.facebook-presence', visible: true)
    expect(page).to have_selector('.soundcloud-presence', visible: true)
    expect(page).to have_selector('.twitter-presence', visible: true)
  end

end