Maintenance: Port old cti integration tests to capybara.

This commit is contained in:
Bola Ahmed Buari 2021-10-12 16:16:59 +02:00 committed by Thorsten Eckel
parent d7cdb308dd
commit e6c3b07b0d
5 changed files with 294 additions and 412 deletions

View file

@ -48,8 +48,6 @@ if [ "$LEVEL" == '1' ]; then
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
rm test/browser/keyboard_shortcuts_test.rb rm test/browser/keyboard_shortcuts_test.rb
# test/browser/manage_test.rb # test/browser/manage_test.rb
rm test/browser/integration_sipgate_test.rb
rm test/browser/integration_cti_test.rb
# test/browser/swich_to_user_test.rb # test/browser/swich_to_user_test.rb
# test/browser/taskbar_session_test.rb # test/browser/taskbar_session_test.rb
# test/browser/taskbar_task_test.rb # test/browser/taskbar_task_test.rb
@ -99,8 +97,6 @@ elif [ "$LEVEL" == '2' ]; then
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
rm test/browser/keyboard_shortcuts_test.rb rm test/browser/keyboard_shortcuts_test.rb
rm test/browser/manage_test.rb rm test/browser/manage_test.rb
rm test/browser/integration_sipgate_test.rb
rm test/browser/integration_cti_test.rb
rm test/browser/switch_to_user_test.rb rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb rm test/browser/taskbar_task_test.rb
@ -150,8 +146,6 @@ elif [ "$LEVEL" == '3' ]; then
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
rm test/browser/keyboard_shortcuts_test.rb rm test/browser/keyboard_shortcuts_test.rb
rm test/browser/manage_test.rb rm test/browser/manage_test.rb
rm test/browser/integration_sipgate_test.rb
rm test/browser/integration_cti_test.rb
rm test/browser/switch_to_user_test.rb rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb rm test/browser/taskbar_task_test.rb
@ -201,8 +195,6 @@ elif [ "$LEVEL" == '4' ]; then
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
rm test/browser/keyboard_shortcuts_test.rb rm test/browser/keyboard_shortcuts_test.rb
rm test/browser/manage_test.rb rm test/browser/manage_test.rb
rm test/browser/integration_sipgate_test.rb
rm test/browser/integration_cti_test.rb
rm test/browser/switch_to_user_test.rb rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb rm test/browser/taskbar_task_test.rb
@ -251,8 +243,6 @@ elif [ "$LEVEL" == '5' ]; then
rm test/browser/integration_test.rb rm test/browser/integration_test.rb
rm test/browser/keyboard_shortcuts_test.rb rm test/browser/keyboard_shortcuts_test.rb
rm test/browser/manage_test.rb rm test/browser/manage_test.rb
rm test/browser/integration_sipgate_test.rb
rm test/browser/integration_cti_test.rb
rm test/browser/switch_to_user_test.rb rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb rm test/browser/taskbar_task_test.rb
@ -304,8 +294,6 @@ elif [ "$LEVEL" == '6' ]; then
# test/browser/integration_test.rb # test/browser/integration_test.rb
# test/browser/keyboard_shortcuts_test.rb # test/browser/keyboard_shortcuts_test.rb
rm test/browser/manage_test.rb rm test/browser/manage_test.rb
# rm test/browser/integration_sipgate_test.rb
# rm test/browser/integration_cti_test.rb
rm test/browser/switch_to_user_test.rb rm test/browser/switch_to_user_test.rb
rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_session_test.rb
rm test/browser/taskbar_task_test.rb rm test/browser/taskbar_task_test.rb

View file

