Improved tag widget.

This commit is contained in:
Martin Edenhofer 2016-09-13 00:14:10 +02:00
parent f0c4c2f68a
commit 6adae4ed6b
3 changed files with 32 additions and 11 deletions

View file

@ -8,8 +8,8 @@ class App.WidgetTag extends App.Controller
events: events:
'click .js-newTagLabel': 'showInput' 'click .js-newTagLabel': 'showInput'
'blur .js-newTagInput': 'hideOrAddInput' 'blur .js-newTagInput': 'hideAndAddInput'
'click .js-newTagInput': 'onAddTag' 'keyup .js-newTagInput': 'addInput'
'submit form': 'onAddTag' 'submit form': 'onAddTag'
'click .js-delete': 'onRemoveTag' 'click .js-delete': 'onRemoveTag'
'click .js-tag': 'searchTag' 'click .js-tag': 'searchTag'
@ -26,6 +26,10 @@ class App.WidgetTag extends App.Controller
@fetch() @fetch()
addInput: (e) =>
return if e.keyCode isnt 9 # tab
@hideAndAddInput()
fetch: => fetch: =>
@pendingRefresh = false @pendingRefresh = false
@ajax( @ajax(
@ -72,14 +76,14 @@ class App.WidgetTag extends App.Controller
@newTagInput.removeClass('hide').focus() @newTagInput.removeClass('hide').focus()
@editMode = true @editMode = true
hideOrAddInput: (e) => hideAndAddInput: =>
e.preventDefault()
@newTagLabel.removeClass('hide') @newTagLabel.removeClass('hide')
@newTagInput.addClass('hide') @newTagInput.addClass('hide')
@onAddTag(e) @onAddTag()
@editMode = false @editMode = false
onAddTag: (e) => onAddTag: (e) =>
if e
e.preventDefault() e.preventDefault()
item = @$('[name="new_tag"]').val().trim() item = @$('[name="new_tag"]').val().trim()
if !item if !item
@ -118,7 +122,6 @@ class App.WidgetTag extends App.Controller
@remove(item) @remove(item)
remove: (item) => remove: (item) =>
@localTags = _.filter(@localTags, (tagItem) -> return tagItem if tagItem isnt item) @localTags = _.filter(@localTags, (tagItem) -> return tagItem if tagItem isnt item)
@render() @render()

View file

@ -451,6 +451,7 @@ class AgentTicketTagTest < TestCase
body: 'some body 223äöü - tags no new 1', body: 'some body 223äöü - tags no new 1',
}, },
) )
sleep 2
click(css: '.active .sidebar .js-newTagLabel') click(css: '.active .sidebar .js-newTagLabel')
set( set(
@ -459,6 +460,7 @@ class AgentTicketTagTest < TestCase
) )
sleep 2 sleep 2
sendkey(value: :tab) sendkey(value: :tab)
sleep 1
click(css: '.active .sidebar .js-newTagLabel') click(css: '.active .sidebar .js-newTagLabel')
set( set(
css: '.active .sidebar .js-newTagInput', css: '.active .sidebar .js-newTagInput',
@ -466,6 +468,7 @@ class AgentTicketTagTest < TestCase
) )
sleep 2 sleep 2
sendkey(value: :tab) sendkey(value: :tab)
sleep 1
click(css: '.active .sidebar .js-newTagLabel') click(css: '.active .sidebar .js-newTagLabel')
set( set(
css: '.active .sidebar .js-newTagInput', css: '.active .sidebar .js-newTagInput',
@ -473,6 +476,7 @@ class AgentTicketTagTest < TestCase
) )
sleep 2 sleep 2
sendkey(value: :tab) sendkey(value: :tab)
sleep 1
click(css: '.active .sidebar .js-newTagLabel') click(css: '.active .sidebar .js-newTagLabel')
set( set(
css: '.active .sidebar .js-newTagInput', css: '.active .sidebar .js-newTagInput',
@ -480,6 +484,7 @@ class AgentTicketTagTest < TestCase
) )
sleep 2 sleep 2
sendkey(value: :tab) sendkey(value: :tab)
sleep 1
# verify tags # verify tags
tags_verify( tags_verify(

View file

@ -589,7 +589,7 @@ class TestCase < Test::Unit::TestCase
css: '.some_class', css: '.some_class',
value: true, value: true,
slow: false, slow: false,
blur: true, blur: true, # default false
clear: true, # todo | default: true clear: true, # todo | default: true
no_click: true, no_click: true,
) )
@ -793,7 +793,7 @@ class TestCase < Test::Unit::TestCase
sendkey( sendkey(
browser: browser1, browser: browser1,
value: :enter, value: :enter,
slow: false, slow: false, # default false
) )
=end =end
@ -803,15 +803,28 @@ class TestCase < Test::Unit::TestCase
log('sendkey', params) log('sendkey', params)
instance = params[:browser] || @browser instance = params[:browser] || @browser
element = nil
if params[:css]
element = instance.find_elements(css: params[:css])[0]
end
screenshot(browser: instance, comment: 'sendkey_before') screenshot(browser: instance, comment: 'sendkey_before')
if params[:value].class == Array if params[:value].class == Array
params[:value].each { |key| params[:value].each { |key|
if element
element.send_keys(key)
else
instance.action.send_keys(key).perform instance.action.send_keys(key).perform
end
} }
screenshot(browser: instance, comment: 'sendkey_after') screenshot(browser: instance, comment: 'sendkey_after')
return return
end end
if element
element.send_keys(params[:value])
else
instance.action.send_keys(params[:value]).perform instance.action.send_keys(params[:value]).perform
end
if params[:slow] if params[:slow]
sleep 1.5 sleep 1.5
else else