Maintenance: ticket/zoom_spec improvements

This commit is contained in:
Mantas 2020-08-07 17:48:09 +03:00 committed by Thorsten Eckel
parent e5ffb9e840
commit 2d861508f4

View file

@ -2,19 +2,20 @@ require 'rails_helper'
RSpec.describe 'Ticket zoom', type: :system do RSpec.describe 'Ticket zoom', type: :system do
describe 'owner auto-assignment' do describe 'owner auto-assignment', authenticated_as: :authenticate do
let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), state: Ticket::State.find_by(name: 'new')) } let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), state: Ticket::State.find_by(name: 'new')) }
let!(:session_user) { User.find_by(login: 'master@example.com') } let!(:session_user) { User.find_by(login: 'master@example.com') }
context 'for agent disabled' do context 'for agent disabled' do
before do def authenticate
Setting.set('ticket_auto_assignment', false) Setting.set('ticket_auto_assignment', false)
Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } }) Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
Setting.set('ticket_auto_assignment_user_ids_ignore', []) Setting.set('ticket_auto_assignment_user_ids_ignore', [])
true
end end
it 'do not assign ticket to current session user' do it 'do not assign ticket to current session user' do
refresh
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -27,14 +28,16 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'for agent enabled' do context 'for agent enabled' do
before do def authenticate
Setting.set('ticket_auto_assignment', true) Setting.set('ticket_auto_assignment', true)
Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } }) Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
Setting.set('ticket_auto_assignment_user_ids_ignore', setting_user_ids_ignore) if defined?(setting_user_ids_ignore)
true
end end
context 'with empty "ticket_auto_assignment_user_ids_ignore"' do context 'with empty "ticket_auto_assignment_user_ids_ignore"' do
it 'assigns ticket to current session user' do it 'assigns ticket to current session user' do
refresh
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -47,10 +50,9 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with "ticket_auto_assignment_user_ids_ignore" (as integer)' do context 'with "ticket_auto_assignment_user_ids_ignore" (as integer)' do
it 'assigns ticket not to current session user' do let(:setting_user_ids_ignore) { session_user.id }
Setting.set('ticket_auto_assignment_user_ids_ignore', session_user.id)
refresh it 'assigns ticket not to current session user' do
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -63,10 +65,9 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with "ticket_auto_assignment_user_ids_ignore" (as string)' do context 'with "ticket_auto_assignment_user_ids_ignore" (as string)' do
it 'assigns ticket not to current session user' do let(:setting_user_ids_ignore) { session_user.id.to_s }
Setting.set('ticket_auto_assignment_user_ids_ignore', session_user.id.to_s)
refresh it 'assigns ticket not to current session user' do
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -79,10 +80,9 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with "ticket_auto_assignment_user_ids_ignore" (as [integer])' do context 'with "ticket_auto_assignment_user_ids_ignore" (as [integer])' do
it 'assigns ticket not to current session user' do let(:setting_user_ids_ignore) { [session_user.id] }
Setting.set('ticket_auto_assignment_user_ids_ignore', [session_user.id])
refresh it 'assigns ticket not to current session user' do
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -95,10 +95,9 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with "ticket_auto_assignment_user_ids_ignore" (as [string])' do context 'with "ticket_auto_assignment_user_ids_ignore" (as [string])' do
it 'assigns ticket not to current session user' do let(:setting_user_ids_ignore) { [session_user.id.to_s] }
Setting.set('ticket_auto_assignment_user_ids_ignore', [session_user.id.to_s])
refresh it 'assigns ticket not to current session user' do
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -111,10 +110,9 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with "ticket_auto_assignment_user_ids_ignore" and other user ids' do context 'with "ticket_auto_assignment_user_ids_ignore" and other user ids' do
it 'assigns ticket to current session user' do let(:setting_user_ids_ignore) { [99_999, 999_999] }
Setting.set('ticket_auto_assignment_user_ids_ignore', [99_999, 999_999])
refresh it 'assigns ticket to current session user' do
visit "#ticket/zoom/#{ticket.id}" visit "#ticket/zoom/#{ticket.id}"
within(:active_content) do within(:active_content) do
@ -207,14 +205,20 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
end end
describe 'delete article', authenticated_as: :user do describe 'delete article', authenticated_as: :authenticate do
let(:admin) { create :admin, groups: [Group.first] } let(:group) { Group.first }
let(:agent) { create :agent, groups: [Group.first] } let(:admin) { create :admin, groups: [group] }
let(:other_agent) { create :agent, groups: [Group.first] } let(:agent) { create :agent, groups: [group] }
let(:other_agent) { create :agent, groups: [group] }
let(:customer) { create :customer } let(:customer) { create :customer }
let(:ticket) { create :ticket, group: agent.groups.first, customer: customer }
let(:article) { send(item) } let(:article) { send(item) }
def authenticate
Setting.set('ui_ticket_zoom_article_delete_timeframe', setting_delete_timeframe) if defined?(setting_delete_timeframe)
article
user
end
def article_communication def article_communication
create_ticket_article(sender_name: 'Agent', internal: false, type_name: 'email', updated_by: customer) create_ticket_article(sender_name: 'Agent', internal: false, type_name: 'email', updated_by: customer)
end end
@ -244,10 +248,13 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
def create_ticket_article(sender_name:, internal:, type_name:, updated_by:) def create_ticket_article(sender_name:, internal:, type_name:, updated_by:)
UserInfo.current_user_id = updated_by.id
ticket = create :ticket, group: group, customer: customer
create(:ticket_article, create(:ticket_article,
sender_name: sender_name, internal: internal, type_name: type_name, ticket: ticket, sender_name: sender_name, internal: internal, type_name: type_name, ticket: ticket,
body: "to be deleted #{offset} #{item}", body: "to be deleted #{offset} #{item}",
updated_by_id: updated_by.id, created_by_id: updated_by.id,
created_at: offset.ago, updated_at: offset.ago) created_at: offset.ago, updated_at: offset.ago)
end end
@ -258,13 +265,11 @@ RSpec.describe 'Ticket zoom', type: :system do
let(:offset) { 0.minutes } let(:offset) { 0.minutes }
it 'succeeds' do it 'succeeds' do
refresh # make sure user roles are loaded
ensure_websocket do ensure_websocket do
visit "ticket/zoom/#{ticket.id}" visit "ticket/zoom/#{article.ticket.id}"
end end
within :active_ticket_article, article, wait: 15 do within :active_ticket_article, article do
click '.js-ArticleAction[data-type=delete]' click '.js-ArticleAction[data-type=delete]'
end end
@ -280,18 +285,14 @@ RSpec.describe 'Ticket zoom', type: :system do
context 'verifying permissions matrix' do context 'verifying permissions matrix' do
shared_examples 'according to permission matrix' do |item:, expects_visible:, offset:, description:| shared_examples 'according to permission matrix' do |item:, expects_visible:, offset:, description:|
context "looking at #{description} #{item}" do context "looking at #{description} #{item}" do
let(:item) { item } let(:item) { item }
let!(:article) { send(item) } let(:offset) { offset }
let(:offset) { offset }
let(:matcher) { expects_visible ? :have_css : :have_no_css } let(:matcher) { expects_visible ? :have_css : :have_no_css }
it expects_visible ? 'delete button is visible' : 'delete button is not visible' do it expects_visible ? 'delete button is visible' : 'delete button is not visible' do
refresh # make sure user roles are loaded visit "ticket/zoom/#{article.ticket.id}"
visit "ticket/zoom/#{ticket.id}" within :active_ticket_article, article do
within :active_ticket_article, article, wait: 15 do
expect(page).to send(matcher, '.js-ArticleAction[data-type=delete]', wait: 0) expect(page).to send(matcher, '.js-ArticleAction[data-type=delete]', wait: 0)
end end
end end
@ -374,7 +375,7 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with custom offset' do context 'with custom offset' do
before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 6000 } let(:setting_delete_timeframe) { 6_000 }
context 'as admin' do context 'as admin' do
let(:user) { admin } let(:user) { admin }
@ -392,7 +393,7 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'with timeframe as 0' do context 'with timeframe as 0' do
before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 0 } let(:setting_delete_timeframe) { 0 }
context 'as agent' do context 'as agent' do
let(:user) { agent } let(:user) { agent }
@ -403,7 +404,7 @@ RSpec.describe 'Ticket zoom', type: :system do
end end
context 'button is hidden on the go' do context 'button is hidden on the go' do
before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 5 } let(:setting_delete_timeframe) { 5 }
let(:user) { agent } let(:user) { agent }
let(:item) { 'article_note_self' } let(:item) { 'article_note_self' }
@ -411,13 +412,11 @@ RSpec.describe 'Ticket zoom', type: :system do
let(:offset) { 0.seconds } let(:offset) { 0.seconds }
it 'successfully' do it 'successfully' do
refresh # make sure user roles are loaded visit "ticket/zoom/#{article.ticket.id}"
visit "ticket/zoom/#{ticket.id}"
within :active_ticket_article, article do within :active_ticket_article, article do
find '.js-ArticleAction[data-type=delete]' # make sure delete button did show up find '.js-ArticleAction[data-type=delete]' # make sure delete button did show up
expect(page).to have_no_css('.js-ArticleAction[data-type=delete]', wait: 15) expect(page).to have_no_css('.js-ArticleAction[data-type=delete]')
end end
end end
end end