Improved CTI tests, removed removed potential race condition.

This commit is contained in:
Martin Edenhofer 2018-06-05 10:31:59 +02:00
parent 89a46cf045
commit 9a9e37c1a6
4 changed files with 40 additions and 48 deletions

View file

@ -19,35 +19,10 @@ class App.CTI extends App.Controller
@meta.active = preferences.cti || false @meta.active = preferences.cti || false
@load() @load()
@bind('cti_event', (data) =>
if data.direction is 'in'
if data.state is 'newCall'
if @switch()
@notify(data)
return if @meta.state[data.id]
@meta.state[data.id] = true
@meta.counter += 1
@updateNavMenu()
if data.state is 'answer' || data.state is 'hangup'
if @meta.state[data.id]
delete @meta.state[data.id]
@meta.counter -= 1
@updateNavMenu()
'cti_event'
)
@bind('cti_list_push', (data) => @bind('cti_list_push', (data) =>
if data.assets delay = =>
App.Collection.loadAssets(data.assets) @load()
if data.backends @delay(delay, 500, 'cti_list_push_render')
@backends = data.backends
if data.list
@list = data.list
if @renderDone
@renderCallerLog()
return
@render()
'cti_list_push' 'cti_list_push'
) )
@bind('auth', (data) => @bind('auth', (data) =>
@ -132,7 +107,6 @@ class App.CTI extends App.Controller
@html App.view('cti/index')() @html App.view('cti/index')()
@renderCallerLog() @renderCallerLog()
@updateNavMenu()
renderCallerLog: -> renderCallerLog: ->
format = (time) -> format = (time) ->
@ -181,6 +155,7 @@ class App.CTI extends App.Controller
@userPopupsDestroy() @userPopupsDestroy()
@callerLog.html( App.view('cti/caller_log')(list: @list)) @callerLog.html( App.view('cti/caller_log')(list: @list))
@userPopups() @userPopups()
@updateNavMenu()
done: (e) => done: (e) =>
element = $(e.currentTarget) element = $(e.currentTarget)

View file

@ -28,7 +28,10 @@ class IntegrationCtiTest < TestCase
type: 'on' type: 'on'
) )
watch_for(css: 'a[href="#cti"]') watch_for(
css: 'a[href="#cti"]',
timeout: 4,
)
click(css: 'a[href="#cti"]') click(css: 'a[href="#cti"]')
@ -49,13 +52,15 @@ class IntegrationCtiTest < TestCase
watch_for( watch_for(
css: '.js-phoneMenuItem .counter', css: '.js-phoneMenuItem .counter',
value: (call_counter + 1).to_s value: (call_counter + 1).to_s,
timeout: 4,
) )
click(css: '.content.active .table-checkbox label', all: true) check(css: '.content.active .table-checkbox input')
watch_for_disappear( watch_for_disappear(
css: '.js-phoneMenuItem .counter' css: '.js-phoneMenuItem .counter',
timeout: 6,
) )
click(css: 'a[href="#manage"]') click(css: 'a[href="#manage"]')
@ -123,24 +128,25 @@ class IntegrationCtiTest < TestCase
click(css: 'a[href="#cti"]') click(css: 'a[href="#cti"]')
# assertion: private network numbers appear verbatim # assertion: private network numbers appear verbatim
match( watch_for(
css: '.js-callerLog', css: '.content.active .js-callerLog',
value: '007', value: '007',
timeout: 3,
) )
match( match(
css: '.js-callerLog', css: '.content.active .js-callerLog',
value: '008', value: '008',
) )
# assertion: E164 numbers appear prettified # assertion: E164 numbers appear prettified
match( match(
css: '.js-callerLog', css: '.content.active .js-callerLog',
value: '+49 30 609854180', value: '+49 30 609854180',
) )
match( match(
css: '.js-callerLog', css: '.content.active .js-callerLog',
value: '+49 30 609811111', value: '+49 30 609811111',
) )
end end

View file

@ -22,31 +22,43 @@ class IntegrationSipgateTest < TestCase
) )
watch_for( watch_for(
css: 'a[href="#cti"]' css: 'a[href="#cti"]',
timeout: 4,
) )
click(css: 'a[href="#cti"]') click(css: 'a[href="#cti"]')
# simulate sipgate callbacks call_counter = @browser.find_elements(css: '.js-phoneMenuItem .counter')
.first&.text.to_i
# simulate cti callbacks
url = URI.join(browser_url, 'api/v1/sipgate/in') url = URI.join(browser_url, 'api/v1/sipgate/in')
params = { direction: 'in', from: '491715000002', to: '4930600000000', callId: "4991155921769858278-#{id}", cause: 'busy' } params = {
direction: 'in',
from: '491715000003',
to: '4930600000004',
callId: "4991155921769858279-#{id}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall')) Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup')) Net::HTTP.post_form(url, params.merge(event: 'hangup'))
watch_for( watch_for(
css: '.js-phoneMenuItem .counter', css: '.js-phoneMenuItem .counter',
value: '1' value: (call_counter + 1).to_s,
timeout: 4,
) )
click(css: '.content.active .table-checkbox label') check(css: '.content.active .table-checkbox input')
watch_for_disappear( watch_for_disappear(
css: '.js-phoneMenuItem .counter' css: '.js-phoneMenuItem .counter',
timeout: 6,
) )
click(css: 'a[href="#manage"]') click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]') click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/cti"]') click(css: 'a[href="#system/integration/sipgate"]')
switch( switch(
css: '.content.active .js-switch', css: '.content.active .js-switch',

View file

@ -791,8 +791,7 @@ class TestCase < Test::Unit::TestCase
log('check', params) log('check', params)
instance = params[:browser] || @browser instance = params[:browser] || @browser
instance.execute_script("$('#{params[:css]}:not(:checked)').click()")
instance.execute_script("if (!$('#{params[:css]}').prop('checked')) { $('#{params[:css]}').click() }")
#element = instance.find_elements(css: params[:css])[0] #element = instance.find_elements(css: params[:css])[0]
#checked = element.attribute('checked') #checked = element.attribute('checked')
#element.click if !checked #element.click if !checked
@ -813,7 +812,7 @@ class TestCase < Test::Unit::TestCase
instance = params[:browser] || @browser instance = params[:browser] || @browser
instance.execute_script("if ($('#{params[:css]}').prop('checked')) { $('#{params[:css]}').click() }") instance.execute_script("$('#{params[:css]}:checked').click()")
#element = instance.find_elements(css: params[:css])[0] #element = instance.find_elements(css: params[:css])[0]
#checked = element.attribute('checked') #checked = element.attribute('checked')
#element.click if checked #element.click if checked