require 'spec_helper'

describe 'Fixxpert leave a comment for customer' do
  it 'should fail with empty comment' do
    fixxpert = create :fixxpert
    customer = create :customer

    # Need some comment to allow fixxpert to access to a customer profile
    comment = create :comment, user: customer, for_user: fixxpert
    login_as_user fixxpert

    click_link 'fixxpert_customers_link'
    click_link "show_contacted_customer_#{customer.id}"

    click_button 'post_comment'
    page.should have_content "Can't create the comment"
  end

  it 'should create the comment' do
    fixxpert = create :fixxpert
    customer = create :customer

    # Need some comment to allow fixxpert to access to a customer profile
    comment = create :comment, user: customer, for_user: fixxpert
    login_as_user fixxpert

    click_link 'fixxpert_customers_link'
    click_link "show_contacted_customer_#{customer.id}"

    fill_in 'comment_text', with: 'Comment content'
    click_button 'post_comment'
    page.should have_content 'Comment created'

    within '#comments' do
      page.should have_content 'Comment content'
    end

  end

end
