From 1bc9f245e6b79b32962edeba0b06a8819dddb76a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 23 Aug 2018 21:19:48 +0200 Subject: [PATCH] Fixed issue #2209 - Order of relation select fields (Group, State etc.) values is broken. --- .../app/controllers/_ui_element/select.coffee | 1 + public/assets/tests/form_extended.js | 44 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/select.coffee b/app/assets/javascripts/app/controllers/_ui_element/select.coffee index e2061a3f2..e8dbdf1b3 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/select.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/select.coffee @@ -38,6 +38,7 @@ class App.UiElement.select extends App.UiElement.ApplicationUiElement # 1. If attribute.value is not among the current options, then search within historical options # 2. If attribute.value is not among current and historical options, then add the value itself as an option @addDeletedOptions: (attribute) -> + return if !_.isEmpty(attribute.relation) # do not apply for attributes with relation, relations will fill options automatically value = attribute.value return if !value return if _.isArray(value) diff --git a/public/assets/tests/form_extended.js b/public/assets/tests/form_extended.js index 42f84247a..6e88b8a08 100644 --- a/public/assets/tests/form_extended.js +++ b/public/assets/tests/form_extended.js @@ -93,6 +93,8 @@ test('form checks', function() { priority1_id: '1', priority2_id: ['1', '2'], priority3_id: '2', + priority4_id: '2', + priority5_id: '1', working_hours: { mon: { active: true, @@ -146,9 +148,11 @@ test('form checks', function() { el: el, model: { configure_attributes: [ - { name: 'priority1_id', display: 'Priroity1', tag: 'select', relation: 'TicketPriority', null: true, options: {} }, - { name: 'priority2_id', display: 'Priroity2', tag: 'select', multiple: true, relation: 'TicketPriority', null: true, options: {} }, - { name: 'priority3_id', display: 'Priroity3', tag: 'select', relation: 'TicketPriority', null: true }, + { name: 'priority1_id', display: 'Priroity1 (with active selection)', tag: 'select', relation: 'TicketPriority', null: true, options: {} }, + { name: 'priority2_id', display: 'Priroity2 (with active and inactive selection)', tag: 'select', multiple: true, relation: 'TicketPriority', null: true, options: {} }, + { name: 'priority3_id', display: 'Priroity3 (with inactive selection)', tag: 'select', relation: 'TicketPriority', null: true, options: {} }, + { name: 'priority4_id', display: 'Priroity4 (with inactive selection)', tag: 'select', multiple: true, relation: 'TicketPriority', null: true, options: {} }, + { name: 'priority5_id', display: 'Priroity5 (with active selection)', tag: 'select', multiple: true, relation: 'TicketPriority', null: true, options: {} }, { name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true }, { name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true }, ] @@ -161,6 +165,8 @@ test('form checks', function() { priority1_id: '1', priority2_id: ['1', '2'], priority3_id: '2', + priority4_id: '2', + priority5_id: '1', first_response_time: '150', first_response_time_in_text: '02:30', solution_time: '', @@ -219,6 +225,36 @@ test('form checks', function() { equal(el.find('[name="priority1_id"] option').length, 3) equal(el.find('[name="priority2_id"] option').length, 4) equal(el.find('[name="priority3_id"] option').length, 4) + equal(el.find('[name="priority4_id"] option').length, 4) + equal(el.find('[name="priority5_id"] option').length, 3) + + // check priority1_id selection order + equal(el.find('[name="priority1_id"] option:nth-child(1)').text(), '1 low') + equal(el.find('[name="priority1_id"] option:nth-child(2)').text(), '3 high') + equal(el.find('[name="priority1_id"] option:nth-child(3)').text(), '4 very high') + + // check priority2_id selection order + equal(el.find('[name="priority2_id"] option:nth-child(1)').text(), '1 low') + equal(el.find('[name="priority2_id"] option:nth-child(2)').text(), '2 normal') + equal(el.find('[name="priority2_id"] option:nth-child(3)').text(), '3 high') + equal(el.find('[name="priority2_id"] option:nth-child(4)').text(), '4 very high') + + // check priority3_id selection order + equal(el.find('[name="priority3_id"] option:nth-child(1)').text(), '1 low') + equal(el.find('[name="priority3_id"] option:nth-child(2)').text(), '2 normal') + equal(el.find('[name="priority3_id"] option:nth-child(3)').text(), '3 high') + equal(el.find('[name="priority3_id"] option:nth-child(4)').text(), '4 very high') + + // check priority4_id selection order + equal(el.find('[name="priority4_id"] option:nth-child(1)').text(), '1 low') + equal(el.find('[name="priority4_id"] option:nth-child(2)').text(), '2 normal') + equal(el.find('[name="priority4_id"] option:nth-child(3)').text(), '3 high') + equal(el.find('[name="priority4_id"] option:nth-child(4)').text(), '4 very high') + + // check priority5_id selection order + equal(el.find('[name="priority5_id"] option:nth-child(1)').text(), '1 low') + equal(el.find('[name="priority5_id"] option:nth-child(2)').text(), '3 high') + equal(el.find('[name="priority5_id"] option:nth-child(3)').text(), '4 very high') // change sla times el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur') @@ -229,6 +265,8 @@ test('form checks', function() { priority1_id: '1', priority2_id: ['1', '2'], priority3_id: '2', + priority4_id: '2', + priority5_id: '1', working_hours: { mon: { active: true,