debian-mirror-gitlab/spec/features/users/show_spec.rb

471 lines
13 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'User page' do
2019-07-07 11:18:12 +05:30
include ExternalAuthorizationServiceHelpers
2021-11-11 11:23:49 +05:30
let_it_be(:user) { create(:user, bio: '<b>Lorem</b> <i>ipsum</i> dolor sit <a href="https://example.com">amet</a>') }
2021-01-29 00:20:46 +05:30
2021-02-22 17:27:13 +05:30
subject(:visit_profile) { visit(user_path(user)) }
2018-03-27 19:54:05 +05:30
2018-11-18 11:00:15 +05:30
context 'with public profile' do
it 'shows all the tabs' do
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
page.within '.nav-links' do
2018-12-05 23:21:45 +05:30
expect(page).to have_link('Overview')
2018-11-18 11:00:15 +05:30
expect(page).to have_link('Activity')
expect(page).to have_link('Groups')
expect(page).to have_link('Contributed projects')
expect(page).to have_link('Personal projects')
expect(page).to have_link('Snippets')
2021-03-11 19:13:27 +05:30
expect(page).to have_link('Followers')
expect(page).to have_link('Following')
2018-11-18 11:00:15 +05:30
end
end
it 'does not show private profile message' do
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
expect(page).not_to have_content("This user has a private profile")
end
2020-04-08 14:13:33 +05:30
context 'work information' do
it 'shows job title and organization details' do
2021-04-29 21:17:54 +05:30
user.update!(organization: 'GitLab - work info test', job_title: 'Frontend Engineer')
2020-04-08 14:13:33 +05:30
subject
expect(page).to have_content('Frontend Engineer at GitLab - work info test')
end
it 'shows job title' do
2021-04-29 21:17:54 +05:30
user.update!(organization: nil, job_title: 'Frontend Engineer - work info test')
2020-04-08 14:13:33 +05:30
subject
expect(page).to have_content('Frontend Engineer - work info test')
end
it 'shows organization details' do
2021-04-29 21:17:54 +05:30
user.update!(organization: 'GitLab - work info test', job_title: '')
2020-04-08 14:13:33 +05:30
subject
expect(page).to have_content('GitLab - work info test')
end
end
2021-03-11 19:13:27 +05:30
2021-10-27 15:23:28 +05:30
context 'location' do
let_it_be(:location) { 'San Francisco, CA' }
context 'when location is set' do
let_it_be(:user) { create(:user, location: location) }
it 'shows location' do
subject
expect(page).to have_content(location)
end
end
context 'when location is not set' do
it 'does not show location' do
subject
expect(page).not_to have_content(location)
end
end
end
context 'timezone' do
let_it_be(:timezone) { 'America/Los_Angeles' }
2021-11-18 22:05:49 +05:30
let_it_be(:local_time_selector) { '[data-testid="user-local-time"]' }
2021-10-27 15:23:28 +05:30
before do
travel_to Time.find_zone(timezone).local(2021, 7, 20, 15, 30, 45)
end
context 'when timezone is set' do
let_it_be(:user) { create(:user, timezone: timezone) }
it 'shows local time' do
subject
2021-11-18 22:05:49 +05:30
within local_time_selector do
expect(page).to have_content('3:30 PM')
end
end
end
context 'when timezone is not set' do
let_it_be(:user) { create(:user, timezone: nil) }
it 'does not show local time' do
subject
expect(page).not_to have_selector(local_time_selector)
2021-10-27 15:23:28 +05:30
end
end
context 'when timezone is invalid' do
let_it_be(:user) { create(:user, timezone: 'Foo/Bar') }
it 'shows local time using the configured default timezone (UTC in this case)' do
subject
2021-11-18 22:05:49 +05:30
within local_time_selector do
expect(page).to have_content('10:30 PM')
end
2021-10-27 15:23:28 +05:30
end
end
end
2021-03-11 19:13:27 +05:30
context 'follow/unfollow and followers/following' do
let_it_be(:followee) { create(:user) }
let_it_be(:follower) { create(:user) }
it 'does not show link to follow' do
subject
expect(page).not_to have_link(text: 'Follow', class: 'gl-button')
end
it 'shows 0 followers and 0 following' do
subject
expect(page).to have_content('0 followers')
expect(page).to have_content('0 following')
end
it 'shows 1 followers and 1 following' do
follower.follow(user)
user.follow(followee)
subject
expect(page).to have_content('1 follower')
expect(page).to have_content('1 following')
end
it 'does show link to follow' do
sign_in(user)
visit user_path(followee)
expect(page).to have_link(text: 'Follow', class: 'gl-button')
end
it 'does show link to unfollow' do
sign_in(user)
user.follow(followee)
visit user_path(followee)
expect(page).to have_link(text: 'Unfollow', class: 'gl-button')
end
end
2018-11-18 11:00:15 +05:30
end
context 'with private profile' do
2021-01-29 00:20:46 +05:30
let_it_be(:user) { create(:user, private_profile: true) }
2018-11-18 11:00:15 +05:30
it 'shows no tab' do
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
expect(page).to have_css("div.profile-header")
expect(page).not_to have_css("ul.nav-links")
end
it 'shows private profile message' do
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
expect(page).to have_content("This user has a private profile")
end
it 'shows own tabs' do
sign_in(user)
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
page.within '.nav-links' do
2018-12-05 23:21:45 +05:30
expect(page).to have_link('Overview')
2018-11-18 11:00:15 +05:30
expect(page).to have_link('Activity')
expect(page).to have_link('Groups')
expect(page).to have_link('Contributed projects')
expect(page).to have_link('Personal projects')
expect(page).to have_link('Snippets')
2021-03-11 19:13:27 +05:30
expect(page).to have_link('Followers')
expect(page).to have_link('Following')
2018-11-18 11:00:15 +05:30
end
end
end
2020-01-01 13:55:28 +05:30
context 'with blocked profile' do
2021-11-11 11:23:49 +05:30
let_it_be(:user) do
create(
:user,
state: :blocked,
organization: 'GitLab - work info test',
job_title: 'Frontend Engineer',
2022-01-26 12:08:38 +05:30
pronunciation: 'pruh-nuhn-see-ay-shn',
bio: 'My personal bio'
2021-11-11 11:23:49 +05:30
)
end
let_it_be(:status) { create(:user_status, user: user, message: "Working hard!") }
2020-01-01 13:55:28 +05:30
2022-01-26 12:08:38 +05:30
before do
visit_profile
end
2020-01-01 13:55:28 +05:30
2022-01-26 12:08:38 +05:30
it 'shows no tab' do
2020-01-01 13:55:28 +05:30
expect(page).to have_css("div.profile-header")
expect(page).not_to have_css("ul.nav-links")
end
it 'shows blocked message' do
expect(page).to have_content("This user is blocked")
end
it 'shows user name as blocked' do
expect(page).to have_css(".cover-title", text: 'Blocked user')
end
it 'shows no additional fields' do
expect(page).not_to have_css(".profile-user-bio")
2021-11-11 11:23:49 +05:30
expect(page).not_to have_content('GitLab - work info test')
expect(page).not_to have_content('Frontend Engineer')
expect(page).not_to have_content('Working hard!')
expect(page).not_to have_content("Pronounced as: pruh-nuhn-see-ay-shn")
2020-01-01 13:55:28 +05:30
end
it 'shows username' do
expect(page).to have_content("@#{user.username}")
end
2022-01-26 12:08:38 +05:30
it_behaves_like 'default brand title page meta description'
2020-01-01 13:55:28 +05:30
end
2021-02-22 17:27:13 +05:30
context 'with unconfirmed user' do
2021-11-11 11:23:49 +05:30
let_it_be(:user) do
create(
:user,
:unconfirmed,
organization: 'GitLab - work info test',
job_title: 'Frontend Engineer',
2022-01-26 12:08:38 +05:30
pronunciation: 'pruh-nuhn-see-ay-shn',
bio: 'My personal bio'
2021-11-11 11:23:49 +05:30
)
end
let_it_be(:status) { create(:user_status, user: user, message: "Working hard!") }
2021-02-22 17:27:13 +05:30
shared_examples 'unconfirmed user profile' do
before do
visit_profile
end
it 'shows user name as unconfirmed' do
expect(page).to have_css(".cover-title", text: 'Unconfirmed user')
end
it 'shows no tab' do
expect(page).to have_css("div.profile-header")
expect(page).not_to have_css("ul.nav-links")
end
it 'shows no additional fields' do
expect(page).not_to have_css(".profile-user-bio")
2021-11-11 11:23:49 +05:30
expect(page).not_to have_content('GitLab - work info test')
expect(page).not_to have_content('Frontend Engineer')
expect(page).not_to have_content('Working hard!')
expect(page).not_to have_content("Pronounced as: pruh-nuhn-see-ay-shn")
2021-02-22 17:27:13 +05:30
end
it 'shows private profile message' do
expect(page).to have_content("This user has a private profile")
end
2022-01-26 12:08:38 +05:30
it_behaves_like 'default brand title page meta description'
2021-02-22 17:27:13 +05:30
end
context 'when visited by an authenticated user' do
before do
authenticated_user = create(:user)
sign_in(authenticated_user)
end
it_behaves_like 'unconfirmed user profile'
end
context 'when visited by an unauthenticated user' do
it_behaves_like 'unconfirmed user profile'
end
end
2018-11-18 11:00:15 +05:30
it 'shows the status if there was one' do
create(:user_status, user: user, message: "Working hard!")
2021-01-29 00:20:46 +05:30
subject
2018-03-27 19:54:05 +05:30
2018-11-18 11:00:15 +05:30
expect(page).to have_content("Working hard!")
end
2021-09-04 01:27:46 +05:30
it 'shows the pronouns of the user if there was one' do
user.user_detail.update_column(:pronouns, 'they/them')
subject
expect(page).to have_content("(they/them)")
end
2021-10-27 15:23:28 +05:30
it 'shows the pronunctiation of the user if there was one' do
user.user_detail.update_column(:pronunciation, 'pruh-nuhn-see-ay-shn')
subject
expect(page).to have_content("Pronounced as: pruh-nuhn-see-ay-shn")
end
2018-11-18 11:00:15 +05:30
context 'signup disabled' do
it 'shows the sign in link' do
stub_application_setting(signup_enabled: false)
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
page.within '.navbar-nav' do
expect(page).to have_link('Sign in')
end
end
end
context 'signup enabled' do
it 'shows the sign in and register link' do
stub_application_setting(signup_enabled: true)
2021-01-29 00:20:46 +05:30
subject
2018-11-18 11:00:15 +05:30
page.within '.navbar-nav' do
expect(page).to have_link('Sign in / Register')
end
2018-03-27 19:54:05 +05:30
end
end
2019-07-07 11:18:12 +05:30
context 'most recent activity' do
it 'shows the most recent activity' do
2021-01-29 00:20:46 +05:30
subject
2019-07-07 11:18:12 +05:30
expect(page).to have_content('Most Recent Activity')
end
context 'when external authorization is enabled' do
before do
enable_external_authorization_service_check
end
it 'hides the most recent activity' do
2021-01-29 00:20:46 +05:30
subject
2019-07-07 11:18:12 +05:30
expect(page).not_to have_content('Most Recent Activity')
end
end
end
2021-01-03 14:25:43 +05:30
context 'page description' do
before do
2021-01-29 00:20:46 +05:30
subject
2021-01-03 14:25:43 +05:30
end
it_behaves_like 'page meta description', 'Lorem ipsum dolor sit amet'
end
context 'with a bot user' do
2021-01-29 00:20:46 +05:30
let_it_be(:user) { create(:user, user_type: :security_bot) }
2021-01-03 14:25:43 +05:30
describe 'feature flag enabled' do
before do
stub_feature_flags(security_auto_fix: true)
end
it 'only shows Overview and Activity tabs' do
2021-01-29 00:20:46 +05:30
subject
2021-01-03 14:25:43 +05:30
page.within '.nav-links' do
expect(page).to have_link('Overview')
expect(page).to have_link('Activity')
expect(page).not_to have_link('Groups')
expect(page).not_to have_link('Contributed projects')
expect(page).not_to have_link('Personal projects')
expect(page).not_to have_link('Snippets')
2021-03-11 19:13:27 +05:30
expect(page).not_to have_link('Followers')
expect(page).not_to have_link('Following')
2021-01-03 14:25:43 +05:30
end
end
end
describe 'feature flag disabled' do
before do
stub_feature_flags(security_auto_fix: false)
end
it 'only shows Overview and Activity tabs' do
2021-01-29 00:20:46 +05:30
subject
2021-01-03 14:25:43 +05:30
page.within '.nav-links' do
expect(page).to have_link('Overview')
expect(page).to have_link('Activity')
expect(page).to have_link('Groups')
expect(page).to have_link('Contributed projects')
expect(page).to have_link('Personal projects')
expect(page).to have_link('Snippets')
2021-03-11 19:13:27 +05:30
expect(page).to have_link('Followers')
expect(page).to have_link('Following')
2021-01-03 14:25:43 +05:30
end
end
end
end
2021-01-29 00:20:46 +05:30
context 'structured markup' do
2022-05-07 20:08:51 +05:30
let_it_be(:user) { create(:user, website_url: 'https://gitlab.com', organization: 'GitLab', job_title: 'Frontend Engineer', email: 'public@example.com', public_email: 'public@example.com', location: 'Country', created_at: Time.zone.now, updated_at: Time.zone.now) }
2021-01-29 00:20:46 +05:30
it 'shows Person structured markup' do
subject
aggregate_failures do
expect(page).to have_selector('[itemscope][itemtype="http://schema.org/Person"]')
expect(page).to have_selector('img[itemprop="image"]')
expect(page).to have_selector('[itemprop="name"]')
expect(page).to have_selector('[itemprop="address"][itemscope][itemtype="https://schema.org/PostalAddress"]')
expect(page).to have_selector('[itemprop="addressLocality"]')
expect(page).to have_selector('[itemprop="url"]')
expect(page).to have_selector('[itemprop="email"]')
expect(page).to have_selector('span[itemprop="jobTitle"]')
expect(page).to have_selector('span[itemprop="worksFor"]')
end
end
end
2021-11-11 11:23:49 +05:30
context 'GPG keys' do
context 'when user has verified GPG keys' do
let_it_be(:user) { create(:user, email: GpgHelpers::User1.emails.first) }
let_it_be(:gpg_key) { create(:gpg_key, user: user, key: GpgHelpers::User1.public_key) }
let_it_be(:gpg_key2) { create(:gpg_key, user: user, key: GpgHelpers::User1.public_key2) }
it 'shows link to public GPG keys' do
subject
expect(page).to have_link('View public GPG keys', href: user_gpg_keys_path(user))
end
end
context 'when user does not have verified GPG keys' do
it 'does not show link to public GPG keys' do
subject
expect(page).not_to have_link('View public GPG key', href: user_gpg_keys_path(user))
expect(page).not_to have_link('View public GPG keys', href: user_gpg_keys_path(user))
end
end
end
2018-03-27 19:54:05 +05:30
end