user_edit_profile_spec.rb 11.7 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7 8 9 10 11 12
require 'spec_helper'

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

  before do
    sign_in(user)
    visit(profile_path)
  end

13 14
  def submit_settings
    click_button 'Update profile settings'
15
    wait_for_requests if respond_to?(:wait_for_requests)
16 17
  end

18 19 20 21 22
  def visit_user
    visit user_path(user)
    wait_for_requests
  end

23 24 25 26 27 28 29
  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'
30
    fill_in 'user_job_title', with: 'Frontend Engineer'
31
    fill_in 'user_organization', with: 'GitLab'
32
    submit_settings
33 34 35 36 37 38 39

    expect(user.reload).to have_attributes(
      skype: 'testskype',
      linkedin: 'testlinkedin',
      twitter: 'testtwitter',
      website_url: 'testurl',
      bio: 'I <3 GitLab',
40 41
      job_title: 'Frontend Engineer',
      organization: 'GitLab'
42 43 44 45 46 47
    )

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

48 49 50 51
  it 'shows an error if the full name contains an emoji', :js do
    simulate_input('#user_name', 'Martin 😀')
    submit_settings

52
    page.within('.rspec-full-name') do
53 54 55 56 57 58
      expect(page).to have_css '.gl-field-error-outline'
      expect(find('.gl-field-error')).not_to have_selector('.hidden')
      expect(find('.gl-field-error')).to have_content('Using emojis in names seems fun, but please try to set a status message instead')
    end
  end

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  describe 'when I change my email' do
    before do
      user.send_reset_password_instructions
    end

    it 'clears the reset password token' do
      expect(user.reset_password_token?).to be true

      fill_in 'user_email', with: 'new-email@example.com'
      submit_settings

      user.reload
      expect(user.confirmation_token).not_to be_nil
      expect(user.reset_password_token?).to be false
    end
  end

76 77 78
  context 'user avatar' do
    before do
      attach_file(:user_avatar, Rails.root.join('spec', 'fixtures', 'banana_sample.gif'))
79
      submit_settings
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    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
100

101
  context 'user status', :js do
102 103
    def select_emoji(emoji_name, is_modal = false)
      emoji_menu_class = is_modal ? '.js-modal-status-emoji-menu' : '.js-status-emoji-menu'
104 105
      toggle_button = find('.js-toggle-emoji-menu')
      toggle_button.click
