From 9be7269646a8d09d8ec98e614f2f3384e09f33e6 Mon Sep 17 00:00:00 2001 From: Billy Zhou Date: Thu, 23 Aug 2018 15:44:32 +0800 Subject: [PATCH] Fixed issue #2206 and #2207 by limiting historical_options to only select attributes --- app/models/object_manager/attribute.rb | 4 +- .../admin_object_manager_tree_select_test.rb | 90 +++++++++++++++++++ test/browser_test_helper.rb | 22 ++--- 3 files changed, 104 insertions(+), 12 deletions(-) diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index d8e57d40c..547595c5d 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -621,7 +621,7 @@ to send no browser reload event, pass false # config changes if attribute.to_config execute_config_count += 1 - if attribute.data_option[:options] + if attribute.data_type == 'select' && attribute.data_option[:options] historical_options = attribute.data_option[:historical_options] || {} historical_options.update(attribute.data_option[:options]) historical_options.update(attribute.data_option_new[:options]) @@ -634,7 +634,7 @@ to send no browser reload event, pass false next if !attribute.to_create && !attribute.to_migrate && !attribute.to_delete end - if attribute.data_option[:options] + if attribute.data_type == 'select' && attribute.data_option[:options] attribute.data_option[:historical_options] = attribute.data_option[:options] end diff --git a/test/browser/admin_object_manager_tree_select_test.rb b/test/browser/admin_object_manager_tree_select_test.rb index 4303f7c88..df708e871 100644 --- a/test/browser/admin_object_manager_tree_select_test.rb +++ b/test/browser/admin_object_manager_tree_select_test.rb @@ -116,4 +116,94 @@ class AdminObjectManagerTreeSelectTest < TestCase ) end + # verify the fix for issue #2206 - Unable to modify tree_select attributes with fresh 2.6 + def test_modify_tree_select_attributes + @browser = instance = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + object_manager_attribute_create( + data: { + name: 'browser_test_tree_select2', + display: 'Browser Test TreeSelect2', + data_type: 'Tree Select', + data_option: { + options: { + 'Incident' => { + 'Hardware' => { + 'Monitor' => {}, + 'Mouse' => {}, + }, + }, + 'Service request' => { + 'New software requirement' => {}, + 'New hardware' => {}, + }, + 'Change request' => {}, + }, + }, + }, + ) + object_manager_attribute_migrate + + # open the newly created tree_select and add some new options + object_manager_attribute_update( + data: { + name: 'browser_test_tree_select2', + }, + do_not_submit: true, + ) + + # add two new first level entries + 2.times do |i| + instance.find_elements(css: '.modal .js-treeTable .js-key').last.click + + element = instance.find_elements(css: '.modal .js-treeTable .js-key').last + element.clear + element.send_keys("new tree option #{i}") + end + + click( + css: '.modal button.js-submit' + ) + modal_disappear + + object_manager_attribute_migrate + + # open the tree select again and check that the newly added options are there + watch_for( + css: '.content.active table', + value: 'browser_test_tree_select2', + ) + object_manager_attribute_update( + data: { + name: 'browser_test_tree_select2', + }, + do_not_submit: true, + ) + 2.times do |i| + exists( + css: '.modal .js-treeTable', + value: "new tree option #{i}", + ) + end + modal_close + + # clean up and confirm the deletion of newly created attributes + object_manager_attribute_delete( + data: { + name: 'browser_test_tree_select2', + }, + ) + object_manager_attribute_migrate + + match_not( + css: '.content.active table', + value: 'browser_test_tree_select2', + ) + end end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 9190cf1a3..84058f50c 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -4196,17 +4196,19 @@ wait untill text in selector disabppears options: data[:data_option][:options], ) else - # first clear all existing entries - loop do - target = { - browser: instance, - css: '.modal .js-Table .js-remove', - mute_log: true, - } - break if !instance.find_elements(css: target[:css])[0] - click(target) + if action == 'update' + # first clear all existing entries + loop do + target = { + browser: instance, + css: '.modal .js-Table .js-remove', + mute_log: true, + } + break if !instance.find_elements(css: target[:css])[0] + click(target) + end + sleep 1 end - sleep 1 # then populate the table with the new values data[:data_option][:options].each do |key, value|