From 26c740715013a38629011df51e6cf07b3cf12f34 Mon Sep 17 00:00:00 2001 From: Martin Wortschack Date: Wed, 19 Dec 2018 20:37:08 +0100 Subject: Add test for compact mode and for helpers - add tests for merge_request_count - add tests for show_issue_count - add tests for explore_projects_tab - change interface for show_merge_request_count and show_issue_count --- spec/features/users/overview_spec.rb | 6 ++ spec/helpers/projects_helper_spec.rb | 110 +++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) (limited to 'spec') diff --git a/spec/features/users/overview_spec.rb b/spec/features/users/overview_spec.rb index 34ed771340f..873de85708a 100644 --- a/spec/features/users/overview_spec.rb +++ b/spec/features/users/overview_spec.rb @@ -119,6 +119,12 @@ describe 'Overview tab on a user profile', :js do it 'shows a link to the project list' do expect(find('#js-overview .projects-block')).to have_selector('.js-view-all', visible: true) 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 describe 'user has more than ten personal projects' do diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 486416c3370..edd680ee1d1 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -519,4 +519,114 @@ describe ProjectsHelper do expect(helper.legacy_render_context({})).to be_empty 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 -- cgit v1.2.3