summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorEzekiel Kigbo <ekigbo@gitlab.com>2019-06-17 12:08:10 +1000
committerEzekiel Kigbo <ekigbo@gitlab.com>2019-07-12 09:53:46 +1000
commit305f4031a48535aca4229de0c5945b247a608c07 (patch)
treec3b2b0b6eccafff20006d027bb8bb98da00fb83c /spec
parentd73f42645d985dcf3d383f5316b8ca603e3700dc (diff)
downloadgitlab-ce-305f4031a48535aca4229de0c5945b247a608c07.tar.gz
Added tests for current behaviour
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/sorting_helper_spec.rb114
1 files changed, 114 insertions, 0 deletions
diff --git a/spec/helpers/sorting_helper_spec.rb b/spec/helpers/sorting_helper_spec.rb
index f405268d198..8184b6c3a08 100644
--- a/spec/helpers/sorting_helper_spec.rb
+++ b/spec/helpers/sorting_helper_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
describe SortingHelper do
include ApplicationHelper
include IconsHelper
+ include ExploreHelper
describe '#issuable_sort_option_title' do
it 'returns correct title for issuable_sort_option_overrides key' do
@@ -44,4 +45,117 @@ describe SortingHelper do
expect(issuable_sort_direction_button('due_date')).to include('sort-lowest')
end
end
+
+ # TODO: need separate tests for /admin/projects and /projects
+ # TODO: should this be renamed to `projects_sort_option_title??` ... maybe not
+ def stub_controller_path(value)
+ allow(helper.controller).to receive(:controller_path).and_return(value)
+ end
+
+ def project_common_options()
+ {
+ sort_value_latest_activity => sort_title_latest_activity,
+ sort_value_recently_created => sort_title_created_date,
+ sort_value_name => sort_title_name,
+ sort_value_stars_desc => sort_title_stars
+ }
+ end
+
+ def admin_additional_project_options()
+ {
+ sort_value_recently_created => sort_title_recently_created,
+ sort_value_largest_repo => sort_title_largest_repo,
+ sort_value_oldest_activity => sort_title_oldest_activity,
+ sort_value_oldest_created => sort_title_oldest_created,
+ sort_value_stars_desc => sort_title_most_stars
+ }
+ end
+
+ describe 'with `admin/projects` controller', :focus do
+ before do
+ stub_controller_path('admin/projects')
+ end
+
+ describe '#projects_sort_options_hash' do
+ it 'returns a hash of available sorting options' do
+ hash = projects_sort_options_hash
+
+ admin_options = project_common_options.merge(admin_additional_project_options)
+ expect(hash).to eq(admin_options)
+ end
+ end
+ end
+
+ describe 'with `projects` controller', :focus do
+ before do
+ stub_controller_path('projects')
+ end
+
+ describe '#projects_sort_options_hash' do
+ it 'returns a hash of available sorting options' do
+ hash = projects_sort_options_hash
+
+ common_options = project_common_options
+ admin_options = admin_additional_project_options
+ common_with_different_values = [sort_value_recently_created, sort_value_stars_desc]
+
+ common_options.each do |key, opt|
+ expect(hash).to include(key)
+ expect(hash[key]).to eq(opt)
+ end
+
+ admin_options.each do |key, opt|
+ if common_with_different_values.include?(key)
+ expect(hash[key]).not_to eq(opt)
+ else
+ expect(hash).not_to include(key)
+ end
+ end
+ end
+ end
+
+ describe '#projects_reverse_sort_options_hash' do
+ it 'returns a reversed hash of available sorting options' do
+ reverse_hash = projects_reverse_sort_options_hash
+
+ options = {
+ sort_value_latest_activity => sort_value_oldest_activity,
+ sort_value_recently_created => sort_value_oldest_created,
+ sort_value_name => sort_value_name_desc,
+ sort_value_stars_desc => sort_value_stars_asc,
+ sort_value_oldest_activity => sort_value_latest_activity,
+ sort_value_oldest_created => sort_value_recently_created,
+ sort_value_name_desc => sort_value_name,
+ sort_value_stars_asc => sort_value_stars_desc
+ }
+
+ options.each do |key, opt|
+ expect(reverse_hash).to include(key)
+ expect(reverse_hash[key]).to eq(opt)
+ end
+ end
+ end
+ end
+
+ describe '#project_sort_direction_button', :focus do
+ before do
+ allow(self).to receive(:request).and_return(double(path: 'http://test.com', query_parameters: { label_name: 'test_label' }))
+ end
+
+ it 'returns icon with sort-highest when sort is created_date' do
+ expect(project_sort_direction_button('created_date')).to include('sort-highest')
+ end
+
+ it 'returns icon with sort-lowest when sort is asc' do
+ expect(project_sort_direction_button('created_asc')).to include('sort-lowest')
+ end
+
+ it 'returns icon with sort-lowest when sorting by milestone' do
+ expect(project_sort_direction_button('milestone')).to include('sort-lowest')
+ end
+
+ it 'returns icon with sort-lowest when sorting by due_date' do
+ expect(project_sort_direction_button('due_date')).to include('sort-lowest')
+ end
+ end
end