user_edit_profile_spec.rb 3.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
require 'spec_helper'

describe 'User edit profile' do
  let(:user) { create(:user) }

  before do
    sign_in(user)
    visit(profile_path)
  end

11 12 13 14
  def submit_settings
    click_button 'Update profile settings'
  end

15 16 17 18 19 20 21 22
  it 'changes user profile' do
    fill_in 'user_skype', with: 'testskype'
    fill_in 'user_linkedin', with: 'testlinkedin'
    fill_in 'user_twitter', with: 'testtwitter'
    fill_in 'user_website_url', with: 'testurl'
    fill_in 'user_location', with: 'Ukraine'
    fill_in 'user_bio', with: 'I <3 GitLab'
    fill_in 'user_organization', with: 'GitLab'
23
    submit_settings
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

    expect(user.reload).to have_attributes(
      skype: 'testskype',
      linkedin: 'testlinkedin',
      twitter: 'testtwitter',
      website_url: 'testurl',
      bio: 'I <3 GitLab',
      organization: 'GitLab'
    )

    expect(find('#user_location').value).to eq 'Ukraine'
    expect(page).to have_content('Profile was successfully updated')
  end

  context 'user avatar' do
    before do
      attach_file(:user_avatar, Rails.root.join('spec', 'fixtures', 'banana_sample.gif'))
41
      submit_settings
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    end

    it 'changes user avatar' do
      expect(page).to have_link('Remove avatar')

      user.reload
      expect(user.avatar).to be_instance_of AvatarUploader
      expect(user.avatar.url).to eq "/uploads/-/system/user/avatar/#{user.id}/banana_sample.gif"
    end

    it 'removes user avatar' do
      click_link 'Remove avatar'

      user.reload

      expect(user.avatar?).to eq false
      expect(page).not_to have_link('Remove avatar')
      expect(page).to have_link('gravatar.com')
    end
  end
62

63 64 65 66 67 68 69
  context 'user status', :js do
    def select_emoji(emoji_name)
      toggle_button = find('.js-toggle-emoji-menu')
      toggle_button.click
      emoji_button = find(%Q{.js-status-emoji-menu .js-emoji-btn gl-emoji[data-name="#{emoji_name}"]})
      emoji_button.click
    end
70

71
    it 'shows the user status form' do
72 73
      visit(profile_path)

74
      expect(page).to have_content('Current status')
75 76
    end

77 78 79 80 81
    it 'adds emoji to user status' do
      emoji = 'biohazard'
      visit(profile_path)
      select_emoji(emoji)
      submit_settings
82

83 84 85 86 87 88 89 90
      visit user_path(user)
      within('.cover-status') do
        expect(page).to have_emoji(emoji)
      end
    end

    it 'adds message to user status' do
      message = 'I have something to say'
91
      visit(profile_path)
92 93 94 95 96 97 98 99 100
      fill_in 'js-status-message-field', with: message
      submit_settings

      visit user_path(user)
      within('.cover-status') do
        expect(page).to have_emoji('speech_balloon')
        expect(page).to have_content message
      end
    end
101

102 103 104 105 106 107 108 109 110 111 112 113 114
    it 'adds message and emoji to user status' do
      emoji = 'tanabata_tree'
      message = 'Playing outside'
      visit(profile_path)
      select_emoji(emoji)
      fill_in 'js-status-message-field', with: message
      submit_settings

      visit user_path(user)
      within('.cover-status') do
        expect(page).to have_emoji(emoji)
        expect(page).to have_content message
      end
115 116
    end

117 118 119 120 121 122 123 124
    it 'clears the user status' do
      user_status = create(:user_status, user: user, message: 'Eating bread', emoji: 'stuffed_flatbread')

      visit user_path(user)
      within('.cover-status') do
        expect(page).to have_emoji(user_status.emoji)
        expect(page).to have_content user_status.message
      end
125 126

      visit(profile_path)
127 128
      click_button 'js-clear-user-status-button'
      submit_settings
129

130 131
      visit user_path(user)
      expect(page).not_to have_selector '.cover-status'
132 133
    end
  end
134
end