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'
|
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
|
||||||
|
|
||||||
|
|
|
@ -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,48 +92,60 @@ RSpec.describe 'Overview', type: :system do
|
||||||
visit "ticket/view/#{overview.link}"
|
visit "ticket/view/#{overview.link}"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when group direction is default' do
|
context 'when grouping by priority' do
|
||||||
let(:group_direction) { nil }
|
let(:group_key) { 'priority' }
|
||||||
|
|
||||||
it 'sorts groups 1 > 3' do
|
context 'when group direction is default' do
|
||||||
within :active_content do
|
let(:group_direction) { nil }
|
||||||
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')
|
it 'sorts groups 1 > 3' do
|
||||||
|
within :active_content do
|
||||||
|
expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not show duplicates when any ticket attribute is updated using bulk update' do
|
||||||
|
find("tr[data-id='#{ticket3.id}']").check('bulk', allow_label_click: true)
|
||||||
|
select '2 normal', from: 'priority_id'
|
||||||
|
|
||||||
|
click '.js-confirm'
|
||||||
|
find('.js-confirm-step textarea').fill_in with: 'test tickets ordering'
|
||||||
|
click '.js-submit'
|
||||||
|
|
||||||
|
within :active_content do
|
||||||
|
expect(page).to have_css("tr[data-id='#{ticket3.id}']", count: 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not show duplicates when any ticket attribute is updated using bulk update' do
|
context 'when group direction is ASC' do
|
||||||
find("tr[data-id='#{ticket3.id}']").check('bulk', allow_label_click: true)
|
let(:group_direction) { 'ASC' }
|
||||||
select '2 normal', from: 'priority_id'
|
|
||||||
|
|
||||||
click '.js-confirm'
|
it 'sorts groups 1 > 3' do
|
||||||
find('.js-confirm-step textarea').fill_in with: 'test tickets ordering'
|
within :active_content do
|
||||||
click '.js-submit'
|
expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
within :active_content do
|
context 'when group direction is DESC' do
|
||||||
expect(page).to have_css("tr[data-id='#{ticket3.id}']", count: 1)
|
let(:group_direction) { 'DESC' }
|
||||||
|
|
||||||
|
it 'sorts groups 3 > 1' do
|
||||||
|
within :active_content do
|
||||||
|
expect(all('.table-overview table b').map(&:text)).to eq ['3 high', '2 normal', '1 low']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when group direction is ASC' do
|
context 'when grouping by groups' do
|
||||||
|
let(:group_key) { 'group' }
|
||||||
let(:group_direction) { 'ASC' }
|
let(:group_direction) { 'ASC' }
|
||||||
|
|
||||||
it 'sorts groups 1 > 3' do
|
it 'sorts groups a > b > c' 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 %w[aaa bbb ccc]
|
||||||
expect(find('.table-overview table tbody tr:nth-child(5) td:nth-child(1)').text).to match('3 high')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when group direction is DESC' do
|
|
||||||
let(:group_direction) { 'DESC' }
|
|
||||||
|
|
||||||
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')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue