2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-09-04 07:42:50 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
RSpec.describe 'Ticket views', type: :system, authenticated_as: :authenticate do
|
|
|
|
def authenticate
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2020-07-15 11:51:13 +00:00
|
|
|
context 'macros' do
|
2021-12-12 15:45:33 +00:00
|
|
|
let(:group1) { create :group }
|
|
|
|
let(:group2) { create :group }
|
|
|
|
let(:macro_without_group) { create :macro }
|
|
|
|
let(:macro_note) { create :macro, perform: { 'article.note'=>{ 'body' => 'macro body', 'internal' => 'true', 'subject' => 'macro note' } } }
|
|
|
|
let(:macro_group1) { create :macro, groups: [group1] }
|
|
|
|
let(:macro_group2) { create :macro, groups: [group2] }
|
|
|
|
let(:ticket1) { create :ticket, group: group1 }
|
|
|
|
let(:ticket2) { create :ticket, group: group2 }
|
|
|
|
|
|
|
|
describe 'group-dependent macros' do
|
|
|
|
let(:agent) { create(:agent, groups: Group.all) }
|
2020-07-15 11:51:13 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
def authenticate
|
|
|
|
ticket1 && ticket2
|
|
|
|
macro_without_group && macro_group1 && macro_group2
|
|
|
|
agent
|
2020-07-15 11:51:13 +00:00
|
|
|
end
|
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
it 'shows only non-group macro when ticket does not match any group macros' do
|
|
|
|
visit '#ticket/view/all_open'
|
2019-09-04 07:42:50 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
within(:active_content) do
|
|
|
|
display_macro_batches Ticket.first
|
2019-09-04 07:42:50 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_selector(:macro_batch, macro_without_group.id)
|
|
|
|
.and(have_no_selector(:macro_batch, macro_group1.id))
|
|
|
|
.and(have_no_selector(:macro_batch, macro_group2.id))
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 07:42:50 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
it 'shows non-group and matching group macros for matching ticket' do
|
|
|
|
visit '#ticket/view/all_open'
|
2019-09-04 07:42:50 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
within(:active_content) do
|
|
|
|
display_macro_batches ticket1
|
2019-09-04 07:42:50 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_selector(:macro_batch, macro_without_group.id)
|
|
|
|
.and(have_selector(:macro_batch, macro_group1.id))
|
|
|
|
.and(have_no_selector(:macro_batch, macro_group2.id))
|
|
|
|
end
|
2020-07-15 11:51:13 +00:00
|
|
|
end
|
|
|
|
end
|
2020-12-08 09:17:21 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
describe 'macro article creation' do
|
|
|
|
def authenticate
|
|
|
|
macro_note
|
|
|
|
true
|
|
|
|
end
|
2020-12-08 09:17:21 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
it 'can use macro to create article' do
|
|
|
|
visit '#ticket/view/all_open'
|
2020-12-08 09:17:21 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
within(:active_content) do
|
|
|
|
display_macro_batches Ticket.first
|
2020-12-08 09:17:21 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
move_mouse_to find(:macro_batch, macro_note.id)
|
|
|
|
release_mouse
|
2020-12-08 09:17:21 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect do
|
|
|
|
wait.until { Ticket.first.articles.last.subject == 'macro note' }
|
|
|
|
end.not_to raise_error
|
|
|
|
end
|
2020-12-08 09:17:21 +00:00
|
|
|
end
|
|
|
|
end
|
2021-07-01 09:03:41 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
context 'when saving is blocked by one of selected tickets' do
|
|
|
|
let(:ticket) { Ticket.first }
|
|
|
|
let(:core_workflow_action) { { 'ticket.priority_id': { operator: 'remove_option', remove_option: '3' } } }
|
|
|
|
let(:core_workflow) { create(:core_workflow, :active_and_screen, :perform_action) }
|
2021-12-20 13:02:30 +00:00
|
|
|
|
|
|
|
let(:macro_perform) do
|
|
|
|
{
|
|
|
|
'ticket.priority_id': { pre_condition: 'specific', value: 3.to_s }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:macro_priority) { create :macro, perform: macro_perform }
|
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
def authenticate
|
2021-12-20 13:02:30 +00:00
|
|
|
core_workflow && macro_priority && ticket1
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows modal with blocking ticket title' do
|
|
|
|
visit '#ticket/view/all_open'
|
|
|
|
|
|
|
|
within(:active_content) do
|
2021-12-12 15:45:33 +00:00
|
|
|
display_macro_batches ticket
|
2021-12-20 13:02:30 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
move_mouse_to find(:macro_batch, macro_priority.id)
|
2021-12-20 13:02:30 +00:00
|
|
|
release_mouse
|
|
|
|
|
|
|
|
in_modal disappears: false do
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_text(ticket.title)
|
2021-12-20 13:02:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-01 09:03:41 +00:00
|
|
|
context 'with macro batch overlay' do
|
|
|
|
shared_examples "adding 'small' class to macro element" do
|
|
|
|
it 'adds a "small" class to the macro element' do
|
|
|
|
within(:active_content) do
|
2021-12-12 15:45:33 +00:00
|
|
|
display_macro_batches Ticket.first
|
2021-07-01 09:03:41 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_selector('.batch-overlay-macro-entry.small')
|
2021-07-01 09:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "not adding 'small' class to macro element" do
|
|
|
|
it 'does not add a "small" class to the macro element' do
|
|
|
|
within(:active_content) do
|
2021-12-12 15:45:33 +00:00
|
|
|
display_macro_batches Ticket.first
|
2021-07-01 09:03:41 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_no_selector('.batch-overlay-macro-entry.small')
|
2021-07-01 09:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'showing all macros' do
|
|
|
|
it 'shows all macros' do
|
|
|
|
within(:active_content) do
|
2021-12-12 15:45:33 +00:00
|
|
|
display_macro_batches Ticket.first
|
2021-07-01 09:03:41 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_selector('.batch-overlay-macro-entry', count: all)
|
2021-07-01 09:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'showing some macros' do |count|
|
|
|
|
it 'shows all macros' do
|
|
|
|
within(:active_content) do
|
2021-12-12 15:45:33 +00:00
|
|
|
display_macro_batches Ticket.first
|
2021-07-01 09:03:41 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_selector('.batch-overlay-macro-entry', count: count)
|
2021-07-01 09:03:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'show macros batch overlay' do
|
2021-12-12 15:45:33 +00:00
|
|
|
def authenticate
|
2021-07-01 09:03:41 +00:00
|
|
|
Macro.destroy_all && (create_list :macro, all)
|
2021-12-12 15:45:33 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2021-07-01 09:03:41 +00:00
|
|
|
page.current_window.resize_to(width, height)
|
|
|
|
visit '#ticket/view/all_open'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with few macros' do
|
|
|
|
let(:all) { 15 }
|
|
|
|
|
|
|
|
context 'when on large screen' do
|
|
|
|
let(:width) { 1520 }
|
|
|
|
let(:height) { 1040 }
|
|
|
|
|
|
|
|
it_behaves_like 'showing all macros'
|
|
|
|
it_behaves_like "not adding 'small' class to macro element"
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when on small screen' do
|
|
|
|
let(:width) { 1020 }
|
|
|
|
let(:height) { 1040 }
|
|
|
|
|
|
|
|
it_behaves_like 'showing all macros'
|
|
|
|
it_behaves_like "not adding 'small' class to macro element"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with many macros' do
|
|
|
|
let(:all) { 50 }
|
|
|
|
|
|
|
|
context 'when on large screen' do
|
|
|
|
let(:width) { 1520 }
|
|
|
|
let(:height) { 1040 }
|
|
|
|
|
|
|
|
it_behaves_like 'showing some macros', 32
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when on small screen' do
|
|
|
|
let(:width) { 1020 }
|
|
|
|
let(:height) { 1040 }
|
|
|
|
|
|
|
|
it_behaves_like 'showing some macros', 30
|
|
|
|
it_behaves_like "adding 'small' class to macro element"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'show macros batch overlay'
|
|
|
|
end
|
2020-07-15 11:51:13 +00:00
|
|
|
end
|
2019-09-04 07:42:50 +00:00
|
|
|
|
2021-07-26 10:58:42 +00:00
|
|
|
context 'when performing a Bulk action' do
|
|
|
|
context 'when creating a Note', authenticated_as: :user do
|
|
|
|
let(:group) { create :group }
|
|
|
|
let(:user) { create :admin, groups: [group] }
|
2021-12-12 15:45:33 +00:00
|
|
|
let(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) }
|
|
|
|
let(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) }
|
|
|
|
let(:note) { Faker::Lorem.sentence }
|
2021-07-26 10:58:42 +00:00
|
|
|
|
|
|
|
it 'adds note to all selected tickets' do
|
2021-12-12 15:45:33 +00:00
|
|
|
ticket1 && ticket2
|
|
|
|
|
2021-07-26 10:58:42 +00:00
|
|
|
visit 'ticket/view/my_assigned'
|
|
|
|
|
|
|
|
within :active_content do
|
|
|
|
all('.js-checkbox-field', count: 2).each(&:click)
|
|
|
|
click '.js-confirm'
|
|
|
|
find('.js-confirm-step textarea').fill_in with: note
|
|
|
|
click '.js-submit'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect do
|
2021-12-12 15:45:33 +00:00
|
|
|
wait.until { [ ticket1.articles.last&.body, ticket2.articles.last&.body ] == [note, note] }
|
2021-07-26 10:58:42 +00:00
|
|
|
end.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# https://github.com/zammad/zammad/issues/3568
|
|
|
|
# We need a manual ticket creation to test the correct behaviour of the bulk functionality, because of some
|
|
|
|
# leftovers after the creation in the the javascript assets store.
|
|
|
|
context 'when performed a manual Ticket creation', authenticated_as: :agent do
|
|
|
|
let(:customer) { create(:customer) }
|
|
|
|
let(:group) { Group.find_by(name: 'Users') }
|
|
|
|
let(:agent) { create(:agent, groups: [group]) }
|
|
|
|
let!(:template) { create(:template, :dummy_data, group: group, owner: agent, customer: customer) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit 'ticket/create'
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
use_template(template)
|
|
|
|
|
|
|
|
click('.js-submit')
|
|
|
|
|
|
|
|
find('.ticket-article-item')
|
|
|
|
end
|
2020-07-15 11:51:13 +00:00
|
|
|
end
|
|
|
|
|
2021-07-26 10:58:42 +00:00
|
|
|
it 'check that no duplicated article was created after usage of bulk action' do
|
|
|
|
click('.menu-item[href="#ticket/view"]')
|
|
|
|
|
|
|
|
created_ticket_id = Ticket.last.id
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
click("tr[data-id='#{created_ticket_id}'] .js-checkbox-field")
|
|
|
|
|
|
|
|
find('select[name="priority_id"] option[value="1"]').select_option
|
|
|
|
|
|
|
|
click('.js-confirm')
|
|
|
|
click('.js-submit')
|
|
|
|
|
|
|
|
await_empty_ajax_queue
|
|
|
|
|
|
|
|
# Check if still only one article exists on the ticket.
|
|
|
|
click("tr[data-id='#{created_ticket_id}'] a")
|
|
|
|
expect(page).to have_css('.ticket-article-item', count: 1)
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 07:42:50 +00:00
|
|
|
end
|
2021-12-20 13:02:30 +00:00
|
|
|
|
|
|
|
context 'when saving is blocked by one of selected tickets', authenticated_as: :pre_authentication do
|
|
|
|
let(:core_workflow) { create(:core_workflow, :active_and_screen, :perform_action) }
|
|
|
|
let(:ticket1) { create :ticket, group: Group.first }
|
|
|
|
|
|
|
|
def pre_authentication
|
|
|
|
core_workflow && ticket1
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows modal with blocking ticket title' do
|
2021-12-12 15:45:33 +00:00
|
|
|
visit 'ticket/view/all_open'
|
2021-12-20 13:02:30 +00:00
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
find("tr[data-id='#{ticket1.id}']").check('bulk', allow_label_click: true)
|
|
|
|
select '3 high', from: 'priority_id'
|
|
|
|
click '.js-confirm'
|
|
|
|
click '.js-submit'
|
|
|
|
|
|
|
|
in_modal disappears: false do
|
|
|
|
expect(page).to have_text(ticket1.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 07:42:50 +00:00
|
|
|
end
|
2020-12-17 15:03:01 +00:00
|
|
|
|
|
|
|
context 'Setting "ui_table_group_by_show_count"', authenticated_as: :authenticate, db_strategy: :reset do
|
2021-12-12 15:45:33 +00:00
|
|
|
let(:custom_attribute) { create :object_manager_attribute_select, name: 'grouptest' }
|
|
|
|
let(:tickets) do
|
|
|
|
[
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users')),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), grouptest: 'key_1'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), grouptest: 'key_2'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), grouptest: 'key_1')
|
|
|
|
]
|
|
|
|
end
|
2020-12-17 15:03:01 +00:00
|
|
|
|
|
|
|
def authenticate
|
2021-12-12 15:45:33 +00:00
|
|
|
custom_attribute
|
2020-12-17 15:03:01 +00:00
|
|
|
ObjectManager::Attribute.migration_execute
|
2021-12-12 15:45:33 +00:00
|
|
|
tickets
|
|
|
|
Overview.find_by(name: 'Open').update(group_by: custom_attribute.name)
|
2020-12-17 15:03:01 +00:00
|
|
|
Setting.set('ui_table_group_by_show_count', true)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows correct ticket counts' do
|
|
|
|
visit 'ticket/view/all_open'
|
2021-12-12 15:45:33 +00:00
|
|
|
|
2020-12-17 15:03:01 +00:00
|
|
|
within(:active_content) do
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_css('.js-tableBody td b', text: '(1)')
|
|
|
|
.and(have_css('.js-tableBody td b', text: 'value_1 (2)'))
|
|
|
|
.and(have_css('.js-tableBody td b', text: 'value_2 (1)'))
|
2020-12-17 15:03:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 09:59:54 +00:00
|
|
|
|
|
|
|
context 'Customer', authenticated_as: :authenticate do
|
|
|
|
let(:customer) { create(:customer, :with_org) }
|
|
|
|
let(:ticket) { create(:ticket, customer: customer) }
|
|
|
|
|
|
|
|
def authenticate
|
|
|
|
ticket
|
|
|
|
customer
|
|
|
|
end
|
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
it 'shows ticket in my tickets' do
|
|
|
|
visit 'ticket/view/my_tickets'
|
|
|
|
expect(page).to have_text(ticket.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows ticket in my organization tickets' do
|
2021-04-29 09:59:54 +00:00
|
|
|
visit 'ticket/view/my_tickets'
|
|
|
|
click_on 'My Organization Tickets'
|
2021-12-12 15:45:33 +00:00
|
|
|
expect(page).to have_text(ticket.title)
|
2021-04-29 09:59:54 +00:00
|
|
|
end
|
|
|
|
end
|
2021-08-19 07:42:56 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
describe 'Grouping by custom attribute', authenticated_as: :authenticate, db_strategy: :reset do
|
|
|
|
def authenticate
|
|
|
|
custom_attribute
|
|
|
|
ObjectManager::Attribute.migration_execute
|
|
|
|
tickets
|
|
|
|
Overview.find_by(link: 'all_unassigned').update(group_by: custom_attribute.name)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sorted by custom object date' do
|
|
|
|
let(:custom_attribute) { create :object_manager_attribute_date, name: 'cdate' }
|
2021-08-19 07:42:56 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
let(:tickets) do
|
|
|
|
[
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2021-08-18'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2019-01-19'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-01-17'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-08-19')
|
|
|
|
]
|
2021-08-19 07:42:56 +00:00
|
|
|
end
|
|
|
|
|
2021-12-10 10:29:21 +00:00
|
|
|
it 'does show the values grouped and sorted by date key value (yyy-mm-dd) instead of display value' do
|
2021-08-19 07:42:56 +00:00
|
|
|
visit 'ticket/view/all_unassigned'
|
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
headers = all('.js-tableBody td[colspan="6"]').map(&:text)
|
|
|
|
|
|
|
|
expect(headers).to eq ['01/17/2018', '08/19/2018', '01/19/2019', '08/18/2021', '-']
|
2021-08-19 07:42:56 +00:00
|
|
|
end
|
|
|
|
end
|
2021-12-10 10:29:21 +00:00
|
|
|
|
|
|
|
context 'when sorted by custom object select', authenticated_as: :authenticate, db_strategy: :reset do
|
2021-12-12 15:45:33 +00:00
|
|
|
let(:custom_attribute) do
|
|
|
|
create :object_manager_attribute_select,
|
|
|
|
name: 'cselect',
|
|
|
|
data_option_options: {
|
|
|
|
'a' => 'Zzz a',
|
|
|
|
'b' => 'Yyy b',
|
|
|
|
'c' => 'Xxx c',
|
|
|
|
}
|
|
|
|
end
|
2021-12-10 10:29:21 +00:00
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
let(:tickets) do
|
|
|
|
[
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cselect: 'a'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cselect: 'b'),
|
|
|
|
create(:ticket, group: Group.find_by(name: 'Users'), cselect: 'c')
|
|
|
|
]
|
2021-12-10 10:29:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does show the values grouped and sorted by display value instead of key value' do
|
|
|
|
visit 'ticket/view/all_unassigned'
|
|
|
|
|
2021-12-12 15:45:33 +00:00
|
|
|
headers = all('.js-tableBody td[colspan="6"]').map(&:text)
|
|
|
|
|
|
|
|
expect(headers).to eq ['-', 'Xxx c', 'Yyy b', 'Zzz a']
|
2021-12-10 10:29:21 +00:00
|
|
|
end
|
|
|
|
end
|
2021-08-19 07:42:56 +00:00
|
|
|
end
|
2019-09-04 07:42:50 +00:00
|
|
|
end
|