Improved use of text modules. Added unit tests.

This commit is contained in:
Martin Edenhofer 2013-07-17 15:57:12 +02:00
parent 78c6b96aa5
commit 72dbd0a291
6 changed files with 287 additions and 48 deletions

View file

@ -83,6 +83,7 @@ class App.TicketCreate extends App.Controller
# @clearInterval( @key, 'ticket_zoom' ) # @clearInterval( @key, 'ticket_zoom' )
@el.remove() @el.remove()
@clearInterval( @id, @auto_save_key ) @clearInterval( @id, @auto_save_key )
@textModule.release()
autosave: => autosave: =>
@auto_save_key = 'create' + @type + @id @auto_save_key = 'create' + @type + @id
@ -210,7 +211,7 @@ class App.TicketCreate extends App.Controller
# show text module UI # show text module UI
@textModule = new App.TextModuleUI( @textModule = new App.TextModuleUI(
el: $('.ticket-create') el: @el.find('.ticket-create')
) )
localUserInfo: (params) => localUserInfo: (params) =>

View file

@ -1,23 +1,6 @@
class App.TextModuleUI extends App.Controller class App.TextModuleUI extends App.Controller
constructor: -> constructor: ->
super super
ui = @
values = []
all = App.Collection.all( type: 'TextModule' )
for item in all
if item.active is true
contentNew = item.content.replace( /<%=\s{0,2}(.+?)\s{0,2}%>/g, ( all, key ) ->
key = key.replace( /@/g, 'ui.data.' )
varString = "#{key}" + ''
try
key = eval (varString)
catch error
# console.log( "tag replacement: " + error )
key = ''
return key
)
value = { val: contentNew, keywords: item.keywords || item.name }
values.push value
customItemTemplate = "<div><span />&nbsp;<small /></div>" customItemTemplate = "<div><span />&nbsp;<small /></div>"
elementFactory = (element, e) -> elementFactory = (element, e) ->
@ -26,7 +9,65 @@ class App.TextModuleUI extends App.Controller
.find('small') .find('small')
.text("(" + e.keywords + ")").end() .text("(" + e.keywords + ")").end()
element.append(template) element.append(template)
@el.find('textarea').sew({values: values, token: '::', elementFactory: elementFactory })
@el.find('textarea').sew(
values: @reload()
token: '::'
elementFactory: elementFactory
)
App.TextModule.bind(
'refresh change'
=>
@reload()
)
# subscribe and reload data / fetch new data if triggered
@bindLevel = 'TextModule-' + Math.floor( Math.random() * 99999 )
App.Event.bind(
'TextModule:updated TextModule:created TextModule:destroy'
=>
App.TextModule.fetch()
@bindLevel
)
# fetch init collection
App.TextModule.fetch()
release: =>
App.Event.unbindLevel(@bindLevel)
reload: (data = false) =>
if data
@lastData = data
all = App.TextModule.all()
values = [{val: '-', keywords: '-'}]
ui = @lastData || @
for item in all
if item.active is true
contentNew = item.content.replace( /<%=\s{0,2}(.+?)\s{0,2}%>/g, ( all, key ) ->
key = key.replace( /@/g, 'ui.data.' )
varString = "#{key}" + ''
try
key = eval (varString)
catch error
console.log( "tag replacement: " + error )
key = ''
return key
)
value = { val: contentNew, keywords: item.keywords || item.name }
values.push value
if values.length isnt 1
values.shift()
# set new data
if @el.find('textarea')[0]
if $(@el.find('textarea')[0]).data()
if $(@el.find('textarea')[0]).data().plugin_sew
$(@el.find('textarea')[0]).data().plugin_sew.options.values = values
return values
class App.TextModuleUIOld extends App.Controller class App.TextModuleUIOld extends App.Controller
events: events:

View file

