2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.shared_examples 'packages list' do |check_project_name: false|
|
|
|
|
it 'shows a list of packages' do
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
packages.each_with_index do |pkg, index|
|
|
|
|
package_row = package_table_row(index)
|
|
|
|
|
|
|
|
expect(package_row).to have_content(pkg.name)
|
|
|
|
expect(package_row).to have_content(pkg.version)
|
|
|
|
expect(package_row).to have_content(pkg.project.name) if check_project_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_table_row(index)
|
2021-10-27 15:23:28 +05:30
|
|
|
page.all("#{packages_table_selector} > [data-qa-selector=\"package_row\"]")[index].text # rubocop:disable QA/SelectorUsage
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'package details link' do |property|
|
|
|
|
let(:package) { packages.first }
|
|
|
|
|
|
|
|
it 'navigates to the correct url' do
|
|
|
|
page.within(packages_table_selector) do
|
|
|
|
click_link package.name
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_current_path(project_package_path(package.project, package))
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(page).to have_css('.packages-app h2[data-testid="title"]', text: package.name)
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(page).to have_content('Installation')
|
|
|
|
expect(page).to have_content('Registry setup')
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'when there are no packages' do
|
|
|
|
it 'displays the empty message' do
|
|
|
|
expect(page).to have_content('There are no packages yet')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'correctly sorted packages list' do |order_by, ascending: false|
|
|
|
|
context "ordered by #{order_by} and ascending #{ascending}" do
|
|
|
|
before do
|
|
|
|
click_sort_option(order_by, ascending)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'packages list'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'shared package sorting' do
|
|
|
|
it_behaves_like 'correctly sorted packages list', 'Type' do
|
|
|
|
let(:packages) { [package_two, package_one] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'correctly sorted packages list', 'Type', ascending: true do
|
|
|
|
let(:packages) { [package_one, package_two] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'correctly sorted packages list', 'Name' do
|
|
|
|
let(:packages) { [package_two, package_one] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'correctly sorted packages list', 'Name', ascending: true do
|
|
|
|
let(:packages) { [package_one, package_two] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'correctly sorted packages list', 'Version' do
|
|
|
|
let(:packages) { [package_one, package_two] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'correctly sorted packages list', 'Version', ascending: true do
|
|
|
|
let(:packages) { [package_two, package_one] }
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like 'correctly sorted packages list', 'Published' do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:packages) { [package_two, package_one] }
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like 'correctly sorted packages list', 'Published', ascending: true do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:packages) { [package_one, package_two] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def packages_table_selector
|
2021-10-27 15:23:28 +05:30
|
|
|
'[data-qa-selector="packages-table"]' # rubocop:disable QA/SelectorUsage
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def click_sort_option(option, ascending)
|
2021-12-11 22:18:48 +05:30
|
|
|
wait_for_requests
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
# Reset the sort direction
|
|
|
|
if page.has_selector?('button[aria-label="Sorting Direction: Ascending"]', wait: 0) && !ascending
|
|
|
|
click_button 'Sort direction'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
find('button.gl-dropdown-toggle').click
|
|
|
|
|
|
|
|
page.within('.dropdown-menu') do
|
|
|
|
click_button option
|
|
|
|
end
|
|
|
|
|
|
|
|
if ascending
|
|
|
|
wait_for_requests
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
click_button 'Sort direction'
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|