From 6adae4ed6b194b0edaea69e030be8173f2dcfa2b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 13 Sep 2016 00:14:10 +0200 Subject: [PATCH] Improved tag widget. --- .../app/controllers/widget/tag.coffee | 17 ++++++++------- test/browser/agent_ticket_tag_test.rb | 5 +++++ test/browser_test_helper.rb | 21 +++++++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/app/controllers/widget/tag.coffee b/app/assets/javascripts/app/controllers/widget/tag.coffee index 3bcef170e..12d6a0408 100644 --- a/app/assets/javascripts/app/controllers/widget/tag.coffee +++ b/app/assets/javascripts/app/controllers/widget/tag.coffee @@ -8,8 +8,8 @@ class App.WidgetTag extends App.Controller events: 'click .js-newTagLabel': 'showInput' - 'blur .js-newTagInput': 'hideOrAddInput' - 'click .js-newTagInput': 'onAddTag' + 'blur .js-newTagInput': 'hideAndAddInput' + 'keyup .js-newTagInput': 'addInput' 'submit form': 'onAddTag' 'click .js-delete': 'onRemoveTag' 'click .js-tag': 'searchTag' @@ -26,6 +26,10 @@ class App.WidgetTag extends App.Controller @fetch() + addInput: (e) => + return if e.keyCode isnt 9 # tab + @hideAndAddInput() + fetch: => @pendingRefresh = false @ajax( @@ -72,15 +76,15 @@ class App.WidgetTag extends App.Controller @newTagInput.removeClass('hide').focus() @editMode = true - hideOrAddInput: (e) => - e.preventDefault() + hideAndAddInput: => @newTagLabel.removeClass('hide') @newTagInput.addClass('hide') - @onAddTag(e) + @onAddTag() @editMode = false onAddTag: (e) => - e.preventDefault() + if e + e.preventDefault() item = @$('[name="new_tag"]').val().trim() if !item if @pendingRefresh @@ -118,7 +122,6 @@ class App.WidgetTag extends App.Controller @remove(item) remove: (item) => - @localTags = _.filter(@localTags, (tagItem) -> return tagItem if tagItem isnt item) @render() diff --git a/test/browser/agent_ticket_tag_test.rb b/test/browser/agent_ticket_tag_test.rb index eb2c60ec4..e7fb24659 100644 --- a/test/browser/agent_ticket_tag_test.rb +++ b/test/browser/agent_ticket_tag_test.rb @@ -451,6 +451,7 @@ class AgentTicketTagTest < TestCase body: 'some body 223äöü - tags no new 1', }, ) + sleep 2 click(css: '.active .sidebar .js-newTagLabel') set( @@ -459,6 +460,7 @@ class AgentTicketTagTest < TestCase ) sleep 2 sendkey(value: :tab) + sleep 1 click(css: '.active .sidebar .js-newTagLabel') set( css: '.active .sidebar .js-newTagInput', @@ -466,6 +468,7 @@ class AgentTicketTagTest < TestCase ) sleep 2 sendkey(value: :tab) + sleep 1 click(css: '.active .sidebar .js-newTagLabel') set( css: '.active .sidebar .js-newTagInput', @@ -473,6 +476,7 @@ class AgentTicketTagTest < TestCase ) sleep 2 sendkey(value: :tab) + sleep 1 click(css: '.active .sidebar .js-newTagLabel') set( css: '.active .sidebar .js-newTagInput', @@ -480,6 +484,7 @@ class AgentTicketTagTest < TestCase ) sleep 2 sendkey(value: :tab) + sleep 1 # verify tags tags_verify( diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index ad2b5b886..8f3ff55c4 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -589,7 +589,7 @@ class TestCase < Test::Unit::TestCase css: '.some_class', value: true, slow: false, - blur: true, + blur: true, # default false clear: true, # todo | default: true no_click: true, ) @@ -793,7 +793,7 @@ class TestCase < Test::Unit::TestCase sendkey( browser: browser1, value: :enter, - slow: false, + slow: false, # default false ) =end @@ -803,15 +803,28 @@ class TestCase < Test::Unit::TestCase log('sendkey', params) instance = params[:browser] || @browser + element = nil + if params[:css] + element = instance.find_elements(css: params[:css])[0] + end screenshot(browser: instance, comment: 'sendkey_before') if params[:value].class == Array params[:value].each { |key| - instance.action.send_keys(key).perform + if element + element.send_keys(key) + else + instance.action.send_keys(key).perform + end } screenshot(browser: instance, comment: 'sendkey_after') return end - instance.action.send_keys(params[:value]).perform + + if element + element.send_keys(params[:value]) + else + instance.action.send_keys(params[:value]).perform + end if params[:slow] sleep 1.5 else