Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_uploads_avatar_to_profile_spec.rb « uploads « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d121d9eeba9c9b06e4a4be21cb2d4bdc2c9aa2a (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'spec_helper'

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

  shared_examples 'upload avatar' do
    it 'shows the new avatar immediately in the header and setting sidebar', :js do
      expect(page.find('.avatar-image .gl-avatar')['src']).not_to include(
        "/uploads/-/system/user/avatar/#{user.id}/avatar.png"
      )
      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

      within_testid('user-dropdown') do
        # We are setting a blob URL
        expect(find('.gl-avatar')['src']).to start_with 'blob:'
      end

      visit profile_path

      expect(page.find('.avatar-image .gl-avatar')['src']).to include(
        "/uploads/-/system/user/avatar/#{user.id}/avatar.png"
      )
    end
  end

  context 'with "edit_user_profile_vue" turned on' do
    before do
      sign_in_and_visit_profile
    end

    it_behaves_like 'upload avatar'
  end

  context 'with "edit_user_profile_vue" turned off' do
    before do
      stub_feature_flags(edit_user_profile_vue: false)
      sign_in_and_visit_profile
    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(%(img[src$="/uploads/-/system/user/avatar/#{user.id}/dk.png?width=96"]))

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

    it_behaves_like 'upload avatar'
  end

  private

  def sign_in_and_visit_profile
    sign_in user
    visit profile_path
  end
end