require 'spec_helper'

describe "Individual JamTrack Band", :js => true, :type => :feature, :capybara_feature => true do

  subject { page }

  before(:all) do
    ShoppingCart.delete_all
    JamTrackRight.delete_all
    JamTrack.delete_all
    JamTrackTrack.delete_all
    JamTrackLicensor.delete_all
  end

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



  before(:all) do
    @jamtrack_acdc_backinblack = FactoryGirl.create(:jam_track, name: 'Back in Black', original_artist: 'AC/DC', sales_region: 'United States', make_track: true, plan_code: 'jamtrack-acdc-backinblack')
 end


  describe "AC/DC Back in Black" do

    it "logged out" do
      visit "/landing/jamtracks/band/acdc-backinblack"

      find('.jamtrack_band', text: @jamtrack_acdc_backinblack.original_artist)
      jamtrack_acdc_backinblack.jam_track_tracks.each do |track|
        if track.master?
          find('.jam-track-preview-holder[data-id="' + track.id + '"] img.instrument-icon[data-instrument-id="other"]')
          find('.jam-track-preview-holder[data-id="' + track.id + '"] .instrument-name', text:'Master Mix')
        else
          find('.jam-track-preview-holder[data-id="' + track.id + '"] img.instrument-icon[data-instrument-id="' + track.instrument.id + '"]')
          find('.jam-track-preview-holder[data-id="' + track.id + '"] .instrument-name', text:track.instrument.description)
        end
      end
      find('a.cta-free-jamtrack')['href'].should eq("/client?artist=#{jamtrack_acdc_backinblack.original_artist}#/jamtrackBrowse")
      find('a.browse-jamtracks')['href'].should eq("/client?artist=#{jamtrack_acdc_backinblack.original_artist}#/jamtrackBrowse")

      find('a.browse-jamtracks').trigger(:click)
      find('h1', text: 'jamtracks')
    end

    it "logged in" do
      fast_signin(user, "/landing/jamtracks/band/acdc-backinblack")

      find('.jamtrack_band', text: @jamtrack_acdc_backinblack.original_artist)
      jamtrack_acdc_backinblack.jam_track_tracks.each do |track|
        if track.master?
          find('.jam-track-preview-holder[data-id="' + track.id + '"] img.instrument-icon[data-instrument-id="other"]')
          find('.jam-track-preview-holder[data-id="' + track.id + '"] .instrument-name', text:'Master Mix')
        else
          find('.jam-track-preview-holder[data-id="' + track.id + '"] img.instrument-icon[data-instrument-id="' + track.instrument.id + '"]')
          find('.jam-track-preview-holder[data-id="' + track.id + '"] .instrument-name', text:track.instrument.description)
        end
      end
      find('a.cta-free-jamtrack')['href'].should eq("/client?artist=#{jamtrack_acdc_backinblack.original_artist}#/jamtrackBrowse")
      find('a.browse-jamtracks')['href'].should eq("/client?artist=#{jamtrack_acdc_backinblack.original_artist}#/jamtrackBrowse")

      find('a.browse-jamtracks').trigger(:click)
      find('h1', text: 'jamtracks')
    end
  end
end