@ -58,6 +58,7 @@ class App.TicketZoom extends App.Controller
return true return true
release: => release: =>
@textModule.release()
App.Event.unbindLevel 'ticket-zoom-' + @ticket_id App.Event.unbindLevel 'ticket-zoom-' + @ticket_id
@clearInterval( @key, 'ticket_zoom' ) @clearInterval( @key, 'ticket_zoom' )
@el.remove() @el.remove()
@ -184,7 +185,7 @@ class App.TicketZoom extends App.Controller
# show text module UI # show text module UI
if !@isRole('Customer') if !@isRole('Customer')
new App.TextModuleUI( @textModule = new App.TextModuleUI(
el: @el el: @el
data: data:
ticket: @ticket ticket: @ticket

View file

@ -38,9 +38,6 @@ module ExtraCollection
# all templates # all templates
collections['Template'] = Template.all collections['Template'] = Template.all
# all text modules
collections['TextModule'] = TextModule.all
end end
end end

View file

@ -3,4 +3,7 @@
class TextModule < ApplicationModel class TextModule < ApplicationModel
validates :name, :presence => true validates :name, :presence => true
validates :content, :presence => true validates :content, :presence => true
after_create :notify_clients_after_create
after_update :notify_clients_after_update
after_destroy :notify_clients_after_destroy
end end

View file

@ -2,16 +2,18 @@
require 'browser_test_helper' require 'browser_test_helper'
class TextModuleTest < TestCase class TextModuleTest < TestCase
def test_user def test_I
random = 'text_module_test_' + rand(999999).to_s random = 'text_module_test_' + rand(999999).to_s
random2 = 'text_module_test_' + rand(999999).to_s random2 = 'text_module_test_' + rand(999999).to_s
user_email = random + '@example.com'
# user # user
tests = [ tests = [
{ {
:name => 'add #1', :name => 'add #1',
:action => [ :action => [
{
:execute => 'close_all_tasks',
},
{ {
:execute => 'click', :execute => 'click',
:css => 'a[href="#admin"]', :css => 'a[href="#admin"]',
@ -20,18 +22,10 @@ class TextModuleTest < TestCase
:execute => 'click', :execute => 'click',
:css => 'a[href="#text_modules"]', :css => 'a[href="#text_modules"]',
}, },
{
:execute => 'wait',
:value => 1,
},
{ {
:execute => 'click', :execute => 'click',
:css => 'a[data-type="new"]', :css => 'a[data-type="new"]',
}, },
{
:execute => 'wait',
:value => 2,
},
{ {
:execute => 'set', :execute => 'set',
:css => 'input[name=name]', :css => 'input[name=name]',
@ -74,18 +68,10 @@ class TextModuleTest < TestCase
:execute => 'click', :execute => 'click',
:css => 'a[href="#text_modules"]', :css => 'a[href="#text_modules"]',
}, },
{
:execute => 'wait',
:value => 1,
},
{ {
:execute => 'click', :execute => 'click',
:css => 'a[data-type="new"]', :css => 'a[data-type="new"]',
}, },
{
:execute => 'wait',
:value => 1,
},
{ {
:execute => 'set', :execute => 'set',
:css => 'input[name=name]', :css => 'input[name=name]',
@ -148,9 +134,8 @@ class TextModuleTest < TestCase
:match_result => true, :match_result => true,
}, },
{ {
:execute => 'sendkey', :execute => 'click',
:css => '.active textarea[name=body]', :css => '.-sew-list-item.selected',
:value => :enter,
}, },
{ {
:execute => 'wait', :execute => 'wait',
@ -159,13 +144,224 @@ class TextModuleTest < TestCase
{ {
:execute => 'match', :execute => 'match',
:css => '.active textarea[name=body]', :css => '.active textarea[name=body]',
:value => random, :value => 'some content' + random,
:match_result => true, :match_result => true,
}, },
], ],
}, },
] ]
browser_signle_test_with_login(tests, { :username => 'master@example.com' }) browser_signle_test_with_login(tests, { :username => 'master@example.com' })
end end
def test_II
random = 'text_II_module_test_' + rand(999999).to_s
# user
tests = [
{
:name => 'start',
:instance1 => browser_instance,
:instance2 => browser_instance,
:instance1_username => 'master@example.com',
:instance1_password => 'test',
:instance2_username => 'agent1@example.com',
:instance2_password => 'test',
:action => [
# create ticket
{
:where => :instance2,
:execute => 'close_all_tasks',
},
{
:where => :instance2,
:execute => 'click',
:css => 'a[href="#new"]',
},
{
:where => :instance2,
:execute => 'click',
:css => 'a[href="#ticket_create/call_inbound"]',
},
{
:where => :instance2,
:execute => 'click',
:css => 'a[href="#new"]',
},
{
:where => :instance2,
:execute => 'set',
:css => '.active input[name=subject]',
:value => 'A',
},
{
:where => :instance2,
:execute => 'click',
:css => 'a[href="#ticket_create/call_outbound"]',
},
{
:where => :instance2,
:execute => 'set',
:css => '.active input[name=subject]',
:value => 'B',
},
# create new text module
{
:where => :instance1,
:execute => 'click',
:css => 'a[href="#admin"]',
},
{
:where => :instance1,
:execute => 'click',
:css => 'a[href="#text_modules"]',
},
{
:where => :instance1,
:execute => 'click',
:css => 'a[data-type="new"]',
},
{
:where => :instance1,
:execute => 'set',
:css => 'input[name=name]',
:value => 'some name' + random,
},
{
:where => :instance1,
:execute => 'set',
:css => 'input[name="keywords"]',
:value => random,
},
{
:where => :instance1,
:execute => 'set',
:css => 'textarea[name="content"]',
:value => 'some content <%= @ticket.customer.lastname %>' + random,
},
{
:where => :instance1,
:execute => 'click',
:css => '.modal button.submit',
},
{
:execute => 'wait',
:value => 3,
},
{
:where => :instance1,
:execute => 'match',
:css => 'body',
:value => random,
:match_result => true,
},
],
},
{
:name => 'check if text module exists in instance2, for ready to use',
:action => [
{
:execute => 'wait',
:value => 3,
},
{
:where => :instance2,
:execute => 'set',
:css => '.active textarea[name=body]',
:value => '::' + random,
},
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'match',
:css => 'body',
:value => random,
:match_result => true,
},
{
:where => :instance2,
:execute => 'click',
:css => '.-sew-list-item.selected',
},
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'match',
:css => '.active textarea[name=body]',
:value => 'some content ' + random,
:match_result => true,
},
{
:execute => 'wait',
:value => 3,
},
{
:where => :instance2,
:execute => 'set',
:css => '.active .ticket_create input[name="customer_id_autocompletion"]',
:value => 'nicole',
},
{
:execute => 'wait',
:value => 4,
},
{
:where => :instance2,
:execute => 'sendkey',
:css => '.active .ticket_create input[name="customer_id_autocompletion"]',
:value => :arrow_down,
},
{
:where => :instance2,
:execute => 'sendkey',
:css => '.active .ticket_create input[name="customer_id_autocompletion"]',
:value => :tab,
},
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'set',
:css => '.active textarea[name=body]',
:value => '::' + random,
},
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.-sew-list-item.selected',
},
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'match',
:css => '.active textarea[name=body]',
:value => 'some content Braun' + random,
:match_result => true,
},
],
},
]
browser_double_test(tests)
end
end end