require 'spec_helper'

describe 'Customer show fixxpert' do


  it 'should show fixxpert details' do
    fixxpert = create :fixxpert
    customer = create :customer

    login_as_user customer
    click_link 'Fixxpert'
    click_link 'Find a fixxpert'
    click_link "show_fixxpert_#{fixxpert.id}"
    page.should have_content fixxpert.name
  end


  it 'should show all the interactions between the user and the fixxpert' do
    fixxpert = create :fixxpert
    customer = create :customer
    other_fixxpert = create :fixxpert
    comment_1 = create :comment, user: customer, for_user: fixxpert, text: 'For customer to fixxpert'
    comment_2 = create :comment, user: fixxpert, for_user: customer, text: 'For fixxpert to customer'

    other_comment_1 = create :comment, user: customer, for_user: other_fixxpert, text: 'For customer to other fixxpert'
    other_comment_2 = create :comment, user: other_fixxpert, for_user: customer, text: 'For other fixxpert to customer'

    expert_session = create :expert_session, fixxpert: fixxpert, customer: customer
    invoice = create :invoice, expert_session: expert_session, customer: customer, fixxpert: fixxpert
    subtrade = create :subtrade
    review = create :review, user: customer, for_user: fixxpert, text: 'Customer review for fixxpert', subtrade: subtrade
    other_review = create :review, for_user: fixxpert, user: create(:customer), subtrade: subtrade

    login_as_user customer
    click_link 'Fixxpert'
    click_link 'Find a fixxpert'
    click_link "show_fixxpert_#{fixxpert.id}"

    within '#comments' do
      page.should have_content comment_1.text
      page.should have_content comment_2.text

      page.should_not have_content other_comment_1.text
      page.should_not have_content other_comment_2.text
    end

    within '#expert_sessions_upcoming' do
      page.should have_content expert_session.date.strftime("%m-%d-%Y")
    end

    within '#invoices_pending' do
      page.should have_content I18n.l invoice.created_at.to_date
    end

    within '#customer_review' do
      page.should have_content review.text
    end

    within '#reviews' do
      page.should have_content other_review.text
    end
  end

end

describe 'Visitor view fixxpert' do
  it 'should show fixxpert details' do
    fixxpert = create :fixxpert
    subtrade = create :subtrade
    review = create :review, user: create(:customer), for_user: fixxpert, subtrade: subtrade
    visit root_path
    click_button 'submit_customer_fixxperts_search'
    click_link "show_fixxpert_#{fixxpert.id}"
    page.should have_content fixxpert.name

    within '#reviews' do
      page.should have_content review.text
    end
  end
end
