Commit 305f4031 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Added tests for current behaviour

parent d73f4264
......@@ -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]
......
......@@ -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
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