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

Merge branch '55359-add-tests-for-redesign-projects-lists-ui' into 'master'

Resolve "Add tests for "Redesign projects lists UI""

Closes #55359

See merge request gitlab-org/gitlab-ce!23915
parents 37c934e0 26c74071
...@@ -271,6 +271,20 @@ module ProjectsHelper ...@@ -271,6 +271,20 @@ module ProjectsHelper
params[:legacy_render] ? { markdown_engine: :redcarpet } : {} params[:legacy_render] ? { markdown_engine: :redcarpet } : {}
end end
def explore_projects_tab?
current_page?(explore_projects_path) ||
current_page?(trending_explore_projects_path) ||
current_page?(starred_explore_projects_path)
end
def show_merge_request_count?(disabled: false, compact_mode: false)
!disabled && !compact_mode && Feature.enabled?(:project_list_show_mr_count, default_enabled: true)
end
def show_issue_count?(disabled: false, compact_mode: false)
!disabled && !compact_mode && Feature.enabled?(:project_list_show_issue_count, default_enabled: true)
end
private private
def get_project_nav_tabs(project, current_user) def get_project_nav_tabs(project, current_user)
...@@ -515,20 +529,6 @@ module ProjectsHelper ...@@ -515,20 +529,6 @@ module ProjectsHelper
end end
end end
def explore_projects_tab?
current_page?(explore_projects_path) ||
current_page?(trending_explore_projects_path) ||
current_page?(starred_explore_projects_path)
end
def show_merge_request_count?(merge_requests, compact_mode)
merge_requests && !compact_mode && Feature.enabled?(:project_list_show_mr_count, default_enabled: true)
end
def show_issue_count?(issues, compact_mode)
issues && !compact_mode && Feature.enabled?(:project_list_show_issue_count, default_enabled: true)
end
def sidebar_projects_paths def sidebar_projects_paths
%w[ %w[
projects#show projects#show
......
...@@ -72,13 +72,13 @@ ...@@ -72,13 +72,13 @@
title: _('Forks'), data: { container: 'body', placement: 'top' } do title: _('Forks'), data: { container: 'body', placement: 'top' } do
= sprite_icon('fork', size: 14, css_class: 'append-right-4') = sprite_icon('fork', size: 14, css_class: 'append-right-4')
= number_with_delimiter(project.forks_count) = number_with_delimiter(project.forks_count)
- if show_merge_request_count?(merge_requests, compact_mode) - if show_merge_request_count?(disabled: !merge_requests, compact_mode: compact_mode)
= link_to project_merge_requests_path(project), = link_to project_merge_requests_path(project),
class: "d-none d-lg-flex align-items-center icon-wrapper merge-requests has-tooltip", class: "d-none d-lg-flex align-items-center icon-wrapper merge-requests has-tooltip",
title: _('Merge Requests'), data: { container: 'body', placement: 'top' } do title: _('Merge Requests'), data: { container: 'body', placement: 'top' } do
= sprite_icon('git-merge', size: 14, css_class: 'append-right-4') = sprite_icon('git-merge', size: 14, css_class: 'append-right-4')
= number_with_delimiter(project.open_merge_requests_count) = number_with_delimiter(project.open_merge_requests_count)
- if show_issue_count?(issues, compact_mode) - if show_issue_count?(disabled: !issues, compact_mode: compact_mode)
= link_to project_issues_path(project), = link_to project_issues_path(project),
class: "d-none d-lg-flex align-items-center icon-wrapper issues has-tooltip", class: "d-none d-lg-flex align-items-center icon-wrapper issues has-tooltip",
title: _('Issues'), data: { container: 'body', placement: 'top' } do title: _('Issues'), data: { container: 'body', placement: 'top' } do
......
...@@ -119,6 +119,12 @@ describe 'Overview tab on a user profile', :js do ...@@ -119,6 +119,12 @@ describe 'Overview tab on a user profile', :js do
it 'shows a link to the project list' do it 'shows a link to the project list' do
expect(find('#js-overview .projects-block')).to have_selector('.js-view-all', visible: true) expect(find('#js-overview .projects-block')).to have_selector('.js-view-all', visible: true)
end end
it 'shows projects in "compact mode"' do
page.within('#js-overview .projects-block') do
expect(find('.js-projects-list-holder')).to have_selector('.compact')
end
end
end end
describe 'user has more than ten personal projects' do describe 'user has more than ten personal projects' do
......
...@@ -519,4 +519,114 @@ describe ProjectsHelper do ...@@ -519,4 +519,114 @@ describe ProjectsHelper do
expect(helper.legacy_render_context({})).to be_empty expect(helper.legacy_render_context({})).to be_empty
end end
end end
describe '#explore_projects_tab?' do
subject { helper.explore_projects_tab? }
it 'returns true when on the "All" tab under "Explore projects"' do
allow(@request).to receive(:path) { explore_projects_path }
expect(subject).to be_truthy
end
it 'returns true when on the "Trending" tab under "Explore projects"' do
allow(@request).to receive(:path) { trending_explore_projects_path }
expect(subject).to be_truthy
end
it 'returns true when on the "Starred" tab under "Explore projects"' do
allow(@request).to receive(:path) { starred_explore_projects_path }
expect(subject).to be_truthy
end
it 'returns false when on the "Your projects" tab' do
allow(@request).to receive(:path) { dashboard_projects_path }
expect(subject).to be_falsey
end
end
describe '#show_merge_request_count' do
context 'when the feature flag is enabled' do
before do
stub_feature_flags(project_list_show_mr_count: true)
end
it 'returns true if compact mode is disabled' do
expect(helper.show_merge_request_count?).to be_truthy
end
it 'returns false if compact mode is enabled' do
expect(helper.show_merge_request_count?(compact_mode: true)).to be_falsey
end
end
context 'when the feature flag is disabled' do
before do
stub_feature_flags(project_list_show_mr_count: false)
end
it 'always returns false' do
expect(helper.show_merge_request_count?(disabled: false)).to be_falsy
expect(helper.show_merge_request_count?(disabled: true)).to be_falsy
end
end
context 'disabled flag' do
before do
stub_feature_flags(project_list_show_mr_count: true)
end
it 'returns false if disabled flag is true' do
expect(helper.show_merge_request_count?(disabled: true)).to be_falsey
end
it 'returns true if disabled flag is false' do
expect(helper.show_merge_request_count?).to be_truthy
end
end
end
describe '#show_issue_count?' do
context 'when the feature flag is enabled' do
before do
stub_feature_flags(project_list_show_issue_count: true)
end
it 'returns true if compact mode is disabled' do
expect(helper.show_issue_count?).to be_truthy
end
it 'returns false if compact mode is enabled' do
expect(helper.show_issue_count?(compact_mode: true)).to be_falsey
end
end
context 'when the feature flag is disabled' do
before do
stub_feature_flags(project_list_show_issue_count: false)
end
it 'always returns false' do
expect(helper.show_issue_count?(disabled: false)).to be_falsy
expect(helper.show_issue_count?(disabled: true)).to be_falsy
end
end
context 'disabled flag' do
before do
stub_feature_flags(project_list_show_issue_count: true)
end
it 'returns false if disabled flag is true' do
expect(helper.show_issue_count?(disabled: true)).to be_falsey
end
it 'returns true if disabled flag is false' do
expect(helper.show_issue_count?).to be_truthy
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