summaryrefslogtreecommitdiff
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
parentd73f42645d985dcf3d383f5316b8ca603e3700dc (diff)
downloadgitlab-ce-305f4031a48535aca4229de0c5945b247a608c07.tar.gz
Added tests for current behaviour
-rw-r--r--app/helpers/sorting_helper.rb15
-rw-r--r--spec/helpers/sorting_helper_spec.rb114
2 files changed, 119 insertions, 10 deletions
diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb
index 26692934456..ad0d74d7a19 100644
--- a/app/helpers/sorting_helper.rb
+++ b/app/helpers/sorting_helper.rb
@@ -38,14 +38,12 @@ module SortingHelper
# https://gitlab.com/gitlab-org/gitlab-ce/issues/60798
# https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/11209#note_162234858
def old_projects_sort_options_hash
- options = {
- sort_value_latest_activity => sort_title_latest_activity,
- sort_value_name => sort_title_name,
+ options = projects_sort_common_options_hash.merge({
sort_value_oldest_activity => sort_title_oldest_activity,
sort_value_oldest_created => sort_title_oldest_created,
sort_value_recently_created => sort_title_recently_created,
sort_value_stars_desc => sort_title_most_stars
- }
+ })
if current_controller?('admin/projects')
options[sort_value_largest_repo] = sort_title_largest_repo
@@ -64,16 +62,12 @@ module SortingHelper
end
def projects_sort_option_titles
- {
- 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,
+ projects_sort_common_options_hash.merge({
sort_value_oldest_activity => sort_title_latest_activity,
sort_value_oldest_created => sort_title_created_date,
sort_value_name_desc => sort_title_name,
sort_value_stars_asc => sort_title_stars
- }
+ })
end
def projects_reverse_sort_options_hash
@@ -237,6 +231,7 @@ module SortingHelper
end
end
+ # TODO: dedupicate issuable and project sort direction
def project_sort_direction_button(sort_value)
link_class = 'btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort'
reverse_sort = projects_reverse_sort_options_hash[sort_value]
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