require 'spec_helper'

describe "Teacher Landing", :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, country: 'US') }


  it "logged out" do
    visit "/landing/jamclass/teachers"

    find('h1.jam-track-name', 'JAMCLASS')
    find('h2.original-artist', 'Finally, online music lessons that really work!')

    find('button.cta-button', text: 'Sign Up').trigger(:click)

    # should fail because we haven't filled out email/password/terms
    find('.register-area .errors', text: "Email can't be blank")

    fill_in "email",    with: 'teacher_123@jamkazam.com'
    fill_in "password",    with: 'jam123'
    find('.register-area ins', visible: false).trigger(:click)
    find('button.cta-button', text: 'Sign Up').trigger(:click)

    # this should show on the /client#/home page (WILL CHANGE)
    find('h2', text: 'edit teacher profile: introduction')

    user = User.find_by_email('teacher_123@jamkazam.com')
    user.is_a_student.should be false
    user.is_a_teacher.should be true
    user.musician.should be true
    user.school_interest.should be false
  end

  it "logged in" do
    fast_signin(user,"/landing/jamclass/teachers")

    find('h1.jam-track-name', 'JAMCLASS')
    find('h2.original-artist', 'Finally, online music lessons that really work!')

    find('button.cta-button', text: 'Enter Teacher Profile').trigger(:click)

    # this should show on the /client#/home page (WILL CHANGE)
    find('h2', text: 'edit teacher profile: introduction')

    user.reload
    user.is_a_student.should be false
    user.is_a_teacher.should be true
    user.musician.should be true
    user.school_interest.should be false
  end

end
