From 7c23e2a2d072cd83f92885b8797a6c79c960a54f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 28 Mar 2018 12:24:57 +0200 Subject: [PATCH] Fixed issue 1882 - Clearing the entered value in a not required ticket field. --- .../_application_controller_form.coffee | 4 +- .../app/models/_application_model.coffee | 4 +- public/assets/tests/form.js | 24 +++--- public/assets/tests/form_validation.js | 10 +-- script/build/test_slice_tests.sh | 6 ++ test/browser/agent_ticket_update4_test.rb | 77 +++++++++++++++++++ test/browser_test_helper.rb | 34 ++++++++ 7 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 test/browser/agent_ticket_update4_test.rb diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.coffee index 9083d24db..9afbad5a1 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.coffee @@ -507,7 +507,7 @@ class App.ControllerForm extends App.Controller param[newKey] = "invalid #{param[key]}" console.log('ERR', err) else - param[newKey] = undefined + param[newKey] = null delete param[key] # get {datetime} @@ -525,7 +525,7 @@ class App.ControllerForm extends App.Controller param[newKey] = "invalid #{param[key]}" console.log('ERR', err) else - param[newKey] = undefined + param[newKey] = null delete param[key] # split :: fields, build objects diff --git a/app/assets/javascripts/app/models/_application_model.coffee b/app/assets/javascripts/app/models/_application_model.coffee index 25e7cb4aa..b0f1315db 100644 --- a/app/assets/javascripts/app/models/_application_model.coffee +++ b/app/assets/javascripts/app/models/_application_model.coffee @@ -124,13 +124,13 @@ class App.Model extends Spine.Model if parts[0] && !parts[1] # key exists not in hash || value is '' || value is undefined - if !( attributeName of data['params'] ) || data['params'][attributeName] is '' || data['params'][attributeName] is undefined + if !( attributeName of data['params'] ) || data['params'][attributeName] is '' || data['params'][attributeName] is undefined || data['params'][attributeName] is null errors[attributeName] = 'is required' else if parts[0] && parts[1] && !parts[2] # key exists not in hash || value is '' || value is undefined - if !data.params[parts[0]] || !( parts[1] of data.params[parts[0]] ) || data.params[parts[0]][parts[1]] is '' || data.params[parts[0]][parts[1]] is undefined + if !data.params[parts[0]] || !( parts[1] of data.params[parts[0]] ) || data.params[parts[0]][parts[1]] is '' || data.params[parts[0]][parts[1]] is undefined || data.params[parts[0]][parts[1]] is null errors[attributeName] = 'is required' else diff --git a/public/assets/tests/form.js b/public/assets/tests/form.js index 46d22e110..895c433b2 100644 --- a/public/assets/tests/form.js +++ b/public/assets/tests/form.js @@ -281,13 +281,13 @@ test("form params check", function() { richtext7: '', richtext8: '
lalu b lalu
', datetime1: '2015-01-11T12:40:00.000Z', - datetime2: undefined, + datetime2: null, datetime3: '2015-01-11T12:40:00.000Z', - datetime4: undefined, + datetime4: null, date1: '2015-01-11', - date2: undefined, + date2: null, date3: '2015-01-11', - date4: undefined, + date4: null, active1: true, active2: false, checkbox1: [], @@ -518,13 +518,13 @@ test("form dependend fields check", function() { selectmulti2: [ "true", "false" ], selectmultioption1: "false", datetime1: '2015-01-11T12:40:00.000Z', - datetime2: undefined, + datetime2: null, datetime3: '2015-01-11T12:40:00.000Z', - datetime4: undefined, + datetime4: null, date1: '2015-01-11', - date2: undefined, + date2: null, date3: '2015-01-11', - date4: undefined, + date4: null, } deepEqual(params, test_params, 'form param check') @@ -547,13 +547,13 @@ test("form dependend fields check", function() { selectmulti2: [ "true", "false" ], selectmultioption1: "false", datetime1: null, - datetime2: undefined, + datetime2: null, datetime3: '2015-01-11T12:40:00.000Z', - datetime4: undefined, + datetime4: null, date1: '2015-01-11', - date2: undefined, + date2: null, date3: '2015-01-11', - date4: undefined, + date4: null, } deepEqual(params, test_params, 'form param check') }); diff --git a/public/assets/tests/form_validation.js b/public/assets/tests/form_validation.js index c0e00ac9d..1a4291130 100644 --- a/public/assets/tests/form_validation.js +++ b/public/assets/tests/form_validation.js @@ -111,7 +111,7 @@ test('datetime validation check', function() { // check params params = App.ControllerForm.params(el) test_params = { - datetime1: undefined, + datetime1: null, } deepEqual(params, test_params, 'params check') @@ -191,7 +191,7 @@ test('date validation check', function() { // check params params = App.ControllerForm.params(el) test_params = { - date2: undefined, + date2: null, } deepEqual(params, test_params, 'params check') @@ -234,7 +234,7 @@ test('date validation check', function() { // check params params = App.ControllerForm.params(el) test_params = { - date2: undefined, + date2: null, } deepEqual(params, test_params, 'params check') @@ -269,7 +269,7 @@ test( "datetime selector check", function() { // check params params = App.ControllerForm.params(el) test_params = { - datetime1: undefined, + datetime1: null, } deepEqual(params, test_params, 'params check') @@ -330,7 +330,7 @@ test( "date selector check", function() { // check params params = App.ControllerForm.params(el) test_params = { - date3: undefined, + date3: null, } deepEqual(params, test_params, 'params check') diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index af19f1fc3..e23cd0df7 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -38,6 +38,7 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/agent_ticket_update1_test.rb rm test/browser/agent_ticket_update2_test.rb rm test/browser/agent_ticket_update3_test.rb + rm test/browser/agent_ticket_update4_test.rb rm test/browser/agent_ticket_update_and_reload_test.rb rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_profile_test.rb @@ -100,6 +101,7 @@ elif [ "$LEVEL" == '2' ]; then # test/browser/agent_ticket_update1_test.rb # test/browser/agent_ticket_update2_test.rb # test/browser/agent_ticket_update3_test.rb + # test/browser/agent_ticket_update4_test.rb # test/browser/agent_ticket_update_and_reload_test.rb rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_profile_test.rb @@ -162,6 +164,7 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/agent_ticket_update1_test.rb rm test/browser/agent_ticket_update2_test.rb rm test/browser/agent_ticket_update3_test.rb + rm test/browser/agent_ticket_update4_test.rb rm test/browser/agent_ticket_update_and_reload_test.rb rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_profile_test.rb @@ -224,6 +227,7 @@ elif [ "$LEVEL" == '4' ]; then rm test/browser/agent_ticket_update1_test.rb rm test/browser/agent_ticket_update2_test.rb rm test/browser/agent_ticket_update3_test.rb + rm test/browser/agent_ticket_update4_test.rb rm test/browser/agent_ticket_update_and_reload_test.rb rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_profile_test.rb @@ -285,6 +289,7 @@ elif [ "$LEVEL" == '5' ]; then rm test/browser/agent_ticket_update1_test.rb rm test/browser/agent_ticket_update2_test.rb rm test/browser/agent_ticket_update3_test.rb + rm test/browser/agent_ticket_update4_test.rb rm test/browser/agent_ticket_update_and_reload_test.rb # test/browser/agent_user_manage_test.rb # test/browser/agent_user_profile_test.rb @@ -349,6 +354,7 @@ elif [ "$LEVEL" == '6' ]; then rm test/browser/agent_ticket_update1_test.rb rm test/browser/agent_ticket_update2_test.rb rm test/browser/agent_ticket_update3_test.rb + rm test/browser/agent_ticket_update4_test.rb rm test/browser/agent_ticket_update_and_reload_test.rb rm test/browser/agent_user_manage_test.rb rm test/browser/agent_user_profile_test.rb diff --git a/test/browser/agent_ticket_update4_test.rb b/test/browser/agent_ticket_update4_test.rb new file mode 100644 index 000000000..79df969db --- /dev/null +++ b/test/browser/agent_ticket_update4_test.rb @@ -0,0 +1,77 @@ +require 'browser_test_helper' + +class AgentTicketUpdate4Test < TestCase + + def test_update_date_object_for_ticket + + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + # date object + object_manager_attribute_create( + data: { + name: 'date1', + display: "Date-#{rand(999_999)}", + data_type: 'Date', + }, + ) + + watch_for( + css: '.content.active', + value: 'Database Update required', + ) + + click(css: '.content.active .tab-pane.active div.js-execute') + watch_for( + css: '.modal', + value: 'restart', + ) + watch_for_disappear( + css: '.modal', + timeout: 120, + ) + sleep 5 + watch_for( + css: '.content.active', + ) + + # create new ticket + ticket = ticket_create( + data: { + customer: 'nico', + group: 'Users', + priority: '2 normal', + state: 'open', + title: 'ticket attribute test #1', + body: 'ticket attribute test #1', + }, + custom_data_date: { + date1: '02/28/2018', + }, + disable_group_check: true, + ) + + ticket_open_by_search( + browser: @browser, + number: ticket[:number], + ) + + ticket_update( + data: {}, + custom_data_date: { + date1: '', + }, + ) + click(css: '.content.active .js-submit') + + match_not( + css: '.active .sidebar div[data-name="date1"] input[data-item="date"]', + value: '02/28/2018', + ) + end +end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index a6c3744eb..ccbdec8f4 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1832,6 +1832,9 @@ wait untill text in selector disabppears custom_data_input: { key1: 'some value', }, + custom_data_date: { + key!: '02/28/2018', + } disable_group_check: true, ) @@ -1984,6 +1987,14 @@ wait untill text in selector disabppears clear: true, ) end + params[:custom_data_date]&.each do |local_key, local_value| + set( + browser: instance, + css: ".content.active .newTicket div[data-name=\"#{local_key}\"] input[data-item=\"date\"]", + value: local_value, + clear: true, + ) + end if data[:attachment] file_upload( @@ -2064,6 +2075,9 @@ wait untill text in selector disabppears custom_data_input: { key1: 'some value', }, + custom_data_date: { + key1: '02/21/2018', + }, do_not_submit: true, task_type: 'stayOnTab', # default: stayOnTab / possible: closeTab, closeNextInOverview, stayOnTab ) @@ -2214,6 +2228,26 @@ wait untill text in selector disabppears clear: true, ) end + params[:custom_data_date]&.each do |local_key, local_value| + click( + browser: instance, + css: ".active .sidebar div[data-name=\"#{local_key}\"] input[data-item=\"date\"]", + mute_log: true, + ) + # weird bug where you cannot "clear" for date/time input + # this is specific chrome problem, chrome bug report: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1319#c2 + # indirect issue: https://github.com/angular/protractor/issues/562#issuecomment-47745263 + 11.times do + sendkey( + value: :backspace, + ) + end + set( + browser: instance, + css: ".active .sidebar div[data-name=\"#{local_key}\"] input[data-item=\"date\"]", + value: local_value, + ) + end if data[:state] || data[:group] || data[:body] || params[:custom_data_select].present? || params[:custom_data_input].present? found = nil