Fixes #3944 - Multiselects shows wrong display values in overviews

This commit is contained in:
Bola Ahmed Buari 2022-02-04 12:26:19 +01:00 committed by Rolf Schmidt
parent afb75b23ae
commit 48cfdc8697
3 changed files with 142 additions and 1 deletions

View file

@ -95,7 +95,10 @@ class App extends Spine.Controller
# fillup options # fillup options
if !_.isEmpty(attributeConfig.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] resultLocal = attributeConfig.options[resultLocal]
# transform boolean # transform boolean

View file

@ -35,6 +35,40 @@ QUnit.test( "model ui basic tests", assert => {
name: 'link2', display: 'link 1', linktemplate: 'http://zammad.com', tag: 'input', null: true name: 'link2', display: 'link 1', linktemplate: 'http://zammad.com', tag: 'input', null: true
}; };
App.Ticket.configure_attributes.push( attribute4 ) 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() var ticket = new App.Ticket()
ticket.load({ ticket.load({
@ -46,6 +80,7 @@ QUnit.test( "model ui basic tests", assert => {
textarea: "some new\nline", textarea: "some new\nline",
link1: 'closed', link1: 'closed',
link2: 'closed', link2: 'closed',
multiselect: ['1', '2', '3']
}) })
App.i18n.set('en-us') App.i18n.set('en-us')
@ -59,6 +94,7 @@ QUnit.test( "model ui basic tests", assert => {
assert.equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>') assert.equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>')
assert.equal( App.viewPrint( ticket, 'link1' ), '<a href="http://zammad.com" target="blank">closed</a>') assert.equal( App.viewPrint( ticket, 'link1' ), '<a href="http://zammad.com" target="blank">closed</a>')
assert.equal( App.viewPrint( ticket, 'link2' ), '<a href="http://zammad.com" target="blank">closed</a>') assert.equal( App.viewPrint( ticket, 'link2' ), '<a href="http://zammad.com" target="blank">closed</a>')
assert.equal( App.viewPrint( ticket, 'multiselect' ), 'One, Two, Three', 'multiselect test 1')
let stub = sinon.stub(App.Config, 'get') let stub = sinon.stub(App.Config, 'get')
stub.withArgs('timezone_default').returns('Example/Timezone') stub.withArgs('timezone_default').returns('Example/Timezone')
@ -81,6 +117,7 @@ QUnit.test( "model ui basic tests", assert => {
assert.equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>') assert.equal( App.viewPrint( ticket, 'textarea' ), '<div>some new</div><div>line</div>')
assert.equal( App.viewPrint( ticket, 'link1' ), '<a href="http://zammad.com" target="blank">geschlossen</a>') assert.equal( App.viewPrint( ticket, 'link1' ), '<a href="http://zammad.com" target="blank">geschlossen</a>')
assert.equal( App.viewPrint( ticket, 'link2' ), '<a href="http://zammad.com" target="blank">closed</a>') assert.equal( App.viewPrint( ticket, 'link2' ), '<a href="http://zammad.com" target="blank">closed</a>')
assert.equal( App.viewPrint( ticket, 'multiselect' ), 'One, Two, Three', 'multiselect test 2')
App.i18n.set('en-us') App.i18n.set('en-us')
@ -92,6 +129,30 @@ QUnit.test( "model ui basic tests", assert => {
assert.equal( App.viewPrint( ticket, 'state' ), 'closed &lt;&gt;&amp;') assert.equal( App.viewPrint( ticket, 'state' ), 'closed &lt;&gt;&amp;')
assert.equal( App.viewPrint( ticket, 'state_id' ), 'closed &lt;&gt;&amp;') assert.equal( App.viewPrint( ticket, 'state_id' ), 'closed &lt;&gt;&amp;')
// 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 // normal string
data = { data = {
a: 1, a: 1,

View file

@ -150,4 +150,81 @@ RSpec.describe 'Overview', type: :system do
end end
end 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 end