From a960cdf4225f327bfba5f4b5b8a779e198e363d6 Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Tue, 30 Oct 2018 22:51:20 +0100 Subject: [PATCH] Fixed issue #2042 - incorrect notification when closing a tab after setting up an object (fixes #2042) --- .../javascripts/app/lib/app_post/utils.coffee | 5 ++ public/assets/tests/html_utils.js | 27 ++++++++-- script/build/test_slice_tests.sh | 6 +++ .../browser/agent_ticket_task_changed_test.rb | 53 +++++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 test/browser/agent_ticket_task_changed_test.rb diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 44ae9459d..400025117 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -753,6 +753,11 @@ class App.Utils changes[dataNowkey] = diff else if _.isObject( dataNow[dataNowkey] ) && _.isObject( dataLast[dataNowkey] ) changes = @_formDiffChanges( dataNow[dataNowkey], dataLast[dataNowkey], changes ) + # fix for issue #2042 - incorrect notification when closing a tab after setting up an object + # Ignore the diff if both conditions are true: + # 1. current value is the empty string (no user input yet) + # 2. no previous value (it's a newly added attribute) + else if dataNow[dataNowkey] == '' && !dataLast[dataNowkey]? else changes[dataNowkey] = dataNow[dataNowkey] changes diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index a9826538d..4b7f9f3c5 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -1508,7 +1508,6 @@ test("check form diff", function() { pending_date: '2015-01-28T09:39:00Z', } diff = { - owner_id: '', } result = App.Utils.formDiff(dataNow, dataLast) deepEqual(result, diff, 'check form diff') @@ -1520,7 +1519,6 @@ test("check form diff", function() { } dataLast = {} diff = { - owner_id: '', state_ids: ['1','5','6','7'], } result = App.Utils.formDiff(dataNow, dataLast) @@ -1548,7 +1546,6 @@ test("check form diff", function() { state_ids: ['1','5','7'], } diff = { - owner_id: '', state_ids: ['6'], } result = App.Utils.formDiff(dataNow, dataLast) @@ -1714,6 +1711,30 @@ test("check form diff", function() { deepEqual(result, diff, 'check form diff') + // regression test for issue #2042 - incorrect notification when closing a tab after setting up an object + // A newly created attribute will have the empty string as its value, this should be ignored for formDiff comparison + dataNow = { + test: '', + } + dataLast = {} + diff = {} + result = App.Utils.formDiff(dataNow, dataLast) + deepEqual(result, diff, 'check form diff for a newly created attribute that is blank') + + + dataNow = { + test: '', + } + dataLast = { + test: '123', + } + diff = { + test: '', + } + result = App.Utils.formDiff(dataNow, dataLast) + deepEqual(result, diff, 'check form diff for setting a previously valid value to blank') + + dataNow = { test: '123', ticket: { diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 1f2243163..c44ee8c61 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -43,6 +43,7 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/agent_ticket_overview_level1_test.rb rm test/browser/agent_ticket_overview_tab_test.rb rm test/browser/agent_ticket_tag_test.rb + rm test/browser/agent_ticket_task_changed_test.rb rm test/browser/agent_ticket_text_module_test.rb rm test/browser/agent_ticket_time_accounting_test.rb rm test/browser/agent_ticket_update1_test.rb @@ -122,6 +123,7 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/agent_ticket_overview_level1_test.rb rm test/browser/agent_ticket_overview_tab_test.rb rm test/browser/agent_ticket_tag_test.rb + rm test/browser/agent_ticket_task_changed_test.rb # test/browser/agent_ticket_text_module_test.rb # test/browser/agent_ticket_time_accounting_test.rb # test/browser/agent_ticket_update1_test.rb @@ -201,6 +203,7 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/agent_ticket_overview_level1_test.rb rm test/browser/agent_ticket_overview_tab_test.rb # test/browser/agent_ticket_tag_test.rb + # test/browser/agent_ticket_task_changed_test.rb rm test/browser/agent_ticket_text_module_test.rb rm test/browser/agent_ticket_time_accounting_test.rb rm test/browser/agent_ticket_update1_test.rb @@ -280,6 +283,7 @@ elif [ "$LEVEL" == '4' ]; then # test/browser/agent_ticket_overview_level1_test.rb # test/browser/agent_ticket_overview_tab_test.rb rm test/browser/agent_ticket_tag_test.rb + rm test/browser/agent_ticket_task_changed_test.rb rm test/browser/agent_ticket_text_module_test.rb rm test/browser/agent_ticket_time_accounting_test.rb rm test/browser/agent_ticket_update1_test.rb @@ -358,6 +362,7 @@ elif [ "$LEVEL" == '5' ]; then rm test/browser/agent_ticket_overview_level1_test.rb rm test/browser/agent_ticket_overview_tab_test.rb rm test/browser/agent_ticket_tag_test.rb + rm test/browser/agent_ticket_task_changed_test.rb rm test/browser/agent_ticket_text_module_test.rb rm test/browser/agent_ticket_time_accounting_test.rb rm test/browser/agent_ticket_update1_test.rb @@ -439,6 +444,7 @@ elif [ "$LEVEL" == '6' ]; then rm test/browser/agent_ticket_overview_level1_test.rb rm test/browser/agent_ticket_overview_tab_test.rb rm test/browser/agent_ticket_tag_test.rb + rm test/browser/agent_ticket_task_changed_test.rb rm test/browser/agent_ticket_text_module_test.rb rm test/browser/agent_ticket_time_accounting_test.rb rm test/browser/agent_ticket_update1_test.rb diff --git a/test/browser/agent_ticket_task_changed_test.rb b/test/browser/agent_ticket_task_changed_test.rb new file mode 100644 index 000000000..d5c00c770 --- /dev/null +++ b/test/browser/agent_ticket_task_changed_test.rb @@ -0,0 +1,53 @@ +require 'browser_test_helper' + +class AgentTicketTaskChangedTest < TestCase + + # regression test for issue #2042 - incorrect notification when closing a tab after setting up an object + def test_detection_of_ticket_update_after_new_attribute + @browser = instance = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + ticket = ticket_create( + data: { + customer: 'nico', + group: 'Users', + title: 'test ticket', + body: 'some body 123äöü', + }, + ) + + object_manager_attribute_create( + data: { + name: 'text_test', + display: 'text_test', + data_type: 'Text', + }, + ) + object_manager_attribute_migrate + + ticket_open_by_title(title: 'test ticket') + + # verify the 'Discard your changes' message does not appear (since there are no changes) + assert_nil execute(js: "return $('.content.active .js-attributeBar .js-reset:not(\".hide\")').get(0)") + + # try and close the existing open ticket window + instance.action.move_to(instance.find_elements(css: '#navigation .tasks .task:first-child')[0]).release.perform + instance.find_elements(css: '#navigation .tasks .task:first-child .js-close')[0].click + + sleep 0.5 + exists_not( css: '.modal') + + object_manager_attribute_delete( + data: { + name: 'text_test', + }, + ) + object_manager_attribute_migrate + end + +end