106
      emoji_button = find(%Q{#{emoji_menu_class} .js-emoji-btn gl-emoji[data-name="#{emoji_name}"]})
107 108
      emoji_button.click
    end
109

110 111 112 113
    context 'profile edit form' do
      it 'shows the user status form' do
        expect(page).to have_content('Current status')
      end
114

115 116 117 118
      it 'adds emoji to user status' do
        emoji = 'biohazard'
        select_emoji(emoji)
        submit_settings
119

120 121
        visit_user

122 123 124
        within('.cover-status') do
          expect(page).to have_emoji(emoji)
        end
125 126
      end

127 128 129 130
      it 'adds message to user status' do
        message = 'I have something to say'
        fill_in 'js-status-message-field', with: message
        submit_settings
131

132 133
        visit_user

134 135 136 137
        within('.cover-status') do
          expect(page).to have_emoji('speech_balloon')
          expect(page).to have_content message
        end
138
      end
139

140 141 142 143 144 145
      it 'adds message and emoji to user status' do
        emoji = 'tanabata_tree'
        message = 'Playing outside'
        select_emoji(emoji)
        fill_in 'js-status-message-field', with: message
        submit_settings
146

147 148
        visit_user

149 150 151 152
        within('.cover-status') do
          expect(page).to have_emoji(emoji)
          expect(page).to have_content message
        end
153
      end
154

155 156 157
      it 'clears the user status' do
        user_status = create(:user_status, user: user, message: 'Eating bread', emoji: 'stuffed_flatbread')

158 159
        visit_user

160 161 162 163 164 165 166 167
        within('.cover-status') do
          expect(page).to have_emoji(user_status.emoji)
          expect(page).to have_content user_status.message
        end

        visit(profile_path)
        click_button 'js-clear-user-status-button'
        submit_settings
168

169
        visit_user
170

171
        expect(page).not_to have_selector '.cover-status'
172
      end
173

174 175 176
      it 'displays a default emoji if only message is entered' do
        message = 'a status without emoji'
        fill_in 'js-status-message-field', with: message
177

178 179 180 181
        within('.js-toggle-emoji-menu') do
          expect(page).to have_emoji('speech_balloon')
        end
      end
182
    end
183

184
    context 'user menu' do
185 186 187
      let(:issue) { create(:issue, project: project)}
      let(:project) { create(:project) }

188 189 190 191 192 193 194 195 196 197 198 199
      def open_user_status_modal
        find('.header-user-dropdown-toggle').click

        page.within ".header-user" do
          click_button 'Set status'
        end
      end

      def set_user_status_in_modal
        page.within "#set-user-status-modal" do
          click_button 'Set status'
        end
200
        wait_for_requests
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
      end

      before do
        visit root_path(user)
      end

      it 'shows the "Set status" menu item in the user menu' do
        find('.header-user-dropdown-toggle').click

        page.within ".header-user" do
          expect(page).to have_content('Set status')
        end
      end

      it 'shows the "Edit status" menu item in the user menu' do
        user_status = create(:user_status, user: user, message: 'Eating bread', emoji: 'stuffed_flatbread')
        visit root_path(user)

        find('.header-user-dropdown-toggle').click

        page.within ".header-user" do
          expect(page).to have_emoji(user_status.emoji)
          expect(page).to have_content user_status.message
          expect(page).to have_content('Edit status')
        end
      end

      it 'shows user status modal' do
        open_user_status_modal

        expect(page.find('#set-user-status-modal')).to be_visible
        expect(page).to have_content('Set a status')
      end

      it 'adds emoji to user status' do
        emoji = 'biohazard'
        open_user_status_modal
        select_emoji(emoji, true)
        set_user_status_in_modal

241 242
        visit_user

243 244 245 246 247
        within('.cover-status') do
          expect(page).to have_emoji(emoji)
        end
      end

248 249 250 251 252 253 254 255 256 257 258
      it 'does not update the awards panel emoji' do
        project.add_maintainer(user)
        visit(project_issue_path(project, issue))

        emoji = 'biohazard'
        open_user_status_modal
        select_emoji(emoji, true)

        expect(page.all('.award-control .js-counter')).to all(have_content('0'))
      end

259 260 261 262 263 264
      it 'adds message to user status' do
        message = 'I have something to say'
        open_user_status_modal
        find('.js-status-message-field').native.send_keys(message)
        set_user_status_in_modal

265 266
        visit_user

267 268 269 270 271 272 273 274 275 276 277 278 279 280
        within('.cover-status') do
          expect(page).to have_emoji('speech_balloon')
          expect(page).to have_content message
        end
      end

      it 'adds message and emoji to user status' do
        emoji = 'tanabata_tree'
        message = 'Playing outside'
        open_user_status_modal
        select_emoji(emoji, true)
        find('.js-status-message-field').native.send_keys(message)
        set_user_status_in_modal

281 282
        visit_user

283 284 285 286 287 288 289 290 291
        within('.cover-status') do
          expect(page).to have_emoji(emoji)
          expect(page).to have_content message
        end
      end

      it 'clears the user status with the "X" button' do
        user_status = create(:user_status, user: user, message: 'Eating bread', emoji: 'stuffed_flatbread')

292 293 294
        visit_user
        wait_for_requests

295 296 297 298 299 300 301 302 303 304 305 306 307 308
        within('.cover-status') do
          expect(page).to have_emoji(user_status.emoji)
          expect(page).to have_content user_status.message
        end

        find('.header-user-dropdown-toggle').click

        page.within ".header-user" do
          click_button 'Edit status'
        end

        find('.js-clear-user-status-button').click
        set_user_status_in_modal

309 310 311
        visit_user
        wait_for_requests

312 313 314 315 316 317
        expect(page).not_to have_selector '.cover-status'
      end

      it 'clears the user status with the "Remove status" button' do
        user_status = create(:user_status, user: user, message: 'Eating bread', emoji: 'stuffed_flatbread')

318 319 320
        visit_user
        wait_for_requests

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
        within('.cover-status') do
          expect(page).to have_emoji(user_status.emoji)
          expect(page).to have_content user_status.message
        end

        find('.header-user-dropdown-toggle').click

        page.within ".header-user" do
          click_button 'Edit status'
        end

        page.within "#set-user-status-modal" do
          click_button 'Remove status'
        end

336 337
        visit_user

338 339 340 341 342 343 344
        expect(page).not_to have_selector '.cover-status'
      end

      it 'displays a default emoji if only message is entered' do
        message = 'a status without emoji'
        open_user_status_modal
        find('.js-status-message-field').native.send_keys(message)
345

346 347 348
        within('.js-toggle-emoji-menu') do
          expect(page).to have_emoji('speech_balloon')
        end
349 350
      end
    end
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

    context 'User time preferences', :js do
      let(:issue) { create(:issue, project: project)}
      let(:project) { create(:project) }

      before do
        stub_feature_flags(user_time_settings: true)
      end

      it 'shows the user time preferences form' do
        expect(page).to have_content('Time settings')
      end

      it 'allows the user to select a time zone from a dropdown list of options' do
        expect(page.find('.user-time-preferences .dropdown')).not_to have_css('.show')

        page.find('.user-time-preferences .js-timezone-dropdown').click

        expect(page.find('.user-time-preferences .dropdown')).to have_css('.show')

        page.find("a", text: "Nuku'alofa").click

        tz = page.find('.user-time-preferences #user_timezone', visible: false)

        expect(tz.value).to eq('Pacific/Tongatapu')
      end

      it 'timezone defaults to servers default' do
        timezone_name = Time.zone.tzinfo.name
        expect(page.find('.user-time-preferences #user_timezone', visible: false).value).to eq(timezone_name)
      end
    end
383
  end
384 385

  context 'work information', :js do
peterhegman's avatar
peterhegman committed
386 387 388 389 390
    context 'when job title and organziation are entered' do
      it "shows job title and organzation on user's profile" do
        fill_in 'user_job_title', with: 'Frontend Engineer'
        fill_in 'user_organization', with: 'GitLab - work info test'
        submit_settings
391

peterhegman's avatar
peterhegman committed
392
        visit_user
393

peterhegman's avatar
peterhegman committed
394 395
        expect(page).to have_content('Frontend Engineer at GitLab - work info test')
      end
396 397
    end

peterhegman's avatar
peterhegman committed
398 399 400 401
    context 'when only job title is entered' do
      it "shows only job title on user's profile" do
        fill_in 'user_job_title', with: 'Frontend Engineer - work info test'
        submit_settings
402

peterhegman's avatar
peterhegman committed
403
        visit_user
404

peterhegman's avatar
peterhegman committed
405 406
        expect(page).to have_content('Frontend Engineer - work info test')
      end
407 408
    end

peterhegman's avatar
peterhegman committed
409 410 411 412
    context 'when only organization is entered' do
      it "shows only organization on user's profile" do
        fill_in 'user_organization', with: 'GitLab - work info test'
        submit_settings
413

peterhegman's avatar
peterhegman committed
414
        visit_user
415

peterhegman's avatar
peterhegman committed
416 417
        expect(page).to have_content('GitLab - work info test')
      end
418 419
    end
  end
420
end