Fixes #3800 - Sort order group_by broken (alphabetical)

This commit is contained in:
Mantas Masalskis 2021-10-12 15:46:46 +02:00 committed by Thorsten Eckel
parent 61996989b0
commit 55e99d7aa8
2 changed files with 56 additions and 36 deletions

View file

@ -497,7 +497,9 @@ class App.ControllerTable extends App.Controller
reference_key = groupBy + '_id' reference_key = groupBy + '_id'
if reference_key of object 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 groupBy

View file

@ -66,13 +66,19 @@ RSpec.describe 'Overview', type: :system do
end end
end end
context 'sorting when group by is set' do context 'sorting when group by is set', authenticated_as: :user do
let(:user) { create(:customer) } let(:user) { create(:agent, groups: [group_c, group_a, group_b]) }
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(:group_a) { create(:group, name: 'aaa') }
let(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users'), priority_id: 3, customer: user) } 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 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' => { 'ticket.customer_id' => {
operator: 'is', operator: 'is',
value: user.id value: user.id
@ -86,13 +92,15 @@ RSpec.describe 'Overview', type: :system do
visit "ticket/view/#{overview.link}" visit "ticket/view/#{overview.link}"
end end
context 'when grouping by priority' do
let(:group_key) { 'priority' }
context 'when group direction is default' do context 'when group direction is default' do
let(:group_direction) { nil } let(:group_direction) { nil }
it 'sorts groups 1 > 3' do it 'sorts groups 1 > 3' do
within :active_content do within :active_content do
expect(find('.table-overview table tbody tr:first-child td:nth-child(1)').text).to match('1 low') expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('3 high')
end end
end end
@ -115,8 +123,7 @@ RSpec.describe 'Overview', type: :system do
it 'sorts groups 1 > 3' do it 'sorts groups 1 > 3' do
within :active_content do within :active_content do
expect(find('.table-overview table tbody tr:first-child td:nth-child(1)').text).to match('1 low') expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('3 high')
end end
end end
end end
@ -126,8 +133,19 @@ RSpec.describe 'Overview', type: :system do
it 'sorts groups 3 > 1' do it 'sorts groups 3 > 1' do
within :active_content do within :active_content do
expect(find('.table-overview table tbody tr:first-child td:nth-child(1)').text).to match('3 high') expect(all('.table-overview table b').map(&:text)).to eq ['3 high', '2 normal', '1 low']
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('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 end
end end