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

165 lines
4.5 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2018-11-08 19:23:39 +05:30
describe 'Dashboard Groups page', :js 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
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
it 'shows subgroups the user is member of', :nested_groups do
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
2018-10-15 14:42:47 +05:30
context 'when filtering groups', :nested_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)
2017-09-10 17:25:29 +05:30
expect(page.all('.js-groups-list-holder .content-list li').length).to eq 2
end
2017-08-17 22:00:37 +05:30
end
2018-10-15 14:42:47 +05:30
context 'with subgroups', :nested_groups 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
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
2017-08-17 22:00:37 +05:30
end