@ -2,62 +2,234 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe 'Caller log', type: %i[system request] do RSpec.describe 'Caller log', type: :system, authenticated_as: :agent do
let(:admin) do let(:agent_phone) { '0190111' }
create(:admin, groups: Group.all) let(:customer_phone) { '0190333' }
end let(:cti_token) { 'token1234' }
let(:agent) { create(:agent, phone: agent_phone) }
let!(:customer) { create(:customer, phone: '0190333') } let(:customer) { create(:customer, phone: customer_phone) }
let(:cti_on) { true }
let(:params) do let(:params) do
{ {
direction: 'in', direction: 'in',
from: '0190333', from: customer.phone,
to: '0190111', to: agent_phone,
callId: '111', callId: '111',
cause: 'busy' cause: 'busy',
} }
end end
def prepare let(:first_params) { params.merge(event: 'newCall') }
Setting.set('cti_integration', true) let(:second_params) { params.merge(event: 'hangup') }
Setting.set('cti_token', 'token1234')
current_user.update(phone: '0190111') let(:place_call) do
post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: first_params
post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: second_params
end end
context 'without active tickets' do let(:prepare) do
it 'checks opening of the ticket creation screen after phone call inbound' do Setting.set('cti_integration', cti_on)
prepare Setting.set('cti_token', cti_token)
end
before { prepare }
context 'when cti integration is on' do
it 'shows the phone menu in nav bar' do
within '#navigation .menu' do
expect(page).to have_link('Phone', href: '#cti')
end
end
end
context 'when cti integration is not on' do
let(:cti_on) { false }
it 'does not show the phone menu in nav bar' do
within '#navigation .menu' do
expect(page).to have_no_link('Phone', href: '#cti')
end
end
end
context 'when a customer call is answered' do
let(:second_params) { params.merge(event: 'answer', answeringNumber: agent_phone) }
context 'without active tickets' do
before do
travel(-2.months) travel(-2.months)
create(:ticket, customer: customer) create(:ticket, customer: customer)
travel_back travel_back
visit 'cti' visit 'cti'
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'newCall'), as: :json place_call
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'answer', answeringNumber: '0190111'), as: :json end
it 'opens a new ticket after phone call inbound' do
within(:active_content) do within(:active_content) do
expect(page).to have_text('New Ticket', wait: 5) expect(page).to have_text('New Ticket')
end end
end end
end end
context 'with active tickets' do context 'with active tickets' do
it 'checks opening of the user profile screen after phone call inbound with tickets in the last month' do before do
prepare
create(:ticket, customer: customer) create(:ticket, customer: customer)
visit 'cti' visit 'cti'
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'newCall'), as: :json place_call
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'answer', answeringNumber: '0190111'), as: :json end
it 'opens the customer profile screen after phone call inbound with tickets in the last month' do
within(:active_content) do within(:active_content) do
expect(page).to have_text(customer.fullname, wait: 5) expect(page).to have_text(customer.fullname)
end end
end end
end end
end end
context 'with incoming call' do
before do
visit 'cti'
place_call
end
it 'increments the call counter notification badge' do
within '[href="#cti"].js-phoneMenuItem' do
counter = find('.counter')
expect(counter).to have_content 1
end
end
end
context 'when incoming call is checked' do
before do
visit 'cti'
place_call
end
it 'clears the call counter notification badge' do
within :active_content do
find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
end
within '[href="#cti"].js-phoneMenuItem' do
expect(page).to have_no_selector('.counter')
end
end
end
# Regression test for #2018
context 'phone numbers format' do
before do
visit 'cti'
place_call
end
context 'with private number' do
let(:customer_phone) { '007' }
let(:agent_phone) { '008' }
it 'appears verbatim' do
within :active_content do
expect(page).to have_selector('.js-callerLog', text: customer_phone)
.and have_selector('.js-callerLog', text: agent_phone)
end
end
end
context 'with e164 number' do
let(:customer_phone) { '4930609854180' }
let(:agent_phone) { '4930609811111' }
let(:prettified_customer_phone) { '+49 30 609854180' }
let(:prettified_current_user_phone) { '+49 30 609811111' }
it 'appears prettified' do
within :active_content do
expect(page).to have_selector('.js-callerLog', text: prettified_customer_phone)
.and have_selector('.js-callerLog', text: prettified_current_user_phone)
end
end
it 'done not appear verbatim' do
within :active_content do
expect(page).to have_no_selector('.js-callerLog', text: customer_phone)
end
end
end
end
# Regression test for #2096
context 'with inactive user' do
before do
visit 'cti'
place_call
end
let(:customer) do
create(:customer,
phone: customer_phone,
active: false,
firstname: 'John',
lastname: 'Doe')
end
it 'appears inactive' do
within :active_content do
expect(page).to have_selector('span.avatar--inactive', text: 'JD')
end
end
end
# Regression test for #2075
context 'when user is with organization name' do
before do
visit 'cti'
place_call
end
let(:firstname) { 'John' }
let(:lastname) { 'Doe' }
let(:organization_name) { 'Test Organization' }
let(:organization) { create(:organization, name: organization_name) }
let(:full_name) { "#{firstname} #{lastname}" }
let(:customer) do
create(:customer,
phone: customer_phone,
firstname: firstname,
lastname: lastname,
organization: organization)
end
shared_examples 'showing user with thier organization name' do
it 'shows user with thier organization name' do
within :active_content do
expect(page).to have_selector(
'.js-callerLog tr div.user-popover',
text: "#{full_name} (#{organization_name})"
)
end
end
end
context 'with call direction out' do
let(:first_params) { params.merge(event: 'newCall', direction: 'out', from: agent_phone, to: customer.phone) }
let(:second_params) { params.merge(event: 'hangup', direction: 'out', from: agent_phone, to: customer.phone) }
it_behaves_like 'showing user with thier organization name'
end
context 'with call direction in' do
let(:first_params) { params.merge(event: 'newCall', direction: 'in') }
let(:second_params) { params.merge(event: 'hangup', direction: 'in') }
it_behaves_like 'showing user with thier organization name'
end
end
end

