Skip to content

Commit

Permalink
Fixes #3800 - Sort order group_by broken (alphabetical)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas committed Oct 15, 2021
1 parent 0f4c6dd commit 6de1053
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
Expand Up @@ -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

Expand Down
84 changes: 51 additions & 33 deletions spec/system/overview_spec.rb
Expand Up @@ -66,13 +66,19 @@ def authenticate
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
Expand All @@ -86,48 +92,60 @@ def authenticate
visit "ticket/view/#{overview.link}"
end

context 'when group direction is default' do
let(:group_direction) { nil }
context 'when grouping by priority' do
let(:group_key) { 'priority' }

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')
context 'when group direction is default' do
let(:group_direction) { nil }

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
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'
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'
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)
within :active_content do
expect(page).to have_css("tr[data-id='#{ticket3.id}']", count: 1)
end
end
end
end

context 'when group direction is ASC' do
let(:group_direction) { 'ASC' }
context 'when group direction is ASC' do
let(:group_direction) { 'ASC' }

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')
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
end

context 'when group direction is DESC' do
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

context 'when group direction is DESC' do
let(:group_direction) { 'DESC' }
context 'when grouping by groups' do
let(:group_key) { 'group' }
let(:group_direction) { 'ASC' }

it 'sorts groups 3 > 1' do
it 'sorts groups a > b > c' 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 %w[aaa bbb ccc]
end
end
end
Expand Down

0 comments on commit 6de1053

Please sign in to comment.