summaryrefslogtreecommitdiff
path: root/spec/features/uploads/user_uploads_avatar_to_profile_spec.rb
blob: 48f8b8bf77e3af23159d59a1cfadeed028642bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'rails_helper'

describe 'User uploads avatar to profile' do
  let!(:user) { create(:user) }
  let(:avatar_file_path) { Rails.root.join('spec', 'fixtures', 'dk.png') }

  before do
    sign_in user
    visit profile_path
  end

  it 'they see their new avatar on their profile' do
    attach_file('user_avatar', avatar_file_path, visible: false)
    click_button 'Update profile settings'

    visit user_path(user)

    expect(page).to have_selector(%Q(img[data-src$="/uploads/-/system/user/avatar/#{user.id}/dk.png?width=90"]))

    # Cheating here to verify something that isn't user-facing, but is important
    expect(user.reload.avatar.file).to exist
  end

  it 'their new avatar is immediately visible in the header', :js do
    find('.js-user-avatar-input', visible: false).set(avatar_file_path)

    click_button 'Set new profile picture'
    click_button 'Update profile settings'

    wait_for_all_requests

    data_uri = find('.avatar-image .avatar')['src']
    expect(page.find('.header-user-avatar')['src']).to eq data_uri
  end
end