View file

@ -0,0 +1,86 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
RSpec.describe 'Caller log', type: :system, authenticated_as: :agent do
let(:agent_phone) { '0190111' }
let(:customer_phone) { '0190333' }
let(:agent) { create(:agent, phone: agent_phone) }
let(:customer) { create(:customer, phone: customer_phone) }
let(:sipgate_on) { true }
let(:params) do
{
direction: 'in',
from: customer.phone,
to: agent_phone,
callId: '111',
cause: 'busy',
}
end
let(:first_params) { params.merge(event: 'newCall') }
let(:second_params) { params.merge(event: 'hangup') }
let(:place_call) do
post "#{Capybara.app_host}/api/v1/sipgate/in", params: first_params
post "#{Capybara.app_host}/api/v1/sipgate/in", params: second_params
end
let(:prepare) do
Setting.set('sipgate_integration', sipgate_on)
end
before { prepare }
context 'when sipgate integration is on' do
it 'shows the phone menu in nav bar' do
within '#navigation .menu' do
expect(page).to have_link('Phone', href: '#cti')
end
end
end
context 'when sipgate integration is not on' do
let(:sipgate_on) { false }
it 'does not show the phone menu in nav bar' do
within '#navigation .menu' do
expect(page).to have_no_link('Phone', href: '#cti')
end
end
end
context 'with incoming call' do
before do
visit 'cti'
place_call
end
it 'increments the call counter notification badge' do
within '[href="#cti"].js-phoneMenuItem' do
counter = find('.counter')
expect(counter).to have_content 1
end
end
end
context 'when incoming call is checked' do
before do
visit 'cti'
place_call
end
it 'clears the call counter notification badge' do
within :active_content do
find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
end
within '[href="#cti"].js-phoneMenuItem' do
expect(page).to have_no_selector('.counter')
end
end
end
end

View file

