2017-03-01 08:31:56 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Dashboard Groups page', :js do
|
2017-10-11 07:38:12 -04:00
|
|
|
let(:user) { create :user }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:nested_group) { create(:group, :nested) }
|
|
|
|
let(:another_group) { create(:group) }
|
2017-03-01 08:31:56 -05:00
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
def click_group_caret(group)
|
|
|
|
within("#group-#{group.id}") do
|
|
|
|
first('.folder-caret').click
|
|
|
|
end
|
|
|
|
wait_for_requests
|
2017-09-13 11:16:30 -04:00
|
|
|
end
|
|
|
|
|
2017-06-07 23:42:41 -04:00
|
|
|
it 'shows groups user is member of' do
|
2017-03-01 08:31:56 -05:00
|
|
|
group.add_owner(user)
|
|
|
|
nested_group.add_owner(user)
|
2017-10-11 07:38:12 -04:00
|
|
|
expect(another_group).to be_persisted
|
2017-03-01 08:31:56 -05:00
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-03-01 08:31:56 -05:00
|
|
|
visit dashboard_groups_path
|
2017-10-04 10:10:24 -04:00
|
|
|
wait_for_requests
|
2017-03-01 08:31:56 -05:00
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
expect(page).to have_content(group.name)
|
|
|
|
|
2017-10-12 03:44:53 -04:00
|
|
|
expect(page).not_to have_content(another_group.name)
|
2017-03-01 08:31:56 -05:00
|
|
|
end
|
|
|
|
|
2017-10-12 03:44:53 -04:00
|
|
|
it 'shows subgroups the user is member of', :nested_groups do
|
|
|
|
group.add_owner(user)
|
|
|
|
nested_group.add_owner(user)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
visit dashboard_groups_path
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page).to have_content(nested_group.parent.name)
|
2017-10-05 07:13:24 -04:00
|
|
|
click_group_caret(nested_group.parent)
|
|
|
|
expect(page).to have_content(nested_group.name)
|
2017-03-01 08:31:56 -05:00
|
|
|
end
|
|
|
|
|
2018-05-01 05:24:21 -04:00
|
|
|
context 'when filtering groups', :nested_groups do
|
2017-06-07 23:42:41 -04:00
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
nested_group.add_owner(user)
|
2017-10-11 07:38:12 -04:00
|
|
|
expect(another_group).to be_persisted
|
2017-03-01 08:31:56 -05:00
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-06-07 23:42:41 -04:00
|
|
|
|
|
|
|
visit dashboard_groups_path
|
|
|
|
end
|
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
it 'expands when filtering groups' do
|
|
|
|
fill_in 'filter', with: nested_group.name
|
2017-06-07 23:42:41 -04:00
|
|
|
wait_for_requests
|
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
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-06-07 23:42:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'resets search when user cleans the input' do
|
2017-10-04 10:10:24 -04:00
|
|
|
fill_in 'filter', with: group.name
|
2017-06-07 23:42:41 -04:00
|
|
|
wait_for_requests
|
|
|
|
|
2018-06-14 22:31:54 -04:00
|
|
|
expect(page).to have_content(group.name)
|
|
|
|
expect(page).not_to have_content(nested_group.parent.name)
|
|
|
|
|
2017-10-04 10:10:24 -04:00
|
|
|
fill_in 'filter', with: ''
|
2018-06-14 22:31:54 -04:00
|
|
|
page.find('[name="filter"]').send_keys(:enter)
|
2017-06-07 23:42:41 -04:00
|
|
|
wait_for_requests
|
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
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-06-07 23:42:41 -04:00
|
|
|
expect(page.all('.js-groups-list-holder .content-list li').length).to eq 2
|
|
|
|
end
|
2017-03-01 08:31:56 -05:00
|
|
|
end
|
2017-03-02 06:05:48 -05:00
|
|
|
|
2018-05-01 05:24:21 -04:00
|
|
|
context 'with subgroups', :nested_groups do
|
2017-06-07 23:42:41 -04:00
|
|
|
let!(:subgroup) { create(:group, :public, parent: group) }
|
2017-03-02 06:05:48 -05:00
|
|
|
|
2017-06-07 23:42:41 -04:00
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
subgroup.add_owner(user)
|
2017-03-02 06:05:48 -05:00
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-06-07 23:42:41 -04:00
|
|
|
|
|
|
|
visit dashboard_groups_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows subgroups inside of its parent group' do
|
2017-10-05 07:13:24 -04:00
|
|
|
expect(page).to have_selector("#group-#{group.id}")
|
|
|
|
click_group_caret(group)
|
|
|
|
expect(page).to have_selector("#group-#{group.id} #group-#{subgroup.id}")
|
2017-06-07 23:42:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can toggle parent group' do
|
2017-10-05 07:13:24 -04:00
|
|
|
# expand
|
|
|
|
click_group_caret(group)
|
2017-06-07 23:42:41 -04:00
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
expect(page).to have_selector("#group-#{group.id} #group-#{subgroup.id}")
|
2017-06-07 23:42:41 -04:00
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
# collapse
|
|
|
|
click_group_caret(group)
|
2017-06-07 23:42:41 -04:00
|
|
|
|
2017-10-05 07:13:24 -04:00
|
|
|
expect(page).not_to have_selector("#group-#{group.id} #group-#{subgroup.id}")
|
2017-06-07 23:42:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-01 05:24:21 -04:00
|
|
|
context 'when using pagination' do
|
2017-10-11 07:38:12 -04:00
|
|
|
let(:group) { create(:group, created_at: 5.days.ago) }
|
|
|
|
let(:group2) { create(:group, created_at: 2.days.ago) }
|
2017-06-07 23:42:41 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
group2.add_owner(user)
|
|
|
|
|
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
|
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-06-07 23:42:41 -04:00
|
|
|
visit dashboard_groups_path
|
|
|
|
end
|
|
|
|
|
2017-10-11 07:38:12 -04:00
|
|
|
it 'loads results for next page' do
|
2017-06-07 23:42:41 -04:00
|
|
|
expect(page).to have_selector('.gl-pagination .page', count: 2)
|
|
|
|
|
|
|
|
# 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
|
2017-06-17 02:08:27 -04:00
|
|
|
find(".gl-pagination .page:not(.active) a").click
|
2017-06-07 23:42:41 -04:00
|
|
|
|
|
|
|
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-03-02 06:05:48 -05:00
|
|
|
end
|
2018-05-01 05:24:21 -04:00
|
|
|
|
|
|
|
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-03-01 08:31:56 -05:00
|
|
|
end
|