2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'User views releases', :js do
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:today) { Time.zone.now }
|
|
|
|
let_it_be(:yesterday) { today - 1.day }
|
|
|
|
let_it_be(:tomorrow) { today + 1.day }
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
let_it_be(:project) { create(:project, :repository, :private) }
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:release_v1) { create(:release, project: project, tag: 'v1', name: 'The first release', released_at: yesterday, created_at: today) }
|
|
|
|
let_it_be(:release_v2) { create(:release, project: project, tag: 'v2-with-a/slash', name: 'The second release', released_at: today, created_at: yesterday) }
|
|
|
|
let_it_be(:release_v3) { create(:release, project: project, tag: 'v3', name: 'The third release', released_at: tomorrow, created_at: tomorrow) }
|
2020-04-22 19:07:51 +05:30
|
|
|
let_it_be(:maintainer) { create(:user) }
|
|
|
|
let_it_be(:guest) { create(:user) }
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
before do
|
2020-04-22 19:07:51 +05:30
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
project.add_guest(guest)
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
shared_examples 'releases page' do
|
|
|
|
context('when the user is a maintainer') do
|
|
|
|
before do
|
2021-01-03 14:25:43 +05:30
|
|
|
sign_in(maintainer)
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
visit project_releases_path(project)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'sees the release' do
|
|
|
|
page.within("##{release_v1.tag}") do
|
|
|
|
expect(page).to have_content(release_v1.name)
|
|
|
|
expect(page).to have_content(release_v1.tag)
|
|
|
|
expect(page).not_to have_content('Upcoming Release')
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'when there is a link as an asset' do
|
2021-01-29 00:20:46 +05:30
|
|
|
let!(:release_link) { create(:release_link, release: release_v1, url: url ) }
|
2021-01-03 14:25:43 +05:30
|
|
|
let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
|
2021-01-29 00:20:46 +05:30
|
|
|
let(:direct_asset_link) { Gitlab::Routing.url_helpers.project_release_url(project, release_v1) << "/downloads#{release_link.filepath}" }
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it 'sees the link' do
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within("##{release_v1.tag} .js-assets-list") do
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(page).to have_link release_link.name, href: direct_asset_link
|
|
|
|
expect(page).not_to have_css('[data-testid="external-link-indicator"]')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a link redirect' do
|
2021-01-29 00:20:46 +05:30
|
|
|
let!(:release_link) { create(:release_link, release: release_v1, name: 'linux-amd64 binaries', filepath: '/binaries/linux-amd64', url: url) }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:url) { "#{project.web_url}/-/jobs/1/artifacts/download" }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'sees the link' do
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within("##{release_v1.tag} .js-assets-list") do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(page).to have_link release_link.name, href: direct_asset_link
|
|
|
|
expect(page).not_to have_css('[data-testid="external-link-indicator"]')
|
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'when url points to external resource' do
|
|
|
|
let(:url) { 'http://google.com/download' }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it 'sees that the link is external resource' do
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within("##{release_v1.tag} .js-assets-list") do
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(page).to have_css('[data-testid="external-link-indicator"]')
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'with an upcoming release' do
|
|
|
|
it 'sees the upcoming tag' do
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within("##{release_v3.tag}") do
|
|
|
|
expect(page).to have_content('Upcoming Release')
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a tag containing a slash' do
|
|
|
|
it 'sees the release' do
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within("##{release_v2.tag.parameterize}") do
|
|
|
|
expect(page).to have_content(release_v2.name)
|
|
|
|
expect(page).to have_content(release_v2.tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'sorting' do
|
|
|
|
def sort_page(by:, direction:)
|
|
|
|
within '[data-testid="releases-sort"]' do
|
|
|
|
find('.dropdown-toggle').click
|
|
|
|
|
|
|
|
click_button(by, class: 'dropdown-item')
|
|
|
|
|
|
|
|
find('.sorting-direction-button').click if direction == :ascending
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'releases sort order' do
|
|
|
|
it "sorts the releases #{description}" do
|
|
|
|
card_titles = page.all('.release-block .card-title', minimum: expected_releases.count)
|
|
|
|
|
|
|
|
card_titles.each_with_index do |title, index|
|
|
|
|
expect(title).to have_content(expected_releases[index].name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the page is sorted by the default sort order" do
|
|
|
|
let(:expected_releases) { [release_v3, release_v2, release_v1] }
|
|
|
|
|
|
|
|
it_behaves_like 'releases sort order'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the page is sorted by created_at ascending " do
|
|
|
|
let(:expected_releases) { [release_v2, release_v1, release_v3] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sort_page by: 'Created date', direction: :ascending
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it_behaves_like 'releases sort order'
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context('when the user is a guest') do
|
|
|
|
before do
|
2021-01-03 14:25:43 +05:30
|
|
|
sign_in(guest)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders release info except for Git-related data' do
|
2020-04-22 19:07:51 +05:30
|
|
|
visit project_releases_path(project)
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
within('.release-block', match: :first) do
|
|
|
|
expect(page).to have_content(release_v3.description)
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
# The following properties (sometimes) include Git info,
|
|
|
|
# so they are not rendered for Guest users
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(page).not_to have_content(release_v3.name)
|
|
|
|
expect(page).not_to have_content(release_v3.tag)
|
|
|
|
expect(page).not_to have_content(release_v3.commit.short_id)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
2020-01-12 00:16:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when the graphql_releases_page feature flag is enabled' do
|
|
|
|
it_behaves_like 'releases page'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the graphql_releases_page feature flag is disabled' do
|
2020-04-22 19:07:51 +05:30
|
|
|
before do
|
2020-11-24 15:15:51 +05:30
|
|
|
stub_feature_flags(graphql_releases_page: false)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it_behaves_like 'releases page'
|
2020-01-12 00:16:45 +05:30
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|