@ -1,293 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'browser_test_helper'
class IntegrationCtiTest < TestCase
setup do
if !ENV['CTI_TOKEN']
raise "ERROR: Need CTI_TOKEN - hint CTI_TOKEN='some_token'"
end
end
# Regression test for #2017
def test_nav_menu_notification_badge_clears
id = SecureRandom.uuid
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/cti"]')
switch(
css: '.content.active .js-switch',
type: 'on'
)
watch_for(
css: 'a[href="#cti"]',
timeout: 4,
)
click(css: 'a[href="#cti"]')
call_counter = @browser.find_elements(css: '.js-phoneMenuItem .counter')
.first&.text.to_i
# simulate cti callbacks
url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
params = {
direction: 'in',
from: '491715000002',
to: '4930600000000',
callId: "4991155921769858278-#{id}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup'))
# flanky
watch_for(
css: '.js-phoneMenuItem .counter',
value: (call_counter + 1).to_s,
timeout: 4,
)
check(css: '.content.active .table-checkbox input')
watch_for_disappear(
css: '.js-phoneMenuItem .counter',
timeout: 15,
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/cti"]')
switch(
css: '.content.active .js-switch',
type: 'off'
)
end
# Regression test for #2018
def test_e164_numbers_displayed_in_prettified_format
id = SecureRandom.uuid
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/cti"]')
switch(
css: '.content.active .js-switch',
type: 'on'
)
watch_for(
css: 'a[href="#cti"]'
)
click(css: 'a[href="#cti"]')
# simulate cti callbacks...
url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
# ...for private network number
params = {
direction: 'in',
from: '007',
to: '008',
callId: "4991155921769858278-#{id}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup'))
# ...for e164 number
params = {
direction: 'in',
from: '4930609854180',
to: '4930609811111',
callId: "4991155921769858278-#{id.next}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup'))
# view caller log
click(css: 'a[href="#cti"]')
# assertion: private network numbers appear verbatim
watch_for(
css: '.content.active .js-callerLog',
value: '007',
timeout: 3,
)
match(
css: '.content.active .js-callerLog',
value: '008',
)
# assertion: E164 numbers appear prettified
match(
css: '.content.active .js-callerLog',
value: '+49 30 609854180',
)
match(
css: '.content.active .js-callerLog',
value: '+49 30 609811111',
)
end
# Regression test for #2096
def test_inactive_users_displayed_inactive_in_caller_log
id = SecureRandom.uuid
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
# create inactive user with phone number (via API)
user_create(
data: {
login: 'test_user',
firstname: 'John',
lastname: 'Doe',
phone: '1234567890',
active: false,
},
)
# enable CTI
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/cti"]')
switch(
css: '.content.active .js-switch',
type: 'on'
)
watch_for(
css: 'a[href="#cti"]'
)
click(css: 'a[href="#cti"]')
# simulate CTI callback to/from inactive user
url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
params = {
direction: 'in',
from: '1234567890',
to: '1234567890',
callId: "4991155921769858278-#{id}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup'))
# view caller log
click(css: 'a[href="#cti"]')
# assertion: names appear in inactive
match(
css: 'span.avatar--inactive',
value: 'JD',
)
end
# Regression test for #2075
def test_caller_ids_include_organization_names
id = SecureRandom.uuid
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
# create user with organization (via API)
user_create(
data: {
login: 'test_user',
firstname: 'John',
lastname: 'Doe',
phone: '1234567890',
organization: 'Zammad Foundation'
},
)
# enable CTI
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/cti"]')
switch(
css: '.content.active .js-switch',
type: 'on'
)
watch_for(
css: 'a[href="#cti"]'
)
# view caller log
click(css: 'a[href="#cti"]')
# simulate CTI callbacks to/from target user
url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
params = {
direction: 'out',
from: '1234567890',
to: '1234567890',
callId: "4991155921769858278-#{id}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup'))
params = {
direction: 'in',
from: '1234567890',
to: '1234567890',
callId: "4991155921769858278-#{id.next}",
cause: 'busy'
}
Net::HTTP.post_form(url, params.merge(event: 'newCall'))
Net::HTTP.post_form(url, params.merge(event: 'hangup'))
watch_for(
css: '.js-callerLog tr:nth-of-type(2)'
)
# assertions: Caller ID includes user organization
match(
css: '.js-callerLog tr:first-of-type div.user-popover',
value: 'John Doe (Zammad Foundation)',
)
match(
css: '.js-callerLog tr:last-of-type div.user-popover',
value: 'John Doe (Zammad Foundation)',
)
end
end

View file

@ -1,71 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'browser_test_helper'
class IntegrationSipgateTest < TestCase
# Regression test for #2017
def test_nav_menu_notification_badge_clears
id = SecureRandom.uuid
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/sipgate"]')
switch(
css: '.content.active .js-switch',
type: 'on'
)
watch_for(
css: 'a[href="#cti"]',
timeout: 4,
)
click(css: 'a[href="#cti"]')
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: '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'))
# flanky
watch_for(
css: '.js-phoneMenuItem .counter',
value: (call_counter + 1).to_s,
timeout: 4,
)
check(css: '.content.active .table-checkbox input')
watch_for_disappear(
css: '.js-phoneMenuItem .counter',
timeout: 6,
)
click(css: 'a[href="#manage"]')
click(css: 'a[href="#system/integration"]')
click(css: 'a[href="#system/integration/sipgate"]')
switch(
css: '.content.active .js-switch',
type: 'off'
)
end
end