Commit c8733ede authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '8933-decouple-sorting-roadmap' into 'master'

Separate BE roadmaps sort from epics sort

Closes #8933

See merge request gitlab-org/gitlab-ee!9281
parents 653ddceb 19fb1be0
...@@ -2985,6 +2985,7 @@ ActiveRecord::Schema.define(version: 20190124200344) do ...@@ -2985,6 +2985,7 @@ ActiveRecord::Schema.define(version: 20190124200344) do
t.integer "epic_notes_filter", limit: 2, default: 0, null: false t.integer "epic_notes_filter", limit: 2, default: 0, null: false
t.string "issues_sort" t.string "issues_sort"
t.string "merge_requests_sort" t.string "merge_requests_sort"
t.string "roadmaps_sort"
t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true, using: :btree t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true, using: :btree
end end
......
...@@ -11,7 +11,12 @@ module EpicsActions ...@@ -11,7 +11,12 @@ module EpicsActions
end end
def default_sort_order def default_sort_order
sort_value_recently_created default_sort_value || sort_value_recently_created
end
# Override this if you want your controller to have a different default sort order
def default_sort_value
nil
end end
def update_cookie_value(value) def update_cookie_value(value)
......
...@@ -20,7 +20,15 @@ module Groups ...@@ -20,7 +20,15 @@ module Groups
private private
def issuable_sorting_field def issuable_sorting_field
:epics_sort :roadmaps_sort
end
def default_sort_value
sort_value_start_date_soon
end
def remember_sorting_key
@remember_sorting_key ||= "roadmap_sort"
end end
def persist_roadmap_layout def persist_roadmap_layout
......
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddRoadmapSortToUserPreferences < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
add_column :user_preferences, :roadmaps_sort, :string, null: true
end
def down
remove_column :user_preferences, :roadmaps_sort
end
end
...@@ -38,28 +38,36 @@ describe Groups::RoadmapController do ...@@ -38,28 +38,36 @@ describe Groups::RoadmapController do
get :show, params: { group_id: group, sort: 'start_date_asc' } get :show, params: { group_id: group, sort: 'start_date_asc' }
expect(cookies['epic_sort']).to eq('start_date_asc') expect(cookies['roadmap_sort']).to eq('start_date_asc')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
end end
context 'when there is a user logged in' do context 'when there is a user logged in' do
context 'when epics_sort is nil' do context 'when roadmaps_sort is nil' do
it 'stores epics sorting param in user preference' do it 'stores roadmaps sorting param in user preference' do
get :show, params: { group_id: group, sort: 'start_date_asc' } get :show, params: { group_id: group, sort: 'start_date_asc' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(user.reload.user_preference.epics_sort).to eq('start_date_asc') expect(user.reload.user_preference.roadmaps_sort).to eq('start_date_asc')
end
it 'defaults to sort_value_start_date_soon' do
user.user_preference.update(roadmaps_sort: nil)
get :show, params: { group_id: group }
expect(assigns(:sort)).to eq('start_date_asc')
end end
end end
context 'when epics_sort is present' do context 'when roadmaps_sort is present' do
it 'update epics_sort with current value' do it 'update roadmaps_sort with current value' do
user.user_preference.update(epics_sort: 'created_desc') user.user_preference.update(roadmaps_sort: 'created_desc')
get :show, params: { group_id: group, sort: 'start_date_asc' } get :show, params: { group_id: group, sort: 'start_date_asc' }
expect(user.reload.user_preference.epics_sort).to eq('start_date_asc') expect(user.reload.user_preference.roadmaps_sort).to eq('start_date_asc')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
end end
......
...@@ -49,23 +49,23 @@ describe 'epics list', :js do ...@@ -49,23 +49,23 @@ describe 'epics list', :js do
page.within('.content-wrapper .content') do page.within('.content-wrapper .content') do
expect(find('.top-area')).to have_content('All 3') expect(find('.top-area')).to have_content('All 3')
page.within(".issuable-list") do page.within('.issuable-list') do
page.within("li:nth-child(1)") do page.within('li:nth-child(1)') do
expect(page).to have_content(epic3.title) expect(page).to have_content(epic3.title)
end end
page.within("li:nth-child(2)") do page.within('li:nth-child(2)') do
expect(page).to have_content(epic2.title) expect(page).to have_content(epic2.title)
end end
page.within("li:nth-child(3)") do page.within('li:nth-child(3)') do
expect(page).to have_content(epic1.title) expect(page).to have_content(epic1.title)
end end
end end
end end
end end
it 'sorts by the selected value and stores the selection for epic list & roadmap' do it 'sorts by the selected value and stores the selection for epic list' do
page.within('.epics-other-filters') do page.within('.epics-other-filters') do
click_button 'Created date' click_button 'Created date'
sort_options = find('ul.dropdown-menu-sort li').all('a').collect(&:text) sort_options = find('ul.dropdown-menu-sort li').all('a').collect(&:text)
...@@ -75,24 +75,24 @@ describe 'epics list', :js do ...@@ -75,24 +75,24 @@ describe 'epics list', :js do
expect(sort_options[2]).to eq('Start date') expect(sort_options[2]).to eq('Start date')
expect(sort_options[3]).to eq('Due date') expect(sort_options[3]).to eq('Due date')
click_link 'Start date' click_link 'Last updated'
end end
expect(page).to have_button('Start date') expect(page).to have_button('Last updated')
page.within('.content-wrapper .content') do page.within('.content-wrapper .content') do
expect(find('.top-area')).to have_content('All 3') expect(find('.top-area')).to have_content('All 3')
page.within(".issuable-list") do page.within('.issuable-list') do
page.within("li:nth-child(1)") do page.within('li:nth-child(1)') do
expect(page).to have_content(epic3.title) expect(page).to have_content(epic3.title)
end end
page.within("li:nth-child(2)") do page.within('li:nth-child(2)') do
expect(page).to have_content(epic2.title) expect(page).to have_content(epic2.title)
end end
page.within("li:nth-child(3)") do page.within('li:nth-child(3)') do
expect(page).to have_content(epic1.title) expect(page).to have_content(epic1.title)
end end
end end
...@@ -100,11 +100,43 @@ describe 'epics list', :js do ...@@ -100,11 +100,43 @@ describe 'epics list', :js do
visit group_epics_path(group) visit group_epics_path(group)
expect(page).to have_button('Start date') expect(page).to have_button('Last updated')
end
it 'sorts by the selected value and stores the selection for roadmap' do
visit group_roadmap_path(group)
page.within('.epics-other-filters') do
click_button 'Start date'
sort_options = find('ul.dropdown-menu-sort li').all('a').collect(&:text)
expect(sort_options[0]).to eq('Start date')
expect(sort_options[1]).to eq('Due date')
click_link 'Due date'
end
expect(page).to have_button('Due date')
page.within('.content-wrapper .content') do
page.within('.epics-list-section') do
page.within('div.epics-list-item:nth-child(1)') do
expect(page).to have_content(epic1.title)
end
page.within('div.epics-list-item:nth-child(2)') do
expect(page).to have_content(epic3.title)
end
page.within('div.epics-list-item:nth-child(3)') do
expect(page).to have_content(epic2.title)
end
end
end
visit group_roadmap_path(group) visit group_roadmap_path(group)
expect(page).to have_button('Start date') expect(page).to have_button('Due date')
end end
it 'renders the epic detail correctly after clicking the link' do it 'renders the epic detail correctly after clicking the link' do
......
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