Commit 8dfcafdc authored by Sean McGivern's avatar Sean McGivern

Merge branch '28302-move-add-license-button' into 'master'

Move add license button with other project buttons

Closes #28302

See merge request gitlab-org/gitlab!19370
parents 7c981da1 78a8d475
...@@ -21,7 +21,6 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -21,7 +21,6 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def statistics_anchors(show_auto_devops_callout:) def statistics_anchors(show_auto_devops_callout:)
[ [
license_anchor_data,
commits_anchor_data, commits_anchor_data,
branches_anchor_data, branches_anchor_data,
tags_anchor_data, tags_anchor_data,
...@@ -32,6 +31,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -32,6 +31,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def statistics_buttons(show_auto_devops_callout:) def statistics_buttons(show_auto_devops_callout:)
[ [
readme_anchor_data, readme_anchor_data,
license_anchor_data,
changelog_anchor_data, changelog_anchor_data,
contribution_guide_anchor_data, contribution_guide_anchor_data,
autodevops_anchor_data(show_auto_devops_callout: show_auto_devops_callout), autodevops_anchor_data(show_auto_devops_callout: show_auto_devops_callout),
...@@ -41,15 +41,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -41,15 +41,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def empty_repo_statistics_anchors def empty_repo_statistics_anchors
[ []
license_anchor_data
].compact.select { |item| item.is_link }
end end
def empty_repo_statistics_buttons def empty_repo_statistics_buttons
[ [
new_file_anchor_data, new_file_anchor_data,
readme_anchor_data, readme_anchor_data,
license_anchor_data,
changelog_anchor_data, changelog_anchor_data,
contribution_guide_anchor_data, contribution_guide_anchor_data,
gitlab_ci_anchor_data gitlab_ci_anchor_data
...@@ -227,17 +226,18 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -227,17 +226,18 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
icon = statistic_icon('scale') icon = statistic_icon('scale')
if repository.license_blob.present? if repository.license_blob.present?
AnchorData.new(true, AnchorData.new(false,
icon + content_tag(:strong, license_short_name, class: 'project-stat-value'), icon + content_tag(:span, license_short_name, class: 'project-stat-value'),
license_path) license_path,
'default')
else else
if current_user && can_current_user_push_to_default_branch? if current_user && can_current_user_push_to_default_branch?
AnchorData.new(true, AnchorData.new(false,
content_tag(:span, icon + _('Add license'), class: 'add-license-link d-flex'), content_tag(:span, statistic_icon + _('Add LICENSE'), class: 'add-license-link d-flex'),
add_license_path) add_license_path)
else else
AnchorData.new(true, AnchorData.new(false,
icon + content_tag(:strong, _('No license. All rights reserved'), class: 'project-stat-value'), icon + content_tag(:span, _('No license. All rights reserved'), class: 'project-stat-value'),
nil) nil)
end end
end end
......
---
title: Move add license button to project buttons
merge_request: 19370
author:
type: changed
...@@ -905,6 +905,9 @@ msgstr "" ...@@ -905,6 +905,9 @@ msgstr ""
msgid "Add Kubernetes cluster" msgid "Add Kubernetes cluster"
msgstr "" msgstr ""
msgid "Add LICENSE"
msgstr ""
msgid "Add README" msgid "Add README"
msgstr "" msgstr ""
......
...@@ -39,7 +39,7 @@ describe 'Projects > Files > Project owner creates a license file', :js do ...@@ -39,7 +39,7 @@ describe 'Projects > Files > Project owner creates a license file', :js do
end end
it 'project maintainer creates a license file from the "Add license" link' do it 'project maintainer creates a license file from the "Add license" link' do
click_link 'Add license' click_link 'Add LICENSE'
expect(page).to have_content('New file') expect(page).to have_content('New file')
expect(current_path).to eq( expect(current_path).to eq(
......
...@@ -12,7 +12,7 @@ describe 'Projects > Files > Project owner sees a link to create a license file ...@@ -12,7 +12,7 @@ describe 'Projects > Files > Project owner sees a link to create a license file
it 'project maintainer creates a license file from a template' do it 'project maintainer creates a license file from a template' do
visit project_path(project) visit project_path(project)
click_on 'Add license' click_on 'Add LICENSE'
expect(page).to have_content('New file') expect(page).to have_content('New file')
expect(current_path).to eq( expect(current_path).to eq(
......
...@@ -59,8 +59,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -59,8 +59,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
end end
it '"Add license" button linked to new file populated for a license' do it '"Add license" button linked to new file populated for a license' do
page.within('.project-stats') do page.within('.project-buttons') do
expect(page).to have_link('Add license', href: presenter.add_license_path) expect(page).to have_link('Add LICENSE', href: presenter.add_license_path)
end end
end end
end end
...@@ -175,7 +175,7 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -175,7 +175,7 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
expect(project.repository.license_blob).not_to be_nil expect(project.repository.license_blob).not_to be_nil
page.within('.project-buttons') do page.within('.project-buttons') do
expect(page).not_to have_link('Add license') expect(page).not_to have_link('Add LICENSE')
end end
end end
......
...@@ -312,8 +312,8 @@ describe ProjectPresenter do ...@@ -312,8 +312,8 @@ describe ProjectPresenter do
project.add_developer(user) project.add_developer(user)
allow(project.repository).to receive(:license_blob).and_return(nil) allow(project.repository).to receive(:license_blob).and_return(nil)
expect(presenter.license_anchor_data).to have_attributes(is_link: true, expect(presenter.license_anchor_data).to have_attributes(is_link: false,
label: a_string_including('Add license'), label: a_string_including('Add LICENSE'),
link: presenter.add_license_path) link: presenter.add_license_path)
end end
end end
...@@ -322,7 +322,7 @@ describe ProjectPresenter do ...@@ -322,7 +322,7 @@ describe ProjectPresenter do
it 'returns anchor data' do it 'returns anchor data' do
allow(project.repository).to receive(:license_blob).and_return(double(name: 'foo')) allow(project.repository).to receive(:license_blob).and_return(double(name: 'foo'))
expect(presenter.license_anchor_data).to have_attributes(is_link: true, expect(presenter.license_anchor_data).to have_attributes(is_link: false,
label: a_string_including(presenter.license_short_name), label: a_string_including(presenter.license_short_name),
link: presenter.license_path) link: presenter.license_path)
end end
...@@ -420,6 +420,7 @@ describe ProjectPresenter do ...@@ -420,6 +420,7 @@ describe ProjectPresenter do
it 'orders the items correctly' do it 'orders the items correctly' do
allow(project.repository).to receive(:readme).and_return(double(name: 'readme')) allow(project.repository).to receive(:readme).and_return(double(name: 'readme'))
allow(project.repository).to receive(:license_blob).and_return(nil)
allow(project.repository).to receive(:changelog).and_return(nil) allow(project.repository).to receive(:changelog).and_return(nil)
allow(project.repository).to receive(:contribution_guide).and_return(double(name: 'foo')) allow(project.repository).to receive(:contribution_guide).and_return(double(name: 'foo'))
allow(presenter).to receive(:filename_path).and_return('fake/path') allow(presenter).to receive(:filename_path).and_return('fake/path')
...@@ -433,25 +434,54 @@ describe ProjectPresenter do ...@@ -433,25 +434,54 @@ describe ProjectPresenter do
end end
end end
describe '#empty_repo_statistics_buttons' do describe '#repo_statistics_buttons' do
let(:project) { create(:project, :repository) }
let(:presenter) { described_class.new(project, current_user: user) } let(:presenter) { described_class.new(project, current_user: user) }
subject(:empty_repo_statistics_buttons) { presenter.empty_repo_statistics_buttons } subject(:empty_repo_statistics_buttons) { presenter.empty_repo_statistics_buttons }
before do before do
project.add_developer(user)
allow(project).to receive(:auto_devops_enabled?).and_return(false) allow(project).to receive(:auto_devops_enabled?).and_return(false)
end end
it 'orders the items correctly in an empty project' do context 'empty repo' do
expect(empty_repo_statistics_buttons.map(&:label)).to start_with( let(:project) { create(:project, :stubbed_repository)}
a_string_including('New'),
a_string_including('README'), context 'for a guest user' do
a_string_including('CHANGELOG'), it 'orders the items correctly' do
a_string_including('CONTRIBUTING'), expect(empty_repo_statistics_buttons.map(&:label)).to start_with(
a_string_including('CI/CD') a_string_including('No license')
) )
end
end
context 'for a developer' do
before do
project.add_developer(user)
end
it 'orders the items correctly' do
expect(empty_repo_statistics_buttons.map(&:label)).to start_with(
a_string_including('New'),
a_string_including('README'),
a_string_including('LICENSE'),
a_string_including('CHANGELOG'),
a_string_including('CONTRIBUTING'),
a_string_including('CI/CD')
)
end
end
end
context 'initialized repo' do
let(:project) { create(:project, :repository) }
it 'orders the items correctly' do
expect(empty_repo_statistics_buttons.map(&:label)).to start_with(
a_string_including('README'),
a_string_including('License'),
a_string_including('CHANGELOG'),
a_string_including('CONTRIBUTING')
)
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment