From 48cfdc86979ec000b588d253ce61f9c42a613f8d Mon Sep 17 00:00:00 2001 From: Bola Ahmed Buari Date: Fri, 4 Feb 2022 12:26:19 +0100 Subject: [PATCH] Fixes #3944 - Multiselects shows wrong display values in overviews --- app/assets/javascripts/app/index.coffee | 5 +- public/assets/tests/qunit/model_ui.js | 61 ++++++++++++++++++++ spec/system/overview_spec.rb | 77 +++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/index.coffee b/app/assets/javascripts/app/index.coffee index eb7837e32..b559a7b0f 100644 --- a/app/assets/javascripts/app/index.coffee +++ b/app/assets/javascripts/app/index.coffee @@ -95,7 +95,10 @@ class App extends Spine.Controller # fillup options if !_.isEmpty(attributeConfig.options) - if attributeConfig.options[resultLocal] + if Array.isArray(attributeConfig.options) + option = _.find(attributeConfig.options, (option) -> option.value == resultLocal) + resultLocal = option.name + else if attributeConfig.options[resultLocal] resultLocal = attributeConfig.options[resultLocal] # transform boolean diff --git a/public/assets/tests/qunit/model_ui.js b/public/assets/tests/qunit/model_ui.js index f64160c15..7b6ec1aee 100644 --- a/public/assets/tests/qunit/model_ui.js +++ b/public/assets/tests/qunit/model_ui.js @@ -35,6 +35,40 @@ QUnit.test( "model ui basic tests", assert => { name: 'link2', display: 'link 1', linktemplate: 'http://zammad.com', tag: 'input', null: true }; App.Ticket.configure_attributes.push( attribute4 ) + var attribute5 = { + name: 'multiselect', + display: 'Multi Select', + tag: 'multiselect', + options: [ + { + name: 'One', + value: '1', + }, + { + name: 'Two', + value: '2', + }, + { + name: 'Three', + value: '3', + }, + { + name: 'Four', + value: '4', + }, + { + name: 'Five', + value: '5', + }, + ], + linktemplate: '', + null: true, + relation: '', + nulloption: true, + maxlength: 255, + multiple: true, + } + App.Ticket.configure_attributes.push(attribute5) var ticket = new App.Ticket() ticket.load({ @@ -46,6 +80,7 @@ QUnit.test( "model ui basic tests", assert => { textarea: "some new\nline", link1: 'closed', link2: 'closed', + multiselect: ['1', '2', '3'] }) App.i18n.set('en-us') @@ -59,6 +94,7 @@ QUnit.test( "model ui basic tests", assert => { assert.equal( App.viewPrint( ticket, 'textarea' ), '
some new
line
') assert.equal( App.viewPrint( ticket, 'link1' ), 'closed') assert.equal( App.viewPrint( ticket, 'link2' ), 'closed') + assert.equal( App.viewPrint( ticket, 'multiselect' ), 'One, Two, Three', 'multiselect test 1') let stub = sinon.stub(App.Config, 'get') stub.withArgs('timezone_default').returns('Example/Timezone') @@ -81,6 +117,7 @@ QUnit.test( "model ui basic tests", assert => { assert.equal( App.viewPrint( ticket, 'textarea' ), '
some new
line
') assert.equal( App.viewPrint( ticket, 'link1' ), 'geschlossen') assert.equal( App.viewPrint( ticket, 'link2' ), 'closed') + assert.equal( App.viewPrint( ticket, 'multiselect' ), 'One, Two, Three', 'multiselect test 2') App.i18n.set('en-us') @@ -92,6 +129,30 @@ QUnit.test( "model ui basic tests", assert => { assert.equal( App.viewPrint( ticket, 'state' ), 'closed <>&') assert.equal( App.viewPrint( ticket, 'state_id' ), 'closed <>&') + // multiselect single value in array + ticket.load({ + multiselect: ['4'] + }) + assert.equal( App.viewPrint( ticket, 'multiselect' ), 'Four', 'multiselect single value in array') + + // multiselect single value in string + ticket.load({ + multiselect: '4' + }) + assert.equal( App.viewPrint( ticket, 'multiselect' ), 'Four', 'multiselect single value in string') + + // multiselect multiple value + ticket.load({ + multiselect: ['3', '4', '5'] + }) + assert.equal( App.viewPrint( ticket, 'multiselect' ), 'Three, Four, Five', 'multiselect multiple value') + + // multiselect no value + ticket.load({ + multiselect: null + }) + assert.equal( App.viewPrint( ticket, 'multiselect' ), '-', 'multiselect no value') + // normal string data = { a: 1, diff --git a/spec/system/overview_spec.rb b/spec/system/overview_spec.rb index bf18b2692..4c5851eb1 100644 --- a/spec/system/overview_spec.rb +++ b/spec/system/overview_spec.rb @@ -150,4 +150,81 @@ RSpec.describe 'Overview', type: :system do end end end + + context 'when multiselect is choosen as column', authenticated_as: :authenticate, db_strategy: :reset do + def authenticate + create :object_manager_attribute_multiselect, data_option: data_option, name: attribute_name + ObjectManager::Attribute.migration_execute + user + end + + let(:user) { create(:agent, groups: [group]) } + + let(:attribute_name) { 'multiselect' } + let(:options_hash) do + { + 'key_1' => 'display_value_1', + 'key_2' => 'display_value_2', + 'key_3' => 'display_value_3', + 'key_4' => 'display_value_4', + 'key_5' => 'display_value_5' + } + end + let(:data_option) { { options: options_hash, default: '' } } + let(:group) { create(:group, name: 'aaa') } + + let(:ticket) { create(:ticket, group: group, customer: user, multiselect: multiselect_value) } + + let(:view) { { 's'=>%w[number title multiselect] } } + let(:condition) do + { + 'ticket.customer_id' => { + operator: 'is', + value: user.id + } + } + end + let(:overview) { create(:overview, condition: condition, view: view) } + + let(:overview_table_selector) { '.table-overview .js-tableBody' } + + before do + ticket + + visit "ticket/view/#{overview.link}" + end + + context 'with nil multiselect value' do + let(:multiselect_value) { nil } + let(:expected_text) { '-' } + + it "shows dash '-' for tickets" do + within :active_content, overview_table_selector do + expect(page).to have_selector 'tr.item td', text: expected_text + end + end + end + + context 'with a single multiselect value' do + let(:multiselect_value) { ['key_4'] } + let(:expected_text) { 'display_value_4' } + + it 'shows the display value for tickets' do + within :active_content, overview_table_selector do + expect(page).to have_selector 'tr.item td', text: expected_text + end + end + end + + context 'with multiple multiselect values' do + let(:multiselect_value) { %w[key_2 key_3 key_5] } + let(:expected_text) { 'display_value_2, display_value_3, display_value_5' } + + it 'shows comma seperated diaplay value for tickets' do + within :active_content, overview_table_selector do + expect(page).to have_selector 'tr.item td', text: expected_text + end + end + end + end end