require 'spec_helper'

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

  subject { page }

  before(:all) do
    Capybara.javascript_driver = :poltergeist
    Capybara.current_driver = Capybara.javascript_driver
    Capybara.default_max_wait_time = 10
  end

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

  before(:each) do
    UserMailer.deliveries.clear
    sign_in_poltergeist user
    visit "/client#/account/profile/avatar"

    find('#account-edit-avatar-upload')
    # within_frame 'filepicker_dialog' do
    #   attach_file '#fileUploadInput', Rails.root.join('spec', 'files', 'avatar.jpg')
    # end
  end

  it {
    should have_selector('#account-edit-avatar-upload')

    # this causes capybara 1.9.0 and 1.9.2 to crash.
    #click_link "UPLOAD"  # launch filepicker dialog, which is an iframe
    #within_frame('filepicker_dialog') {
    #  attach_file('fileUpload', 'spec/assets/images/sample_avatar.png')
    #  find('div.jcrop-tracker').should_not be_nil
    #}
  }
end
