From 03b56b8fc84e61f4439447fc900d386bbf7130ef Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Tue, 1 Dec 2020 13:35:32 +0100 Subject: [PATCH] Fixes #3213 - Relative fields get copied on macro --- .../_ui_element/ticket_perform_action.coffee | 10 +++- .../tests/form_ticket_perform_action.js | 48 +++++++++++++++++-- spec/system/js/q_unit_spec.rb | 2 +- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee b/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee index a46e6de40..d53da8ec4 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ticket_perform_action.coffee @@ -333,7 +333,15 @@ class App.UiElement.ticket_perform_action 'relative' ] - if _.include(relative_operators, meta.operator) + upcoming_operator = meta.operator + + if !_.include(config.operator, upcoming_operator) + if Array.isArray(config.operator) + upcoming_operator = config.operator[0] + else + upcoming_operator = null + + if _.include(relative_operators, upcoming_operator) config['name'] = "#{attribute.name}::#{groupAndAttribute}" if attribute.value && attribute.value[groupAndAttribute] config['value'] = _.clone(attribute.value[groupAndAttribute]) diff --git a/public/assets/tests/form_ticket_perform_action.js b/public/assets/tests/form_ticket_perform_action.js index 979298629..ba79b63f8 100644 --- a/public/assets/tests/form_ticket_perform_action.js +++ b/public/assets/tests/form_ticket_perform_action.js @@ -1,5 +1,5 @@ // ticket_perform_action -test( "ticket_perform_action check", function() { +test( "ticket_perform_action check", function(assert) { App.TicketPriority.refresh([ { @@ -251,7 +251,6 @@ test( "ticket_perform_action check", function() { row.find('.js-datepicker').datepicker('setDate') row.find('.js-timepicker').val(date_parsed.getHours() + ':' + date_parsed.getMinutes()).trigger('blur') - params = App.ControllerForm.params(el) test_params = { ticket_perform_action1: { 'ticket.state_id': { @@ -288,7 +287,14 @@ test( "ticket_perform_action check", function() { } } } - deepEqual(params, test_params, 'form param check') + + var done = assert.async() + + setTimeout(function(){ + params = App.ControllerForm.params(el) + deepEqual(params, test_params, 'form param check') + done() + }, 0); // switch pending time to relative @@ -504,3 +510,39 @@ test( "ticket_perform_action backwards check after PR#2862", function() { deepEqual(params, test_params, 'form param check') }); + +test( "ticket_perform_action orphan time fields", function() { + $('#forms').append('

ticket_perform_action orphan time fields

') + + var el = $('#form4') + + var defaults = { + ticket_perform_action4: { + 'ticket.pending_time': { + operator: 'relative', + value: '1' + } + } + } + + new App.ControllerForm({ + el: el, + model: { + configure_attributes: [ + { + name: 'ticket_perform_action4', + display: 'TicketPerformAction4', + tag: 'ticket_perform_action', + null: true, + }, + ] + }, + params: defaults, + autofocus: true + }) + + // change to another attribute + el.find('select:first').val('ticket.tags').trigger('change') + + equal(el.find('.js-valueRangeSelector').length, 0) +}); diff --git a/spec/system/js/q_unit_spec.rb b/spec/system/js/q_unit_spec.rb index 45be92d62..437b0a1c0 100644 --- a/spec/system/js/q_unit_spec.rb +++ b/spec/system/js/q_unit_spec.rb @@ -107,7 +107,7 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we end it 'Ticket perform action' do - q_unit_tests('form_ticket_perform_action') + async_q_unit_tests('form_ticket_perform_action') end it 'Ticket macro' do