debian-mirror-gitlab/spec/features/dashboard/groups_list_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

241 lines
6.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Dashboard Groups page', :js, feature_category: :subgroups do
2018-03-17 18:26:18 +05:30
let(:user) { create :user }
let(:group) { create(:group) }
let(:nested_group) { create(:group, :nested) }
let(:another_group) { create(:group) }
def click_group_caret(group)
within("#group-#{group.id}") do
first('.folder-caret').click
end
wait_for_requests
end
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
def click_options_menu(group)
page.find("[data-testid='group-#{group.id}-dropdown-button'").click
end
2023-06-20 00:43:36 +05:30
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :dashboard_groups_path, :groups
2023-03-17 16:20:25 +05:30
2017-09-10 17:25:29 +05:30
it 'shows groups user is member of' do
2017-08-17 22:00:37 +05:30
group.add_owner(user)
nested_group.add_owner(user)
2018-03-17 18:26:18 +05:30
expect(another_group).to be_persisted
sign_in(user)
visit dashboard_groups_path
wait_for_requests
expect(page).to have_content(group.name)
expect(page).not_to have_content(another_group.name)
end
2019-10-12 21:52:04 +05:30
it 'shows subgroups the user is member of' do
2018-03-17 18:26:18 +05:30
group.add_owner(user)
nested_group.add_owner(user)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
visit dashboard_groups_path
2018-03-17 18:26:18 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(page).to have_content(nested_group.parent.name)
click_group_caret(nested_group.parent)
expect(page).to have_content(nested_group.name)
2017-08-17 22:00:37 +05:30
end
2019-10-12 21:52:04 +05:30
context 'when filtering groups' do
2017-09-10 17:25:29 +05:30
before do
group.add_owner(user)
nested_group.add_owner(user)
2018-03-17 18:26:18 +05:30
expect(another_group).to be_persisted
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
sign_in(user)
visit dashboard_groups_path
end
2018-03-17 18:26:18 +05:30
it 'expands when filtering groups' do
fill_in 'filter', with: nested_group.name
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
expect(page).not_to have_content(group.name)
expect(page).to have_content(nested_group.parent.name)
expect(page).to have_content(nested_group.name)
expect(page).not_to have_content(another_group.name)
2017-09-10 17:25:29 +05:30
end
it 'resets search when user cleans the input' do
2018-03-17 18:26:18 +05:30
fill_in 'filter', with: group.name
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-11-08 19:23:39 +05:30
expect(page).to have_content(group.name)
expect(page).not_to have_content(nested_group.parent.name)
2018-03-17 18:26:18 +05:30
fill_in 'filter', with: ''
2018-11-08 19:23:39 +05:30
page.find('[name="filter"]').send_keys(:enter)
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
expect(page).to have_content(group.name)
expect(page).to have_content(nested_group.parent.name)
expect(page).not_to have_content(another_group.name)
2020-04-22 19:07:51 +05:30
expect(page.all('.js-groups-list-holder .groups-list li').length).to eq 2
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
end
2019-10-12 21:52:04 +05:30
context 'with subgroups' do
2017-09-10 17:25:29 +05:30
let!(:subgroup) { create(:group, :public, parent: group) }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
before do
group.add_owner(user)
subgroup.add_owner(user)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
sign_in(user)
visit dashboard_groups_path
end
it 'shows subgroups inside of its parent group' do
2018-03-17 18:26:18 +05:30
expect(page).to have_selector("#group-#{group.id}")
click_group_caret(group)
expect(page).to have_selector("#group-#{group.id} #group-#{subgroup.id}")
2017-09-10 17:25:29 +05:30
end
it 'can toggle parent group' do
2018-03-17 18:26:18 +05:30
# expand
click_group_caret(group)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
expect(page).to have_selector("#group-#{group.id} #group-#{subgroup.id}")
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
# collapse
click_group_caret(group)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
expect(page).not_to have_selector("#group-#{group.id} #group-#{subgroup.id}")
2017-09-10 17:25:29 +05:30
end
end
2022-04-04 11:22:00 +05:30
context 'group actions dropdown' do
let!(:subgroup) { create(:group, :public, parent: group) }
context 'user with subgroup ownership' do
before do
subgroup.add_owner(user)
sign_in(user)
visit dashboard_groups_path
end
it 'cannot remove parent group' do
expect(page).not_to have_selector("[data-testid='group-#{group.id}-dropdown-button'")
end
end
context 'user with parent group ownership' do
before do
group.add_owner(user)
sign_in(user)
visit dashboard_groups_path
end
it 'can remove parent group' do
click_options_menu(group)
expect(page).to have_selector("[data-testid='remove-group-#{group.id}-btn']")
end
it 'can remove subgroups' do
click_group_caret(group)
click_options_menu(subgroup)
expect(page).to have_selector("[data-testid='remove-group-#{subgroup.id}-btn']")
end
end
context 'user is a maintainer' do
before do
group.add_maintainer(user)
sign_in(user)
visit dashboard_groups_path
click_options_menu(group)
end
it 'cannot remove the group' do
expect(page).not_to have_selector("[data-testid='remove-group-#{group.id}-btn']")
end
it 'cannot edit the group' do
expect(page).not_to have_selector("[data-testid='edit-group-#{group.id}-btn']")
end
it 'can leave the group' do
expect(page).to have_selector("[data-testid='leave-group-#{group.id}-btn']")
end
end
end
2018-10-15 14:42:47 +05:30
context 'when using pagination' do
2018-03-17 18:26:18 +05:30
let(:group) { create(:group, created_at: 5.days.ago) }
let(:group2) { create(:group, created_at: 2.days.ago) }
2017-09-10 17:25:29 +05:30
before do
group.add_owner(user)
group2.add_owner(user)
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
sign_in(user)
visit dashboard_groups_path
end
2018-03-17 18:26:18 +05:30
it 'loads results for next page' do
2019-09-04 21:01:54 +05:30
expect(page).to have_selector('.gl-pagination .page-item a.page-link', count: 3)
2017-09-10 17:25:29 +05:30
# Check first page
expect(page).to have_content(group2.full_name)
expect(page).to have_selector("#group-#{group2.id}")
expect(page).not_to have_content(group.full_name)
expect(page).not_to have_selector("#group-#{group.id}")
# Go to next page
2019-09-04 21:01:54 +05:30
find('.gl-pagination .page-item:last-of-type a.page-link').click
2017-09-10 17:25:29 +05:30
wait_for_requests
# Check second page
expect(page).to have_content(group.full_name)
expect(page).to have_selector("#group-#{group.id}")
expect(page).not_to have_content(group2.full_name)
expect(page).not_to have_selector("#group-#{group2.id}")
end
2017-08-17 22:00:37 +05:30
end
2018-10-15 14:42:47 +05:30
context 'when signed in as admin' do
let(:admin) { create(:admin) }
it 'shows only groups admin is member of' do
group.add_owner(admin)
expect(another_group).to be_persisted
sign_in(admin)
visit dashboard_groups_path
wait_for_requests
expect(page).to have_content(group.name)
expect(page).not_to have_content(another_group.name)
end
end
2023-05-27 22:25:52 +05:30
it 'links to the "Explore groups" page' do
sign_in(user)
visit dashboard_groups_path
expect(page).to have_link("Explore groups", href: explore_groups_path)
end
2017-08-17 22:00:37 +05:30
end