2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ReleasesHelper do
|
2019-12-04 20:38:33 +05:30
|
|
|
describe '#illustration' do
|
|
|
|
it 'returns the correct image path' do
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(helper.illustration).to match(%r{illustrations/releases-(\w+)\.svg})
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
describe '#releases_help_page_path' do
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'returns the correct link to the help page' do
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(helper.releases_help_page_path).to include('user/project/releases/index')
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'url helpers' do
|
|
|
|
let(:project) { build(:project, namespace: create(:group)) }
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:release) { create(:release, project: project) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:can_user_create_release) { false }
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:common_keys) { [:project_id, :project_path, :illustration_path, :documentation_path] }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-12-04 20:38:33 +05:30
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
2019-12-26 22:10:19 +05:30
|
|
|
helper.instance_variable_set(:@release, release)
|
2020-04-08 14:13:33 +05:30
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:can?)
|
|
|
|
.with(user, :create_release, project)
|
|
|
|
.and_return(can_user_create_release)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
describe '#data_for_releases_page' do
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'includes the required data for displaying release blocks' do
|
|
|
|
expect(helper.data_for_releases_page.keys).to contain_exactly(*common_keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is allowed to create a new release' do
|
|
|
|
let(:can_user_create_release) { true }
|
|
|
|
|
|
|
|
it 'includes new_release_path' do
|
|
|
|
expect(helper.data_for_releases_page.keys).to contain_exactly(*common_keys, :new_release_path)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'points new_release_path to the "New Release" page' do
|
|
|
|
expect(helper.data_for_releases_page[:new_release_path]).to eq(new_project_release_path(project))
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
context 'new releases redirect new milestone creation' do
|
|
|
|
it 'redirects new_milestone_path back to the release page' do
|
|
|
|
expect(helper.data_for_new_release_page[:new_milestone_path]).to include('redirect_path')
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe '#data_for_edit_release_page' do
|
|
|
|
it 'has the needed data to display the "edit release" page' do
|
|
|
|
keys = %i(project_id
|
2021-01-29 00:20:46 +05:30
|
|
|
group_id
|
|
|
|
group_milestones_available
|
2021-01-03 14:25:43 +05:30
|
|
|
project_path
|
2019-12-26 22:10:19 +05:30
|
|
|
tag_name
|
|
|
|
markdown_preview_path
|
|
|
|
markdown_docs_path
|
|
|
|
releases_page_path
|
2020-05-24 23:13:21 +05:30
|
|
|
release_assets_docs_path
|
|
|
|
manage_milestones_path
|
2022-07-16 23:28:13 +05:30
|
|
|
new_milestone_path
|
2022-08-13 15:12:31 +05:30
|
|
|
upcoming_release_docs_path
|
|
|
|
edit_release_docs_path
|
|
|
|
delete_release_docs_path)
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(helper.data_for_edit_release_page.keys).to match_array(keys)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#data_for_new_release_page' do
|
|
|
|
it 'has the needed data to display the "new release" page' do
|
|
|
|
keys = %i(project_id
|
2021-01-29 00:20:46 +05:30
|
|
|
group_id
|
|
|
|
group_milestones_available
|
2021-01-03 14:25:43 +05:30
|
|
|
project_path
|
2022-08-13 15:12:31 +05:30
|
|
|
tag_name
|
2020-10-24 23:57:45 +05:30
|
|
|
releases_page_path
|
2020-07-28 23:09:34 +05:30
|
|
|
markdown_preview_path
|
|
|
|
markdown_docs_path
|
|
|
|
release_assets_docs_path
|
|
|
|
manage_milestones_path
|
|
|
|
new_milestone_path
|
2022-07-16 23:28:13 +05:30
|
|
|
default_branch
|
2022-08-13 15:12:31 +05:30
|
|
|
upcoming_release_docs_path
|
2022-07-16 23:28:13 +05:30
|
|
|
edit_release_docs_path)
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(helper.data_for_new_release_page.keys).to match_array(keys)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe '#data_for_show_page' do
|
|
|
|
it 'has the needed data to display the individual "release" page' do
|
|
|
|
keys = %i(project_id
|
|
|
|
project_path
|
|
|
|
tag_name)
|
|
|
|
|
|
|
|
expect(helper.data_for_show_page.keys).to match_array(keys)
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
describe 'startup queries' do
|
|
|
|
describe 'use_startup_query_for_index_page?' do
|
|
|
|
it 'allows startup queries for non-paginated requests' do
|
|
|
|
allow(helper).to receive(:params).and_return({ unrelated_query_param: 'value' })
|
|
|
|
|
|
|
|
expect(helper.use_startup_query_for_index_page?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows startup queries for requests paginated with a "before" cursor' do
|
|
|
|
allow(helper).to receive(:params).and_return({ unrelated_query_param: 'value', before: 'cursor' })
|
|
|
|
|
|
|
|
expect(helper.use_startup_query_for_index_page?).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows startup queries for requests paginated with an "after" cursor' do
|
|
|
|
allow(helper).to receive(:params).and_return({ unrelated_query_param: 'value', after: 'cursor' })
|
|
|
|
|
|
|
|
expect(helper.use_startup_query_for_index_page?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index_page_startup_query_variables' do
|
|
|
|
let_it_be(:project) { build(:project, namespace: create(:group)) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct GraphQL variables for the startup query' do
|
|
|
|
expect(helper.index_page_startup_query_variables).to eq({
|
|
|
|
fullPath: project.full_path,
|
|
|
|
sort: 'RELEASED_AT_DESC',
|
|
|
|
first: 1
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|