From ce1135a55c1e9b127f99bf2d5f9647128d603d2e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 24 Nov 2017 16:54:56 +0100 Subject: [PATCH] Fixed issue #1670 - Reset customer selection in ticket create screen if input field cleared. --- .../sidebar_customer.coffee | 3 +- .../app/controllers/ticket_customer.coffee | 13 +- ..._object_organization_autocompletion.coffee | 39 +-- script/build/test_slice_tests.sh | 6 + ...et_create_reset_customer_selection_test.rb | 244 ++++++++++++++++++ test/browser/agent_user_manage_test.rb | 18 +- test/browser_test_helper.rb | 2 +- 7 files changed, 297 insertions(+), 28 deletions(-) create mode 100644 test/browser/agent_ticket_create_reset_customer_selection_test.rb diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create/sidebar_customer.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create/sidebar_customer.coffee index cbfd4e7e9..b4b80bdeb 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create/sidebar_customer.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create/sidebar_customer.coffee @@ -1,7 +1,7 @@ class SidebarCustomer extends App.Controller sidebarItem: => return if !@permissionCheck('ticket.agent') - return if !@params.customer_id + return if _.isEmpty(@params.customer_id) { head: 'Customer' name: 'customer' @@ -18,6 +18,7 @@ class SidebarCustomer extends App.Controller showCustomer: (el) => @el = el + return if _.isEmpty(@params.customer_id) new App.WidgetUser( el: @el user_id: @params.customer_id diff --git a/app/assets/javascripts/app/controllers/ticket_customer.coffee b/app/assets/javascripts/app/controllers/ticket_customer.coffee index edb5df0c0..ba50eb0ba 100644 --- a/app/assets/javascripts/app/controllers/ticket_customer.coffee +++ b/app/assets/javascripts/app/controllers/ticket_customer.coffee @@ -18,8 +18,19 @@ class App.TicketCustomer extends App.ControllerModal onSubmit: (e) => params = @formParam(e.target) - @customer_id = params['customer_id'] + ticket = App.Ticket.find(@ticket_id) + ticket.customer_id = params['customer_id'] + errors = ticket.validate() + if !_.isEmpty(errors) + @log 'error', errors + @formValidate( + form: e.target + errors: errors + ) + return + + @customer_id = params['customer_id'] callback = => # close modal diff --git a/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee b/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee index 011dc2202..da0d8b2ee 100644 --- a/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee +++ b/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee @@ -71,7 +71,7 @@ class App.ObjectOrganizationAutocompletion extends App.Controller @open() focusInput: => - @objectSelect.focus() if not @formControl.hasClass 'focus' + @objectSelect.focus() if not @formControl.hasClass('focus') onBlur: => selectObject = @objectSelect.val() @@ -85,6 +85,9 @@ class App.ObjectOrganizationAutocompletion extends App.Controller @objectId.val("guess:#{selectObject}") @formControl.removeClass 'focus' + resetObjectSelection: => + @objectId.val('').trigger('change') + onObjectClick: (e) => objectId = $(e.currentTarget).data('object-id') @selectObject(objectId) @@ -103,23 +106,23 @@ class App.ObjectOrganizationAutocompletion extends App.Controller # Only work with the last one since its the newest one objectId = @objectId.val().split(',').pop() - return if !objectId - return if !App[@objectSingle].exists(objectId) - object = App[@objectSingle].find(objectId) - name = object.displayName() + if objectId && App[@objectSingle].exists(objectId) + object = App[@objectSingle].find(objectId) + name = object.displayName() - if @attribute.multiple - # create token - @createToken name, objectId - else - if object.email + if @attribute.multiple - # quote name for special character - if name.match(/\@|,|;|\^|\+|#|§|\$|%|&|\/|\(|\)|=|\?|!|\*|\[|\]/) - name = "\"#{name}\"" - name += " <#{object.email}>" + # create token + @createToken(name, objectId) + else + if object.email - @objectSelect.val(name) + # quote name for special character + if name.match(/\@|,|;|\^|\+|#|§|\$|%|&|\/|\(|\)|=|\?|!|\*|\[|\]/) + name = "\"#{name}\"" + name += " <#{object.email}>" + + @objectSelect.val(name) if @callback @callback(objectId) @@ -321,12 +324,16 @@ class App.ObjectOrganizationAutocompletion extends App.Controller @hideOrganizationMembers() # hide dropdown - if !query + if _.isEmpty(query) @emptyResultList() if !@attribute.disableCreateObject @recipientList.append(@buildObjectNew()) + # reset object selection + @resetObjectSelection() + return + # show dropdown if query && ( !@attribute.minLengt || @attribute.minLengt <= query.length ) @lazySearch(query) diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 34e837538..559f49fa0 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -20,6 +20,7 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/admin_role_test.rb # test/browser/agent_navigation_and_title_test.rb rm test/browser/agent_ticket_attachment_test.rb + rm test/browser/agent_ticket_create_reset_customer_selection_test.rb rm test/browser/agent_ticket_email_reply_keep_body_test.rb rm test/browser/agent_ticket_email_signature_test.rb rm test/browser/agent_ticket_link_test.rb @@ -78,6 +79,7 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/agent_navigation_and_title_test.rb rm test/browser/agent_organization_profile_test.rb rm test/browser/agent_ticket_attachment_test.rb + rm test/browser/agent_ticket_create_reset_customer_selection_test.rb rm test/browser/agent_ticket_email_reply_keep_body_test.rb rm test/browser/agent_ticket_email_signature_test.rb rm test/browser/agent_ticket_link_test.rb @@ -136,6 +138,7 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/agent_navigation_and_title_test.rb rm test/browser/agent_organization_profile_test.rb # test/browser/agent_ticket_attachment_test.rb + # test/browser/agent_ticket_create_reset_customer_selection_test.rb # test/browser/agent_ticket_email_reply_keep_body_test.rb # test/browser/agent_ticket_email_signature_test.rb # test/browser/agent_ticket_link_test.rb @@ -194,6 +197,7 @@ elif [ "$LEVEL" == '4' ]; then rm test/browser/agent_navigation_and_title_test.rb rm test/browser/agent_organization_profile_test.rb rm test/browser/agent_ticket_attachment_test.rb + rm test/browser/agent_ticket_create_reset_customer_selection_test.rb rm test/browser/agent_ticket_email_reply_keep_body_test.rb rm test/browser/agent_ticket_email_signature_test.rb rm test/browser/agent_ticket_link_test.rb @@ -251,6 +255,7 @@ elif [ "$LEVEL" == '5' ]; then rm test/browser/agent_navigation_and_title_test.rb # test/browser/agent_organization_profile_test.rb rm test/browser/agent_ticket_attachment_test.rb + rm test/browser/agent_ticket_create_reset_customer_selection_test.rb rm test/browser/agent_ticket_email_reply_keep_body_test.rb rm test/browser/agent_ticket_email_signature_test.rb rm test/browser/agent_ticket_link_test.rb @@ -311,6 +316,7 @@ elif [ "$LEVEL" == '6' ]; then rm test/browser/agent_navigation_and_title_test.rb rm test/browser/agent_organization_profile_test.rb rm test/browser/agent_ticket_attachment_test.rb + rm test/browser/agent_ticket_create_reset_customer_selection_test.rb rm test/browser/agent_ticket_email_reply_keep_body_test.rb rm test/browser/agent_ticket_email_signature_test.rb rm test/browser/agent_ticket_link_test.rb diff --git a/test/browser/agent_ticket_create_reset_customer_selection_test.rb b/test/browser/agent_ticket_create_reset_customer_selection_test.rb new file mode 100644 index 000000000..29ebe49dc --- /dev/null +++ b/test/browser/agent_ticket_create_reset_customer_selection_test.rb @@ -0,0 +1,244 @@ + +require 'browser_test_helper' + +class AgentTicketCreateResetCustomerSelectionTest < TestCase + def test_clear_customer + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + click(css: 'a[href="#new"]') + click(css: 'a[href="#ticket/create"]') + sleep 2 + + exists(css: '.content.active .newTicket') + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="template"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab.active[data-tab="template"]') + + exists_not(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]') + exists_not(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="customer"]') + + click(css: '.content.active .newTicket [name="customer_id_completion"]') + + # check if pulldown is open, it's not working stable via selenium + @browser.execute_script( "$('.content.active .newTicket .js-recipientDropdown').addClass('open')" ) + + set( + css: '.content.active .newTicket input[name="customer_id_completion"]', + value: 'nicole', + ) + + sleep 2 + sendkey(value: :enter) + sleep 1 + + exists(css: '.content.active .newTicket') + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="template"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab.active[data-tab="template"]') + + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="customer"]') + + set( + css: '.content.active .newTicket input[name="customer_id_completion"]', + value: '', + ) + sendkey(value: :backspace) + + sleep 1 + + exists(css: '.content.active .newTicket') + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="template"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab.active[data-tab="template"]') + + exists_not(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]') + exists_not(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="customer"]') + + set( + css: '.content.active .newTicket input[name="title"]', + value: 'some title', + ) + + set( + css: '.content.active .newTicket div[data-name="body"]', + value: 'some body', + ) + + select( + css: '.content.active .newTicket select[name="group_id"]', + value: 'Users', + ) + + click(css: '.content.active .newTicket .js-submit') + + watch_for( + css: '.content.active .newTicket .user_autocompletion.form-group.has-error', + ) + + # cleanup + tasks_close_all() + end + + def test_clear_customer_use_email + @browser = browser_instance + login( + username: 'master@example.com', + password: 'test', + url: browser_url, + ) + tasks_close_all() + + click(css: 'a[href="#new"]') + click(css: 'a[href="#ticket/create"]') + sleep 2 + + exists(css: '.content.active .newTicket') + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="template"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab.active[data-tab="template"]') + + exists_not(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]') + exists_not(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="customer"]') + + click(css: '.content.active .newTicket [name="customer_id_completion"]') + + # check if pulldown is open, it's not working stable via selenium + @browser.execute_script( "$('.content.active .newTicket .js-recipientDropdown').addClass('open')" ) + + set( + css: '.content.active .newTicket input[name="customer_id_completion"]', + value: 'nicole', + ) + + sleep 2 + sendkey(value: :enter) + sleep 1 + + exists(css: '.content.active .newTicket') + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="template"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab.active[data-tab="template"]') + + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="customer"]') + + set( + css: '.content.active .newTicket input[name="customer_id_completion"]', + value: '', + ) + sendkey(value: :backspace) + + sleep 1 + + exists(css: '.content.active .newTicket') + exists(css: '.content.active .tabsSidebar .sidebar[data-tab="template"]') + exists(css: '.content.active .tabsSidebar .tabsSidebar-tab.active[data-tab="template"]') + + exists_not(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]') + exists_not(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="customer"]') + + set( + css: '.content.active .newTicket input[name="customer_id_completion"]', + value: 'somecustomer_not_existing_right_now@example.com', + ) + + set( + css: '.content.active .newTicket input[name="title"]', + value: 'some title', + ) + + set( + css: '.content.active .newTicket div[data-name="body"]', + value: 'some body', + ) + + select( + css: '.content.active .newTicket select[name="group_id"]', + value: 'Users', + ) + + click(css: '.content.active .newTicket .js-submit') + + watch_for( + css: '.content.active .ticketZoom-header .ticket-number', + value: '\d', + ) + + click(css: '.content.active .tabsSidebar-tabs .tabsSidebar-tab[data-tab="customer"]') + + match( + css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]', + value: 'somecustomer_not_existing_right_now@example.com', + ) + + click(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"] .js-actions') + click(css: '.content.active .tabsSidebar .sidebar[data-tab="customer"] .js-actions li[data-type="customer-change"]') + + watch_for( + css: '.content.active .modal', + ) + + exists_not( + css: '.content.active .modal .user_autocompletion.form-group.has-error', + ) + + click(css: '.content.active .modal .js-submit') + + watch_for( + css: '.content.active .modal .user_autocompletion.form-group.has-error', + ) + + set( + css: '.content.active .modal input[name="customer_id_completion"]', + value: 'master', + ) + + click(css: '.content.active .modal .js-submit') + + watch_for( + css: '.content.active .modal .user_autocompletion.form-group.has-error', + ) + + set( + css: '.content.active .modal input[name="customer_id_completion"]', + value: 'master', + ) + + sendkey(value: :enter) + sleep 1 + + set( + css: '.content.active .modal input[name="customer_id_completion"]', + value: '', + ) + sendkey(value: :backspace) + sleep 1 + + click(css: '.content.active .modal .js-submit') + + watch_for( + css: '.content.active .modal .user_autocompletion.form-group.has-error', + ) + + set( + css: '.content.active .modal input[name="customer_id_completion"]', + value: 'master', + ) + + sendkey(value: :enter) + sleep 1 + + click(css: '.content.active .modal .js-submit') + #click(css: '.content.active .tabsSidebar-tabs .tabsSidebar-tab[data-tab="customer"]') + + watch_for( + css: '.content.active .tabsSidebar .sidebar[data-tab="customer"]', + value: 'master@example.com', + ) + + # cleanup + tasks_close_all() + end +end diff --git a/test/browser/agent_user_manage_test.rb b/test/browser/agent_user_manage_test.rb index 4d2160f29..4c82d1b16 100644 --- a/test/browser/agent_user_manage_test.rb +++ b/test/browser/agent_user_manage_test.rb @@ -19,17 +19,17 @@ class AgentUserManageTest < TestCase sleep 1 # create customer - click( css: 'a[href="#new"]' ) - click( css: 'a[href="#ticket/create"]' ) - click( css: '.active .newTicket [name="customer_id_completion"]' ) + click(css: 'a[href="#new"]') + click(css: 'a[href="#ticket/create"]') + click(css: '.active .newTicket [name="customer_id_completion"]') # check if pulldown is open, it's not working stable via selenium @browser.execute_script( "$('.active .newTicket .js-recipientDropdown').addClass('open')" ) sleep 1 - sendkey( value: :arrow_down ) + sendkey(value: :arrow_down) sleep 0.5 - click( css: '.active .newTicket .recipientList-entry.js-objectNew' ) + click(css: '.active .newTicket .recipientList-entry.js-objectNew') sleep 1 set( @@ -45,7 +45,7 @@ class AgentUserManageTest < TestCase value: customer_user_email, ) - click( css: '.modal button.js-submit' ) + click(css: '.modal button.js-submit') sleep 4 # check is used to check selected @@ -75,8 +75,8 @@ class AgentUserManageTest < TestCase # call new ticket screen again tasks_close_all() - click( css: 'a[href="#new"]' ) - click( css: 'a[href="#ticket/create"]' ) + click(css: 'a[href="#new"]') + click(css: 'a[href="#ticket/create"]') sleep 2 match( @@ -93,7 +93,7 @@ class AgentUserManageTest < TestCase ) sleep 3 - click( css: '.active .newTicket .recipientList-entry.js-object.is-active' ) + click(css: '.active .newTicket .recipientList-entry.js-object.is-active') sleep 1 # check is used to check selected diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 909503218..3f4decb00 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1261,7 +1261,7 @@ set type of task (closeTab, closeNextInOverview, stayOnTab) sleep 0.5 return true - # match pn attribute + # match an attribute else text = if params[:attribute] element.attribute(params[:attribute])