Fixes #3800 - Sort order group_by broken (alphabetical)
This commit is contained in:
parent
0f4c6ddda3
commit
6de1053d4b
2 changed files with 56 additions and 36 deletions
|
@ -497,7 +497,9 @@ class App.ControllerTable extends App.Controller
|
|||
reference_key = groupBy + '_id'
|
||||
|
||||
if reference_key of object
|
||||
return reference_key
|
||||
attribute = _.findWhere(object.constructor.configure_attributes, { name: reference_key })
|
||||
|
||||
return App[attribute.relation]?.find(object[reference_key])?.displayName() || reference_key
|
||||
|
||||
groupBy
|
||||
|
||||
|
|
|
@ -66,13 +66,19 @@ RSpec.describe 'Overview', type: :system do
|
|||
end
|
||||
end
|
||||
|
||||
context 'sorting when group by is set' do
|
||||
let(:user) { create(:customer) }
|
||||
let(:ticket1) { create(:ticket, group: Group.find_by(name: 'Users'), priority_id: 1, customer: user) }
|
||||
let(:ticket2) { create(:ticket, group: Group.find_by(name: 'Users'), priority_id: 2, customer: user) }
|
||||
let(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users'), priority_id: 3, customer: user) }
|
||||
context 'sorting when group by is set', authenticated_as: :user do
|
||||
let(:user) { create(:agent, groups: [group_c, group_a, group_b]) }
|
||||
|
||||
let(:group_a) { create(:group, name: 'aaa') }
|
||||
let(:group_b) { create(:group, name: 'bbb') }
|
||||
let(:group_c) { create(:group, name: 'ccc') }
|
||||
|
||||
let(:ticket1) { create(:ticket, group: group_a, priority_id: 1, customer: user) }
|
||||
let(:ticket2) { create(:ticket, group: group_c, priority_id: 2, customer: user) }
|
||||
let(:ticket3) { create(:ticket, group: group_b, priority_id: 3, customer: user) }
|
||||
|
||||
let(:overview) do
|
||||
create(:overview, group_by: 'priority', group_direction: group_direction, condition: {
|
||||
create(:overview, group_by: group_key, group_direction: group_direction, condition: {
|
||||
'ticket.customer_id' => {
|
||||
operator: 'is',
|
||||
value: user.id
|
||||
|
@ -86,13 +92,15 @@ RSpec.describe 'Overview', type: :system do
|
|||
visit "ticket/view/#{overview.link}"
|
||||
end
|
||||
|
||||
context 'when grouping by priority' do
|
||||
let(:group_key) { 'priority' }
|
||||
|
||||
context 'when group direction is default' do
|
||||
let(:group_direction) { nil }
|
||||
|
||||
it 'sorts groups 1 > 3' do
|
||||
within :active_content do
|
||||
expect(find('.table-overview table tbody tr:first-child td:nth-child(1)').text).to match('1 low')
|
||||
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('3 high')
|
||||
expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,8 +123,7 @@ RSpec.describe 'Overview', type: :system do
|
|||
|
||||
it 'sorts groups 1 > 3' do
|
||||
within :active_content do
|
||||
expect(find('.table-overview table tbody tr:first-child td:nth-child(1)').text).to match('1 low')
|
||||
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('3 high')
|
||||
expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -126,8 +133,19 @@ RSpec.describe 'Overview', type: :system do
|
|||
|
||||
it 'sorts groups 3 > 1' do
|
||||
within :active_content do
|
||||
expect(find('.table-overview table tbody tr:first-child td:nth-child(1)').text).to match('3 high')
|
||||
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('1 low')
|
||||
expect(all('.table-overview table b').map(&:text)).to eq ['3 high', '2 normal', '1 low']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when grouping by groups' do
|
||||
let(:group_key) { 'group' }
|
||||
let(:group_direction) { 'ASC' }
|
||||
|
||||
it 'sorts groups a > b > c' do
|
||||
within :active_content do
|
||||
expect(all('.table-overview table b').map(&:text)).to eq %w[aaa bbb ccc]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue