Commit 9fa36b14 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '326714-update-admin-users-specs' into 'master'

Convert admin/users view - update specs for feature flag rollout

See merge request gitlab-org/gitlab!59755
parents d6841c0e e18c629a
......@@ -23,9 +23,7 @@ export default {
'data-method': 'put',
'data-modal-attributes': JSON.stringify({
title: sprintf(s__('AdminUsers|Unblock user %{username}?'), { username: this.username }),
message: s__(
'AdminUsers|You can always unblock their account, their data will remain intact.',
),
message: s__('AdminUsers|You can always block their account again if needed.'),
okVariant: 'confirm',
okTitle: s__('AdminUsers|Unblock'),
}),
......
......@@ -70,14 +70,14 @@ export default {
</script>
<template>
<div class="gl-display-flex gl-justify-content-end">
<div class="gl-display-flex gl-justify-content-end" :data-testid="`user-actions-${user.id}`">
<gl-button v-if="hasEditAction" data-testid="edit" :href="userPaths.edit">{{
$options.i18n.edit
}}</gl-button>
<gl-dropdown
v-if="hasDropdownActions"
data-testid="actions"
data-testid="dropdown-toggle"
right
class="gl-ml-2"
icon="settings"
......
......@@ -77,6 +77,10 @@ export default {
<user-date :date="lastActivityOn" show-never />
</template>
<template #cell(projectsCount)="{ item: { id, projectsCount } }">
<div :data-testid="`user-project-count-${id}`">{{ projectsCount }}</div>
</template>
<template #cell(settings)="{ item: user }">
<user-actions :user="user" :paths="paths" />
</template>
......
......@@ -21,13 +21,13 @@
= user.last_activity_on.nil? ? _('Never') : l(user.last_activity_on, format: :admin)
- unless user.internal?
.table-section.section-20.table-button-footer
.table-action-buttons
= link_to _('Edit'), edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: 'btn gl-button btn-default'
.table-action-buttons{ data: { testid: "user-actions-#{user.id}" } }
= link_to _('Edit'), edit_admin_user_path(user), class: 'btn gl-button btn-default'
- unless user == current_user
%button.dropdown-new.btn.gl-button.btn-default{ type: 'button', data: { testid: "user-action-button-#{user.id}", toggle: 'dropdown' } }
%button.dropdown-new.btn.gl-button.btn-default{ type: 'button', data: { testid: "dropdown-toggle", toggle: 'dropdown' } }
= sprite_icon('settings')
= sprite_icon('chevron-down')
%ul.dropdown-menu.dropdown-menu-right{ data: { testid: "user-action-dropdown-#{user.id}" } }
%ul.dropdown-menu.dropdown-menu-right
%li.dropdown-header
= _('Settings')
%li
......
......@@ -3,172 +3,179 @@
require 'spec_helper'
RSpec.describe "Admin::Users" do
include Spec::Support::Helpers::Features::ResponsiveTableHelpers
let!(:user) do
create(:omniauth_user, provider: 'twitter', extern_uid: '123456')
end
let!(:current_user) { create(:admin, last_activity_on: 5.days.ago) }
let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin) }
before do
stub_feature_flags(vue_admin_users: false)
sign_in(current_user)
gitlab_enable_admin_mode_sign_in(current_user)
end
describe 'GET /admin/users' do
describe 'send emails to users' do
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
[true, false].each do |vue_admin_users|
context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
it "shows the 'Send email to users' link" do
visit admin_users_path
describe 'GET /admin/users' do
describe 'send emails to users' do
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
expect(page).to have_link(href: admin_email_path)
end
end
it "shows the 'Send email to users' link" do
visit admin_users_path
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
expect(page).to have_link(href: admin_email_path)
end
end
it "does not show the 'Send email to users' link" do
visit admin_users_path
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
expect(page).not_to have_link(href: admin_email_path)
end
end
end
it "does not show the 'Send email to users' link" do
visit admin_users_path
describe 'user permission export' do
context 'when `export_user_permissions` feature is available' do
before do
stub_licensed_features(export_user_permissions: true)
expect(page).not_to have_link(href: admin_email_path)
end
end
end
it "shows the 'Export Permissions' link" do
visit admin_users_path
describe 'user permission export' do
context 'when `export_user_permissions` feature is available' do
before do
stub_licensed_features(export_user_permissions: true)
end
expect(page).to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
it "shows the 'Export Permissions' link" do
visit admin_users_path
context 'when `export_user_permissions` feature is disabled' do
before do
stub_licensed_features(export_user_permissions: false)
end
expect(page).to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
it "does not show the 'Export Permissions' link" do
visit admin_users_path
context 'when `export_user_permissions` feature is disabled' do
before do
stub_licensed_features(export_user_permissions: false)
end
expect(page).not_to have_link(href: admin_user_permission_exports_path(format: :csv))
it "does not show the 'Export Permissions' link" do
visit admin_users_path
expect(page).not_to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
end
end
end
end
describe "GET /admin/users/:id" do
describe 'Shared runners quota status' do
before do
user.namespace.update!(shared_runners_minutes_limit: 500)
end
describe "GET /admin/users/:id" do
describe 'Shared runners quota status' do
before do
user.namespace.update!(shared_runners_minutes_limit: 500)
end
context 'with projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: true)
end
context 'with projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: true)
end
it 'shows quota' do
visit admin_users_path
it 'shows quota' do
visit admin_users_path
click_link user.name
click_link user.name
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
context 'without projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: false)
end
context 'without projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: false)
end
it 'does not show quota' do
visit admin_users_path
it 'does not show quota' do
visit admin_users_path
click_link user.name
click_link user.name
expect(page).not_to have_content('Pipeline minutes quota:')
expect(page).not_to have_content('Pipeline minutes quota:')
end
end
end
end
end
end
describe "GET /admin/users/:id/edit" do
before do
visit admin_users_path
click_link "edit_user_#{user.id}"
end
describe "GET /admin/users/:id/edit" do
describe "Update user account type" do
before do
visit_edit_user(user.id)
describe "Update user account type" do
before do
allow_any_instance_of(AuditorUserHelper).to receive(:license_allows_auditor_user?).and_return(true)
choose "user_access_level_auditor"
click_button "Save changes"
end
allow_any_instance_of(AuditorUserHelper).to receive(:license_allows_auditor_user?).and_return(true)
choose "user_access_level_auditor"
click_button "Save changes"
end
it "changes account type to be auditor" do
user.reload
it "changes account type to be auditor" do
user.reload
expect(user).not_to be_admin
expect(user).to be_auditor
end
end
expect(user).not_to be_admin
expect(user).to be_auditor
end
end
describe 'Update shared runners quota' do
let!(:project) { create(:project, namespace: user.namespace, shared_runners_enabled: true) }
describe 'Update shared runners quota' do
let_it_be(:project) { create(:project, namespace: user.namespace, shared_runners_enabled: true) }
before do
fill_in "user_namespace_attributes_shared_runners_minutes_limit", with: "500"
click_button "Save changes"
end
it "shows page with new data" do
visit_edit_user(user.id)
fill_in "user_namespace_attributes_shared_runners_minutes_limit", with: "500"
click_button "Save changes"
it "shows page with new data" do
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
def visit_edit_user(user_id)
visit admin_users_path
page.within("[data-testid='user-actions-#{user_id}']") do
click_link 'Edit'
end
end
end
end
end
describe 'show user keys for SSH and LDAP' do
let!(:key1) do
create(:ldap_key, user: user, title: "LDAP Key1")
end
describe 'show user keys for SSH and LDAP' do
let_it_be(:key1) do
create(:ldap_key, user: user, title: "LDAP Key1")
end
let!(:key2) do
create(:key, user: user, title: "ssh-rsa Key2", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key2")
end
let_it_be(:key2) do
create(:key, user: user, title: "ssh-rsa Key2", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key2")
end
it 'only shows the delete button for regular keys' do
visit admin_users_path
it 'only shows the delete button for regular keys' do
visit admin_users_path
click_link user.name
click_link 'SSH keys'
click_link user.name
click_link 'SSH keys'
# Check that the regular Key shows the delete icon and the LDAPKey does not
# Check that the regular Key shows the delete icon and the LDAPKey does not
# SSH key should be the first in the list
within('ul.content-list li.key-list-item:nth-of-type(1)') do
expect(page).to have_content(key2.title)
expect(page).to have_button('Delete')
end
# SSH key should be the first in the list
within('ul.content-list li.key-list-item:nth-of-type(1)') do
expect(page).to have_content(key2.title)
expect(page).to have_button('Delete')
end
# Next, LDAP key
within('ul.content-list li.key-list-item:nth-of-type(2)') do
expect(page).to have_content(key1.title)
expect(page).not_to have_button('Delete')
# Next, LDAP key
within('ul.content-list li.key-list-item:nth-of-type(2)') do
expect(page).to have_content(key1.title)
expect(page).not_to have_button('Delete')
end
end
end
end
end
......
......@@ -4,18 +4,16 @@ require 'spec_helper'
RSpec.describe 'Admin::Users::User' do
let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin, last_activity_on: 5.days.ago) }
let_it_be(:current_user) { create(:admin) }
before do
sign_in(current_user)
gitlab_enable_admin_mode_sign_in(current_user)
stub_feature_flags(vue_admin_users: false)
end
describe 'GET /admin/users/:id' do
it 'has user info', :aggregate_failures do
visit admin_users_path
click_link user.name
visit admin_user_path(user)
expect(page).to have_content(user.email)
expect(page).to have_content(user.name)
......@@ -27,21 +25,6 @@ RSpec.describe 'Admin::Users::User' do
expect(page).to have_button('Delete user and contributions')
end
context 'user pending approval' do
it 'shows user info', :aggregate_failures do
user = create(:user, :blocked_pending_approval)
visit admin_users_path
click_link 'Pending approval'
click_link user.name
expect(page).to have_content(user.name)
expect(page).to have_content('Pending approval')
expect(page).to have_link('Approve user')
expect(page).to have_link('Reject request')
end
end
context 'when blocking/unblocking the user' do
it 'shows confirmation and allows blocking and unblocking', :js do
visit admin_user_path(user)
......@@ -171,6 +154,8 @@ RSpec.describe 'Admin::Users::User' do
it 'logs in as the user when impersonate is clicked' do
subject
find('[data-qa-selector="user_menu"]').click
expect(page.find(:css, '[data-testid="user-profile-link"]')['data-user']).to eql(another_user.username)
end
......@@ -205,6 +190,8 @@ RSpec.describe 'Admin::Users::User' do
it 'logs out of impersonated user back to original user' do
subject
find('[data-qa-selector="user_menu"]').click
expect(page.find(:css, '[data-testid="user-profile-link"]')['data-user']).to eq(current_user.username)
end
......@@ -238,6 +225,8 @@ RSpec.describe 'Admin::Users::User' do
end
it 'shows when disabled' do
user.update!(otp_required_for_login: false)
visit admin_user_path(user)
expect_two_factor_status('Disabled')
......@@ -251,7 +240,7 @@ RSpec.describe 'Admin::Users::User' do
end
describe 'Email verification status' do
let!(:secondary_email) do
let_it_be(:secondary_email) do
create :email, email: 'secondary@example.com', user: user
end
......@@ -274,99 +263,121 @@ RSpec.describe 'Admin::Users::User' do
expect(page).to have_content("#{secondary_email.email} Verified")
end
end
end
describe 'show user attributes' do
it 'has expected attributes', :aggregate_failures do
visit admin_users_path
click_link user.name
describe 'show user identities' do
it 'shows user identities', :aggregate_failures do
visit admin_user_identities_path(user)
expect(page).to have_content 'Account'
expect(page).to have_content 'Personal projects limit'
expect(page).to have_content(user.name)
expect(page).to have_content('twitter')
end
end
end
describe 'remove users secondary email', :js do
let!(:secondary_email) do
create :email, email: 'secondary@example.com', user: user
describe 'update user identities' do
before do
allow(Gitlab::Auth::OAuth::Provider).to receive(:providers).and_return([:twitter, :twitter_updated])
end
it 'modifies twitter identity', :aggregate_failures do
visit admin_user_identities_path(user)
find('.table').find(:link, 'Edit').click
fill_in 'identity_extern_uid', with: '654321'
select 'twitter_updated', from: 'identity_provider'
click_button 'Save changes'
expect(page).to have_content(user.name)
expect(page).to have_content('twitter_updated')
expect(page).to have_content('654321')
end
end
it do
visit admin_user_path(user.username)
describe 'remove users secondary email', :js do
let_it_be(:secondary_email) do
create :email, email: 'secondary@example.com', user: user
end
it do
visit admin_user_path(user.username)
expect(page).to have_content("Secondary email: #{secondary_email.email}")
expect(page).to have_content("Secondary email: #{secondary_email.email}")
accept_confirm { find("#remove_email_#{secondary_email.id}").click }
accept_confirm { find("#remove_email_#{secondary_email.id}").click }
expect(page).not_to have_content(secondary_email.email)
expect(page).not_to have_content(secondary_email.email)
end
end
end
describe 'show user keys', :js do
it do
key1 = create(:key, user: user, title: 'ssh-rsa Key1', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key1')
key2 = create(:key, user: user, title: 'ssh-rsa Key2', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQSTWXhJAX/He+nG78MiRRRn7m0Pb0XbcgTxE0etArgoFoh9WtvDf36HG6tOSg/0UUNcp0dICsNAmhBKdncp6cIyPaXJTURPRAGvhI0/VDk4bi27bRnccGbJ/hDaUxZMLhhrzY0r22mjVf8PF6dvv5QUIQVm1/LeaWYsHHvLgiIjwrXirUZPnFrZw6VLREoBKG8uWvfSXw1L5eapmstqfsME8099oi+vWLR8MgEysZQmD28M73fgW4zek6LDQzKQyJx9nB+hJkKUDvcuziZjGmRFlNgSA2mguERwL1OXonD8WYUrBDGKroIvBT39zS5d9tQDnidEJZ9Y8gv5ViYP7x Key2')
describe 'remove user with identities' do
it 'removes user with twitter identity', :aggregate_failures do
visit admin_user_identities_path(user)
visit admin_users_path
click_link 'Delete'
click_link user.name
click_link 'SSH keys'
expect(page).to have_content(user.name)
expect(page).not_to have_content('twitter')
end
end
expect(page).to have_content(key1.title)
expect(page).to have_content(key2.title)
describe 'show user keys', :js do
it do
key1 = create(:key, user: user, title: 'ssh-rsa Key1', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key1')
key2 = create(:key, user: user, title: 'ssh-rsa Key2', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQSTWXhJAX/He+nG78MiRRRn7m0Pb0XbcgTxE0etArgoFoh9WtvDf36HG6tOSg/0UUNcp0dICsNAmhBKdncp6cIyPaXJTURPRAGvhI0/VDk4bi27bRnccGbJ/hDaUxZMLhhrzY0r22mjVf8PF6dvv5QUIQVm1/LeaWYsHHvLgiIjwrXirUZPnFrZw6VLREoBKG8uWvfSXw1L5eapmstqfsME8099oi+vWLR8MgEysZQmD28M73fgW4zek6LDQzKQyJx9nB+hJkKUDvcuziZjGmRFlNgSA2mguERwL1OXonD8WYUrBDGKroIvBT39zS5d9tQDnidEJZ9Y8gv5ViYP7x Key2')
click_link key2.title
visit admin_user_path(user)
expect(page).to have_content(key2.title)
expect(page).to have_content(key2.key)
click_link 'SSH keys'
click_button 'Delete'
expect(page).to have_content(key1.title)
expect(page).to have_content(key2.title)
page.within('.modal') do
page.click_button('Delete')
end
click_link key2.title
expect(page).not_to have_content(key2.title)
end
end
expect(page).to have_content(key2.title)
expect(page).to have_content(key2.key)
describe 'show user identities' do
it 'shows user identities', :aggregate_failures do
visit admin_user_identities_path(user)
click_button 'Delete'
expect(page).to have_content(user.name)
expect(page).to have_content('twitter')
end
end
page.within('.modal') do
page.click_button('Delete')
end
describe 'update user identities' do
before do
allow(Gitlab::Auth::OAuth::Provider).to receive(:providers).and_return([:twitter, :twitter_updated])
expect(page).not_to have_content(key2.title)
end
end
it 'modifies twitter identity', :aggregate_failures do
visit admin_user_identities_path(user)
find('.table').find(:link, 'Edit').click
fill_in 'identity_extern_uid', with: '654321'
select 'twitter_updated', from: 'identity_provider'
click_button 'Save changes'
describe 'show user attributes' do
it 'has expected attributes', :aggregate_failures do
visit admin_user_path(user)
expect(page).to have_content(user.name)
expect(page).to have_content('twitter_updated')
expect(page).to have_content('654321')
expect(page).to have_content 'Account'
expect(page).to have_content 'Personal projects limit'
end
end
end
describe 'remove user with identities' do
it 'removes user with twitter identity', :aggregate_failures do
visit admin_user_identities_path(user)
[true, false].each do |vue_admin_users|
context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
click_link 'Delete'
describe 'GET /admin/users' do
context 'user pending approval' do
it 'shows user info', :aggregate_failures do
user = create(:user, :blocked_pending_approval)
expect(page).to have_content(user.name)
expect(page).not_to have_content('twitter')
visit admin_users_path
click_link 'Pending approval'
click_link user.name
expect(page).to have_content(user.name)
expect(page).to have_content('Pending approval')
expect(page).to have_link('Approve user')
expect(page).to have_link('Reject request')
end
end
end
end
end
end
......@@ -3,298 +3,305 @@
require 'spec_helper'
RSpec.describe 'Admin::Users' do
include Spec::Support::Helpers::Features::ResponsiveTableHelpers
let_it_be(:user, reload: true) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin, last_activity_on: 5.days.ago) }
let_it_be(:current_user) { create(:admin) }
before do
sign_in(current_user)
gitlab_enable_admin_mode_sign_in(current_user)
end
describe 'GET /admin/users' do
before do
stub_feature_flags(vue_admin_users: false)
visit admin_users_path
end
[true, false].each do |vue_admin_users|
context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
it "is ok" do
expect(current_path).to eq(admin_users_path)
end
describe 'GET /admin/users' do
before do
visit admin_users_path
end
it "has users list" do
expect(page).to have_content(current_user.email)
expect(page).to have_content(current_user.name)
expect(page).to have_content(current_user.created_at.strftime('%e %b, %Y'))
expect(page).to have_content(current_user.last_activity_on.strftime('%e %b, %Y'))
expect(page).to have_content(user.email)
expect(page).to have_content(user.name)
expect(page).to have_content('Projects')
expect(page).to have_button('Block')
expect(page).to have_button('Deactivate')
expect(page).to have_button('Delete user')
expect(page).to have_button('Delete user and contributions')
end
it "is ok" do
expect(current_path).to eq(admin_users_path)
end
describe 'view extra user information' do
it 'shows the user popover on hover', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/11290' do
expect(page).not_to have_selector('#__BV_popover_1__')
it "has users list" do
current_user.reload
first_user_link = page.first('.js-user-link')
first_user_link.hover
expect(page).to have_content(current_user.email)
expect(page).to have_content(current_user.name)
expect(page).to have_content(current_user.created_at.strftime('%e %b, %Y'))
expect(page).to have_content(user.email)
expect(page).to have_content(user.name)
expect(page).to have_content('Projects')
expect(page).to have_selector('#__BV_popover_1__')
end
end
click_user_dropdown_toggle(user.id)
context 'user project count' do
before do
project = create(:project)
project.add_maintainer(current_user)
end
expect(page).to have_button('Block')
expect(page).to have_button('Deactivate')
expect(page).to have_button('Delete user')
expect(page).to have_button('Delete user and contributions')
end
it 'displays count of users projects' do
visit admin_users_path
it 'clicking edit user takes us to edit page', :aggregate_failures do
page.within("[data-testid='user-actions-#{user.id}']") do
click_link 'Edit'
end
expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1")
end
end
expect(page).to have_content('Name')
expect(page).to have_content('Password')
end
describe 'tabs' do
it 'has multiple tabs to filter users' do
expect(page).to have_link('Active', href: admin_users_path)
expect(page).to have_link('Admins', href: admin_users_path(filter: 'admins'))
expect(page).to have_link('2FA Enabled', href: admin_users_path(filter: 'two_factor_enabled'))
expect(page).to have_link('2FA Disabled', href: admin_users_path(filter: 'two_factor_disabled'))
expect(page).to have_link('External', href: admin_users_path(filter: 'external'))
expect(page).to have_link('Blocked', href: admin_users_path(filter: 'blocked'))
expect(page).to have_link('Deactivated', href: admin_users_path(filter: 'deactivated'))
expect(page).to have_link('Without projects', href: admin_users_path(filter: 'wop'))
end
describe 'view extra user information' do
it 'shows the user popover on hover', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/11290' do
expect(page).not_to have_selector('#__BV_popover_1__')
context '`Pending approval` tab' do
before do
visit admin_users_path
end
first_user_link = page.first('.js-user-link')
first_user_link.hover
it 'shows the `Pending approval` tab' do
expect(page).to have_link('Pending approval', href: admin_users_path(filter: 'blocked_pending_approval'))
expect(page).to have_selector('#__BV_popover_1__')
end
end
end
end
describe 'search and sort' do
before_all do
create(:user, name: 'Foo Bar', last_activity_on: 3.days.ago)
create(:user, name: 'Foo Baz', last_activity_on: 2.days.ago)
create(:user, name: 'Dmitriy')
end
context 'user project count' do
before do
project = create(:project)
project.add_maintainer(current_user)
end
it 'searches users by name' do
visit admin_users_path(search_query: 'Foo')
it 'displays count of users projects' do
visit admin_users_path
expect(page).to have_content('Foo Bar')
expect(page).to have_content('Foo Baz')
expect(page).not_to have_content('Dmitriy')
end
expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1")
end
end
it 'sorts users by name' do
visit admin_users_path
describe 'tabs' do
it 'has multiple tabs to filter users' do
expect(page).to have_link('Active', href: admin_users_path)
expect(page).to have_link('Admins', href: admin_users_path(filter: 'admins'))
expect(page).to have_link('2FA Enabled', href: admin_users_path(filter: 'two_factor_enabled'))
expect(page).to have_link('2FA Disabled', href: admin_users_path(filter: 'two_factor_disabled'))
expect(page).to have_link('External', href: admin_users_path(filter: 'external'))
expect(page).to have_link('Blocked', href: admin_users_path(filter: 'blocked'))
expect(page).to have_link('Deactivated', href: admin_users_path(filter: 'deactivated'))
expect(page).to have_link('Without projects', href: admin_users_path(filter: 'wop'))
end
context '`Pending approval` tab' do
before do
visit admin_users_path
end
it 'shows the `Pending approval` tab' do
expect(page).to have_link('Pending approval', href: admin_users_path(filter: 'blocked_pending_approval'))
end
end
end
sort_by('Name')
describe 'search and sort' do
before_all do
create(:user, name: 'Foo Bar', last_activity_on: 3.days.ago)
create(:user, name: 'Foo Baz', last_activity_on: 2.days.ago)
create(:user, name: 'Dmitriy')
end
expect(first_row.text).to include('Dmitriy')
expect(second_row.text).to include('Foo Bar')
end
it 'searches users by name' do
visit admin_users_path(search_query: 'Foo')
it 'sorts search results only' do
visit admin_users_path(search_query: 'Foo')
expect(page).to have_content('Foo Bar')
expect(page).to have_content('Foo Baz')
expect(page).not_to have_content('Dmitriy')
end
sort_by('Name')
it 'sorts users by name' do
visit admin_users_path
expect(page).not_to have_content('Dmitriy')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
sort_by('Name')
it 'searches with respect of sorting' do
visit admin_users_path(sort: 'Name')
expect(first_row.text).to include('Dmitriy')
expect(second_row.text).to include('Foo Bar')
end
fill_in :search_query, with: 'Foo'
click_button('Search users')
it 'sorts search results only' do
visit admin_users_path(search_query: 'Foo')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
sort_by('Name')
expect(page).not_to have_content('Dmitriy')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'sorts users by recent last activity' do
visit admin_users_path(search_query: 'Foo')
it 'searches with respect of sorting' do
visit admin_users_path(sort: 'Name')
sort_by('Recent last activity')
fill_in :search_query, with: 'Foo'
click_button('Search users')
expect(first_row.text).to include('Foo Baz')
expect(second_row.text).to include('Foo Bar')
end
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'sorts users by oldest last activity' do
visit admin_users_path(search_query: 'Foo')
it 'sorts users by recent last activity' do
visit admin_users_path(search_query: 'Foo')
sort_by('Oldest last activity')
sort_by('Recent last activity')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
end
expect(first_row.text).to include('Foo Baz')
expect(second_row.text).to include('Foo Bar')
end
describe 'Two-factor Authentication filters' do
it 'counts users who have enabled 2FA' do
create(:user, :two_factor)
it 'sorts users by oldest last activity' do
visit admin_users_path(search_query: 'Foo')
visit admin_users_path
sort_by('Oldest last activity')
page.within('.filter-two-factor-enabled small') do
expect(page).to have_content('1')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
end
end
it 'filters by users who have enabled 2FA' do
user = create(:user, :two_factor)
describe 'Two-factor Authentication filters' do
it 'counts users who have enabled 2FA' do
create(:user, :two_factor)
visit admin_users_path
click_link '2FA Enabled'
visit admin_users_path
expect(page).to have_content(user.email)
end
page.within('.filter-two-factor-enabled small') do
expect(page).to have_content('1')
end
end
it 'counts users who have not enabled 2FA' do
visit admin_users_path
it 'filters by users who have enabled 2FA' do
user = create(:user, :two_factor)
page.within('.filter-two-factor-disabled small') do
expect(page).to have_content('2') # Including admin
end
end
visit admin_users_path
click_link '2FA Enabled'
it 'filters by users who have not enabled 2FA' do
visit admin_users_path
click_link '2FA Disabled'
expect(page).to have_content(user.email)
end
expect(page).to have_content(user.email)
end
end
it 'counts users who have not enabled 2FA' do
visit admin_users_path
describe 'Pending approval filter' do
it 'counts users who are pending approval' do
create_list(:user, 2, :blocked_pending_approval)
page.within('.filter-two-factor-disabled small') do
expect(page).to have_content('2') # Including admin
end
end
visit admin_users_path
it 'filters by users who have not enabled 2FA' do
visit admin_users_path
click_link '2FA Disabled'
page.within('.filter-blocked-pending-approval small') do
expect(page).to have_content('2')
expect(page).to have_content(user.email)
end
end
end
it 'filters by users who are pending approval' do
user = create(:user, :blocked_pending_approval)
describe 'Pending approval filter' do
it 'counts users who are pending approval' do
create_list(:user, 2, :blocked_pending_approval)
visit admin_users_path
click_link 'Pending approval'
visit admin_users_path
expect(page).to have_content(user.email)
end
end
page.within('.filter-blocked-pending-approval small') do
expect(page).to have_content('2')
end
end
context 'when blocking/unblocking a user' do
it 'shows confirmation and allows blocking and unblocking', :js do
expect(page).to have_content(user.email)
it 'filters by users who are pending approval' do
user = create(:user, :blocked_pending_approval)
click_action_in_user_dropdown(user.id, 'Block')
visit admin_users_path
click_link 'Pending approval'
wait_for_requests
expect(page).to have_content(user.email)
end
end
expect(page).to have_content('Block user')
expect(page).to have_content('Blocking user has the following effects')
expect(page).to have_content('User will not be able to login')
expect(page).to have_content('Owned groups will be left')
context 'when blocking/unblocking a user' do
it 'shows confirmation and allows blocking and unblocking', :js do
expect(page).to have_content(user.email)
find('.modal-footer button', text: 'Block').click
click_action_in_user_dropdown(user.id, 'Block')
wait_for_requests
wait_for_requests
expect(page).to have_content('Successfully blocked')
expect(page).not_to have_content(user.email)
expect(page).to have_content('Block user')
expect(page).to have_content('Blocking user has the following effects')
expect(page).to have_content('User will not be able to login')
expect(page).to have_content('Owned groups will be left')
click_link 'Blocked'
find('.modal-footer button', text: 'Block').click
wait_for_requests
wait_for_requests
expect(page).to have_content(user.email)
expect(page).to have_content('Successfully blocked')
expect(page).not_to have_content(user.email)
click_action_in_user_dropdown(user.id, 'Unblock')
click_link 'Blocked'
expect(page).to have_content('Unblock user')
expect(page).to have_content('You can always block their account again if needed.')
wait_for_requests
find('.modal-footer button', text: 'Unblock').click
expect(page).to have_content(user.email)
wait_for_requests
click_action_in_user_dropdown(user.id, 'Unblock')
expect(page).to have_content('Successfully unblocked')
expect(page).not_to have_content(user.email)
end
end
expect(page).to have_content('Unblock user')
expect(page).to have_content('You can always block their account again if needed.')
context 'when deactivating/re-activating a user' do
it 'shows confirmation and allows deactivating and re-activating', :js do
expect(page).to have_content(user.email)
find('.modal-footer button', text: 'Unblock').click
click_action_in_user_dropdown(user.id, 'Deactivate')
wait_for_requests
expect(page).to have_content('Deactivate user')
expect(page).to have_content('Deactivating a user has the following effects')
expect(page).to have_content('The user will be logged out')
expect(page).to have_content('Personal projects, group and user history will be left intact')
expect(page).to have_content('Successfully unblocked')
expect(page).not_to have_content(user.email)
end
end
find('.modal-footer button', text: 'Deactivate').click
context 'when deactivating/re-activating a user' do
it 'shows confirmation and allows deactivating and re-activating', :js do
expect(page).to have_content(user.email)
wait_for_requests
click_action_in_user_dropdown(user.id, 'Deactivate')
expect(page).to have_content('Successfully deactivated')
expect(page).not_to have_content(user.email)
expect(page).to have_content('Deactivate user')
expect(page).to have_content('Deactivating a user has the following effects')
expect(page).to have_content('The user will be logged out')
expect(page).to have_content('Personal projects, group and user history will be left intact')
click_link 'Deactivated'
find('.modal-footer button', text: 'Deactivate').click
wait_for_requests
wait_for_requests
expect(page).to have_content(user.email)
expect(page).to have_content('Successfully deactivated')
expect(page).not_to have_content(user.email)
click_action_in_user_dropdown(user.id, 'Activate')
click_link 'Deactivated'
expect(page).to have_content('Activate user')
expect(page).to have_content('You can always deactivate their account again if needed.')
wait_for_requests
find('.modal-footer button', text: 'Activate').click
expect(page).to have_content(user.email)
wait_for_requests
click_action_in_user_dropdown(user.id, 'Activate')
expect(page).to have_content('Successfully activated')
expect(page).not_to have_content(user.email)
end
end
expect(page).to have_content('Activate user')
expect(page).to have_content('You can always deactivate their account again if needed.')
def click_action_in_user_dropdown(user_id, action)
find("[data-testid='user-action-button-#{user_id}']").click
find('.modal-footer button', text: 'Activate').click
within find("[data-testid='user-action-dropdown-#{user_id}']") do
find('li button', text: action).click
end
wait_for_requests
wait_for_requests
expect(page).to have_content('Successfully activated')
expect(page).not_to have_content(user.email)
end
end
end
end
end
describe 'GET /admin/users/new' do
let(:user_username) { 'bang' }
let_it_be(:user_username) { 'bang' }
before do
visit new_admin_user_path
......@@ -344,7 +351,7 @@ RSpec.describe 'Admin::Users' do
end
context 'username contains spaces' do
let(:user_username) { 'Bing bang' }
let_it_be(:user_username) { 'Bing bang' }
it "doesn't create the user and shows an error message" do
expect { click_button 'Create user' }.to change {User.count}.by(0)
......@@ -363,22 +370,6 @@ RSpec.describe 'Admin::Users' do
visit new_admin_user_path
end
def expects_external_to_be_checked
expect(find('#user_external')).to be_checked
end
def expects_external_to_be_unchecked
expect(find('#user_external')).not_to be_checked
end
def expects_warning_to_be_hidden
expect(find('#warning_external_automatically_set', visible: :all)[:class]).to include 'hidden'
end
def expects_warning_to_be_shown
expect(find('#warning_external_automatically_set')[:class]).not_to include 'hidden'
end
it 'automatically unchecks external for matching email' do
expects_external_to_be_checked
expects_warning_to_be_hidden
......@@ -413,55 +404,22 @@ RSpec.describe 'Admin::Users' do
expect(new_user.external).to be_falsy
end
end
end
end
describe 'GET /admin/users/:id/edit' do
before do
stub_feature_flags(vue_admin_users: false)
visit admin_users_path
click_link "edit_user_#{user.id}"
end
it 'has user edit page' do
expect(page).to have_content('Name')
expect(page).to have_content('Password')
end
describe 'Update user' do
before do
fill_in 'user_name', with: 'Big Bang'
fill_in 'user_email', with: 'bigbang@mail.com'
fill_in 'user_password', with: 'AValidPassword1'
fill_in 'user_password_confirmation', with: 'AValidPassword1'
choose 'user_access_level_admin'
click_button 'Save changes'
end
it 'shows page with new data' do
expect(page).to have_content('bigbang@mail.com')
expect(page).to have_content('Big Bang')
end
it 'changes user entry' do
user.reload
expect(user.name).to eq('Big Bang')
expect(user.admin?).to be_truthy
expect(user.password_expires_at).to be <= Time.now
end
end
def expects_external_to_be_checked
expect(find('#user_external')).to be_checked
end
describe 'update username to non ascii char' do
it do
fill_in 'user_username', with: '\u3042\u3044'
click_button('Save')
def expects_external_to_be_unchecked
expect(find('#user_external')).not_to be_checked
end
page.within '#error_explanation' do
expect(page).to have_content('Username')
def expects_warning_to_be_hidden
expect(find('#warning_external_automatically_set', visible: :all)[:class]).to include 'hidden'
end
expect(page).to have_selector(%(form[action="/admin/users/#{user.username}"]))
def expects_warning_to_be_shown
expect(find('#warning_external_automatically_set')[:class]).not_to include 'hidden'
end
end
end
end
......@@ -541,15 +499,82 @@ RSpec.describe 'Admin::Users' do
check_breadcrumb('Edit Identity')
end
def check_breadcrumb(content)
expect(find('.breadcrumbs-sub-title')).to have_content(content)
end
end
describe 'GET /admin/users/:id/edit' do
before do
visit edit_admin_user_path(user)
end
describe 'Update user' do
before do
fill_in 'user_name', with: 'Big Bang'
fill_in 'user_email', with: 'bigbang@mail.com'
fill_in 'user_password', with: 'AValidPassword1'
fill_in 'user_password_confirmation', with: 'AValidPassword1'
choose 'user_access_level_admin'
click_button 'Save changes'
end
it 'shows page with new data' do
expect(page).to have_content('bigbang@mail.com')
expect(page).to have_content('Big Bang')
end
it 'changes user entry' do
user.reload
expect(user.name).to eq('Big Bang')
expect(user.admin?).to be_truthy
expect(user.password_expires_at).to be <= Time.now
end
end
describe 'update username to non ascii char' do
it do
fill_in 'user_username', with: '\u3042\u3044'
click_button('Save')
page.within '#error_explanation' do
expect(page).to have_content('Username')
end
expect(page).to have_selector(%(form[action="/admin/users/#{user.username}"]))
end
end
end
def check_breadcrumb(content)
expect(find('.breadcrumbs-sub-title')).to have_content(content)
def click_user_dropdown_toggle(user_id)
page.within("[data-testid='user-actions-#{user_id}']") do
find("[data-testid='dropdown-toggle']").click
end
end
def first_row
page.all('[role="row"]')[1]
end
def second_row
page.all('[role="row"]')[2]
end
def sort_by(text)
page.within('.user-sort-dropdown') do
click_link text
def sort_by(option)
page.within('.filtered-search-block') do
find('.dropdown-menu-toggle').click
click_link option
end
end
def click_action_in_user_dropdown(user_id, action)
click_user_dropdown_toggle(user_id)
within find("[data-testid='user-actions-#{user_id}']") do
find('li button', text: action).click
end
wait_for_requests
end
end
import { GlDropdownDivider } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Actions from '~/admin/users/components/actions';
import AdminUserActions from '~/admin/users/components/user_actions.vue';
import { I18N_USER_ACTIONS } from '~/admin/users/constants';
......@@ -14,12 +14,14 @@ describe('AdminUserActions component', () => {
const user = users[0];
const userPaths = generateUserPaths(paths, user.username);
const findEditButton = () => wrapper.find('[data-testid="edit"]');
const findActionsDropdown = () => wrapper.find('[data-testid="actions"');
const findDropdownDivider = () => wrapper.find(GlDropdownDivider);
const findUserActions = (id) => wrapper.findByTestId(`user-actions-${id}`);
const findEditButton = (id = user.id) => findUserActions(id).find('[data-testid="edit"]');
const findActionsDropdown = (id = user.id) =>
findUserActions(id).find('[data-testid="dropdown-toggle"]');
const findDropdownDivider = () => wrapper.findComponent(GlDropdownDivider);
const initComponent = ({ actions = [] } = {}) => {
wrapper = shallowMount(AdminUserActions, {
wrapper = shallowMountExtended(AdminUserActions, {
propsData: {
user: {
...user,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment