Browse Source

Improved CTI tests, removed removed potential race condition.

Martin Edenhofer 6 years ago
parent
commit
9a9e37c1a6

+ 4 - 29
app/assets/javascripts/app/controllers/cti.coffee

@@ -19,35 +19,10 @@ class App.CTI extends App.Controller
     @meta.active = preferences.cti || false
 
     @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) =>
-      if data.assets
-        App.Collection.loadAssets(data.assets)
-      if data.backends
-        @backends = data.backends
-      if data.list
-        @list = data.list
-        if @renderDone
-          @renderCallerLog()
-          return
-        @render()
-
+      delay = =>
+        @load()
+      @delay(delay, 500, 'cti_list_push_render')
       'cti_list_push'
     )
     @bind('auth', (data) =>
@@ -132,7 +107,6 @@ class App.CTI extends App.Controller
 
     @html App.view('cti/index')()
     @renderCallerLog()
-    @updateNavMenu()
 
   renderCallerLog: ->
     format = (time) ->
@@ -181,6 +155,7 @@ class App.CTI extends App.Controller
     @userPopupsDestroy()
     @callerLog.html( App.view('cti/caller_log')(list: @list))
     @userPopups()
+    @updateNavMenu()
 
   done: (e) =>
     element = $(e.currentTarget)

+ 15 - 9
test/browser/integration_cti_test.rb

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

+ 19 - 7
test/browser/integration_sipgate_test.rb

@@ -22,31 +22,43 @@ class IntegrationSipgateTest < TestCase
     )
 
     watch_for(
-      css: 'a[href="#cti"]'
+      css: 'a[href="#cti"]',
+      timeout: 4,
     )
 
     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')
-    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: 'hangup'))
 
     watch_for(
       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(
-      css: '.js-phoneMenuItem .counter'
+      css: '.js-phoneMenuItem .counter',
+      timeout: 6,
     )
 
     click(css: 'a[href="#manage"]')
     click(css: 'a[href="#system/integration"]')
-    click(css: 'a[href="#system/integration/cti"]')
+    click(css: 'a[href="#system/integration/sipgate"]')
 
     switch(
       css: '.content.active .js-switch',

+ 2 - 3
test/browser_test_helper.rb

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