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-01-04 14:26:43 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2019-09-02 13:28:39 +00:00
|
|
|
require 'system/examples/text_modules_examples'
|
2019-09-04 07:42:50 +00:00
|
|
|
require 'system/examples/macros_examples'
|
2019-07-03 16:14:28 +00:00
|
|
|
|
2019-02-13 09:09:20 +00:00
|
|
|
RSpec.describe 'Ticket Update', type: :system do
|
2019-01-04 14:26:43 +00:00
|
|
|
|
|
|
|
let(:group) { Group.find_by(name: 'Users') }
|
2019-11-26 10:40:23 +00:00
|
|
|
let(:ticket) { create(:ticket, group: group) }
|
2019-01-04 14:26:43 +00:00
|
|
|
|
|
|
|
# Regression test for issue #2242 - mandatory fields can be empty (or "-") on ticket update
|
|
|
|
context 'when updating a ticket without its required select attributes' do
|
2019-04-15 01:41:17 +00:00
|
|
|
it 'frontend checks reject the update', db_strategy: :reset do
|
2019-01-04 14:26:43 +00:00
|
|
|
# setup and migrate a required select attribute
|
2019-11-26 10:40:23 +00:00
|
|
|
attribute = create_attribute(:object_manager_attribute_select,
|
2019-02-27 13:02:16 +00:00
|
|
|
screens: attributes_for(:required_screen),
|
|
|
|
data_option: {
|
|
|
|
options: {
|
|
|
|
'name 1': 'name 1',
|
|
|
|
'name 2': 'name 2',
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
null: false,
|
|
|
|
relation: '',
|
|
|
|
maxlength: 255,
|
|
|
|
nulloption: true,
|
2019-11-26 10:40:23 +00:00
|
|
|
})
|
2019-01-04 14:26:43 +00:00
|
|
|
|
|
|
|
# create a new ticket and attempt to update its state without the required select attribute
|
|
|
|
visit "#ticket/zoom/#{ticket.id}"
|
2019-02-27 13:02:16 +00:00
|
|
|
within(:active_content) do
|
2019-11-26 10:40:23 +00:00
|
|
|
expect(page).to have_selector('.js-objectNumber', text: ticket.number)
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2019-11-26 10:40:23 +00:00
|
|
|
select('closed', from: 'state_id')
|
2019-02-27 13:02:16 +00:00
|
|
|
click('.js-attributeBar .js-submit')
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
|
2019-02-27 13:02:16 +00:00
|
|
|
end
|
2019-01-04 14:26:43 +00:00
|
|
|
|
|
|
|
# the update should have failed and thus the ticket is still in the new state
|
|
|
|
expect(ticket.reload.state.name).to eq('new')
|
2019-02-27 13:02:16 +00:00
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
# update should work now
|
2019-09-16 10:34:26 +00:00
|
|
|
find(".edit [name=#{attribute.name}]").select('name 2')
|
2019-02-27 13:02:16 +00:00
|
|
|
click('.js-attributeBar .js-submit')
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
|
2019-02-27 13:02:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ticket.reload
|
|
|
|
expect(ticket[attribute.name]).to eq('name 2')
|
|
|
|
expect(ticket.state.name).to eq('closed')
|
|
|
|
end
|
2019-11-26 10:40:23 +00:00
|
|
|
end
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2021-09-27 10:49:55 +00:00
|
|
|
context 'when updating a ticket date attribute', db_strategy: :reset do
|
|
|
|
let!(:date_attribute) do
|
|
|
|
create_attribute(
|
|
|
|
:object_manager_attribute_date,
|
|
|
|
name: 'example_date',
|
|
|
|
screens: {
|
|
|
|
create: {
|
|
|
|
'ticket.agent' => {
|
|
|
|
shown: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
'ticket.agent' => {
|
|
|
|
shown: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
view: {
|
|
|
|
'ticket.agent' => {
|
|
|
|
shown: true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data_option: {
|
|
|
|
'future' => true,
|
|
|
|
'past' => false,
|
|
|
|
'diff' => 0,
|
|
|
|
'null' => true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:ticket) { create(:ticket, group: group, "#{date_attribute.name}": '2018-02-28') }
|
|
|
|
|
|
|
|
it 'set date attribute to empty' do
|
|
|
|
visit "#ticket/zoom/#{ticket.id}"
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
check_date_field_value(date_attribute.name, '02/28/2018')
|
|
|
|
|
|
|
|
set_date_field_value(date_attribute.name, '')
|
|
|
|
|
|
|
|
click('.js-attributeBar .js-submit')
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
|
2021-09-27 10:49:55 +00:00
|
|
|
|
|
|
|
ticket.reload
|
2022-03-01 08:00:40 +00:00
|
|
|
expect(ticket[date_attribute.name]).to be_nil
|
2021-09-27 10:49:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-26 10:40:23 +00:00
|
|
|
context 'when updating a ticket with macro' do
|
|
|
|
context 'when required tree_select field is present' do
|
|
|
|
it 'performs no validation (#2492)', db_strategy: :reset do
|
|
|
|
# setup and migrate a required select attribute
|
|
|
|
attribute = create_attribute(:object_manager_attribute_tree_select,
|
|
|
|
screens: attributes_for(:required_screen),
|
|
|
|
data_option: {
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'name 1',
|
|
|
|
value: 'name 1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'name 2',
|
|
|
|
value: 'name 2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: '',
|
|
|
|
null: false,
|
|
|
|
relation: '',
|
|
|
|
maxlength: 255,
|
|
|
|
nulloption: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
attribute_value = 'name 2'
|
|
|
|
state = Ticket::State.by_category(:closed).first
|
|
|
|
macro = create(:macro,
|
|
|
|
perform: {
|
|
|
|
'ticket.state_id' => {
|
|
|
|
value: state.id,
|
|
|
|
},
|
|
|
|
"ticket.#{attribute.name}" => {
|
|
|
|
value: attribute_value,
|
|
|
|
},
|
2019-02-27 13:02:16 +00:00
|
|
|
},
|
2019-11-26 10:40:23 +00:00
|
|
|
ux_flow_next_up: 'none',)
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2019-11-26 10:40:23 +00:00
|
|
|
# refresh browser to get macro accessible
|
|
|
|
refresh
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2019-11-26 10:40:23 +00:00
|
|
|
# create a new ticket and attempt to update its state without the required select attribute
|
|
|
|
visit "#ticket/zoom/#{ticket.id}"
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2019-11-26 10:40:23 +00:00
|
|
|
within(:active_content) do
|
|
|
|
expect(page).to have_selector('.js-objectNumber', text: ticket.number)
|
|
|
|
|
2020-05-11 12:49:22 +00:00
|
|
|
expect(page).to have_field(attribute.name, with: '', visible: :hidden)
|
2019-11-26 10:40:23 +00:00
|
|
|
expect(page).to have_select('state_id',
|
|
|
|
selected: 'new',
|
|
|
|
options: ['new', 'closed', 'open', 'pending close', 'pending reminder'])
|
|
|
|
|
|
|
|
click('.js-openDropdownMacro')
|
|
|
|
click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
|
2020-08-26 12:31:33 +00:00
|
|
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
|
2019-11-26 10:40:23 +00:00
|
|
|
end
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2020-05-11 12:49:22 +00:00
|
|
|
expect(page).to have_field(attribute.name, with: attribute_value, visible: :hidden)
|
2019-11-26 10:40:23 +00:00
|
|
|
expect(page).to have_select('state_id',
|
|
|
|
selected: 'closed',
|
|
|
|
options: ['closed', 'open', 'pending close', 'pending reminder'])
|
|
|
|
|
|
|
|
# the update should not have failed and thus the ticket is in closed state
|
|
|
|
ticket.reload
|
|
|
|
expect(ticket[attribute.name]).to eq(attribute_value)
|
|
|
|
expect(ticket.state.name).to eq(state.name)
|
2019-02-27 13:02:16 +00:00
|
|
|
end
|
2019-11-26 10:40:23 +00:00
|
|
|
end
|
2019-02-27 13:02:16 +00:00
|
|
|
|
2019-11-26 10:40:23 +00:00
|
|
|
context 'when macro has article configured' do
|
|
|
|
it 'creates an article with the configured attributes' do
|
|
|
|
state = Ticket::State.find_by(name: 'closed')
|
|
|
|
macro = create(:macro,
|
|
|
|
perform: {
|
|
|
|
'ticket.state_id' => {
|
|
|
|
value: state.id,
|
|
|
|
},
|
|
|
|
'article.note' => {
|
|
|
|
'body' => 'test body',
|
|
|
|
'internal' => 'true',
|
|
|
|
'subject' => 'test sub'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ux_flow_next_up: 'none',)
|
|
|
|
|
|
|
|
# refresh browser to get macro accessible
|
|
|
|
refresh
|
|
|
|
|
|
|
|
# create a new ticket and attempt to update its state without the required select attribute
|
|
|
|
visit "#ticket/zoom/#{ticket.id}"
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
expect(page).to have_selector('.js-objectNumber', text: ticket.number)
|
|
|
|
expect(page).to have_select('state_id',
|
|
|
|
selected: 'new',
|
|
|
|
options: ['new', 'closed', 'open', 'pending close', 'pending reminder'])
|
|
|
|
|
|
|
|
click('.js-openDropdownMacro')
|
|
|
|
click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
|
2020-08-26 12:31:33 +00:00
|
|
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
|
2019-11-26 10:40:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_selector('.content.active .article-content', text: 'test body')
|
|
|
|
expect(page).to have_select('state_id',
|
|
|
|
selected: 'closed',
|
|
|
|
options: ['closed', 'open', 'pending close', 'pending reminder'])
|
|
|
|
|
|
|
|
# the update should not have failed and thus the ticket is in closed state
|
|
|
|
ticket.reload
|
|
|
|
expect(ticket.state.name).to eq(state.name)
|
|
|
|
article = ticket.articles.last
|
|
|
|
expect(article).to be_present
|
|
|
|
expect(article.body).to eq('test body')
|
|
|
|
expect(article.subject).to eq('test sub')
|
2022-03-01 08:00:40 +00:00
|
|
|
expect(article.internal).to be(true)
|
2019-11-26 10:40:23 +00:00
|
|
|
end
|
2019-01-04 14:26:43 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
|
|
|
|
context 'when merging tickets' do
|
2020-08-03 11:36:53 +00:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:origin_ticket) { create :ticket, group: group }
|
|
|
|
let!(:target_ticket) { create :ticket, group: group }
|
|
|
|
|
|
|
|
before do
|
2019-02-13 09:09:20 +00:00
|
|
|
origin_ticket.merge_to(ticket_id: target_ticket.id, user_id: user.id)
|
2020-08-03 11:36:53 +00:00
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
|
2020-08-03 11:36:53 +00:00
|
|
|
# Issue #2469 - Add information "Ticket merged" to History
|
|
|
|
it 'tickets history of both tickets should show the merge event' do
|
2019-02-13 09:09:20 +00:00
|
|
|
visit "#ticket/zoom/#{origin_ticket.id}"
|
2019-02-27 13:02:16 +00:00
|
|
|
within(:active_content) do
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.js-actions .dropdown-toggle')
|
2019-02-27 13:02:16 +00:00
|
|
|
click '.js-actions .dropdown-toggle'
|
|
|
|
click '.js-actions .dropdown-menu [data-type="ticket-history"]'
|
2019-02-13 09:09:20 +00:00
|
|
|
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.modal')
|
2019-02-27 13:02:16 +00:00
|
|
|
modal = find('.modal')
|
|
|
|
expect(modal).to have_content "This ticket was merged into ticket ##{target_ticket.number}"
|
|
|
|
expect(modal).to have_link "##{target_ticket.number}", href: "#ticket/zoom/#{target_ticket.id}"
|
2019-02-13 09:09:20 +00:00
|
|
|
|
2019-02-27 13:02:16 +00:00
|
|
|
visit "#ticket/zoom/#{target_ticket.id}"
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.js-actions .dropdown-toggle')
|
2019-02-27 13:02:16 +00:00
|
|
|
click '.js-actions .dropdown-toggle'
|
|
|
|
click '.js-actions .dropdown-menu [data-type="ticket-history"]'
|
2019-02-13 09:09:20 +00:00
|
|
|
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.modal')
|
2019-02-27 13:02:16 +00:00
|
|
|
modal = find('.modal')
|
|
|
|
expect(modal).to have_content("Ticket ##{origin_ticket.number} was merged into this ticket")
|
|
|
|
expect(modal).to have_link "##{origin_ticket.number}", href: "#ticket/zoom/#{origin_ticket.id}"
|
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
end
|
2020-08-03 11:36:53 +00:00
|
|
|
|
|
|
|
# Issue #2960 - Ticket removal of merged / linked tickets doesn't remove references
|
|
|
|
context 'when the merged origin ticket is deleted' do
|
|
|
|
before do
|
|
|
|
origin_ticket.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the target ticket history' do
|
|
|
|
visit "#ticket/zoom/#{target_ticket.id}"
|
|
|
|
within(:active_content) do
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.js-actions .dropdown-toggle')
|
2020-08-03 11:36:53 +00:00
|
|
|
click '.js-actions .dropdown-toggle'
|
|
|
|
click '.js-actions .dropdown-menu [data-type="ticket-history"]'
|
|
|
|
end
|
|
|
|
|
|
|
|
modal_ready
|
|
|
|
|
|
|
|
within('.modal-body') do
|
|
|
|
expect(page).to have_text "##{origin_ticket.number} #{origin_ticket.title}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Issue #2960 - Ticket removal of merged / linked tickets doesn't remove references
|
|
|
|
context 'when the merged target ticket is deleted' do
|
|
|
|
before do
|
|
|
|
target_ticket.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the origin history' do
|
|
|
|
visit "#ticket/zoom/#{origin_ticket.id}"
|
|
|
|
within(:active_content) do
|
2022-01-25 09:36:20 +00:00
|
|
|
expect(page).to have_css('.js-actions .dropdown-toggle')
|
2020-08-03 11:36:53 +00:00
|
|
|
click '.js-actions .dropdown-toggle'
|
|
|
|
click '.js-actions .dropdown-menu [data-type="ticket-history"]'
|
|
|
|
end
|
|
|
|
|
|
|
|
modal_ready
|
|
|
|
|
|
|
|
within('.modal-body') do
|
|
|
|
expect(page).to have_text "##{target_ticket.number} #{target_ticket.title}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-13 09:09:20 +00:00
|
|
|
end
|
2019-07-03 16:14:28 +00:00
|
|
|
|
2021-09-27 10:49:55 +00:00
|
|
|
context 'when closing taskbar tab for ticket' do
|
|
|
|
it 'close task bar entry after some changes in ticket update form' do
|
|
|
|
visit "#ticket/zoom/#{ticket.id}"
|
|
|
|
|
|
|
|
within(:active_content) do
|
|
|
|
find('.js-textarea').send_keys('some note')
|
|
|
|
end
|
|
|
|
|
|
|
|
taskbar_tab_close("Ticket-#{ticket.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-03 16:14:28 +00:00
|
|
|
context 'when using text modules' do
|
2019-11-26 10:40:23 +00:00
|
|
|
include_examples 'text modules', path: "#ticket/zoom/#{Ticket.first.id}"
|
2019-07-03 16:14:28 +00:00
|
|
|
end
|
2019-09-04 07:42:50 +00:00
|
|
|
|
|
|
|
context 'when using macros' do
|
2019-11-26 10:40:23 +00:00
|
|
|
include_examples 'macros', path: "#ticket/zoom/#{Ticket.first.id}"
|
2019-09-04 07:42:50 +00:00
|
|
|
end
|
2021-09-27 10:49:55 +00:00
|
|
|
|
|
|
|
context 'when group will be changed' do
|
2021-10-21 11:22:06 +00:00
|
|
|
let(:user) { User.find_by(email: 'agent1@example.com') }
|
2021-09-27 10:49:55 +00:00
|
|
|
let(:ticket) { create(:ticket, group: group, owner: user) }
|
|
|
|
|
2021-10-21 11:22:06 +00:00
|
|
|
it 'check that owner resets after group change' do
|
2021-09-27 10:49:55 +00:00
|
|
|
visit "#ticket/zoom/#{ticket.id}"
|
|
|
|
|
|
|
|
expect(page).to have_field('owner_id', with: user.id)
|
|
|
|
|
|
|
|
find('[name=group_id]').select '-'
|
|
|
|
|
|
|
|
expect(page).to have_field('owner_id', with: '')
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 14:26:43 +00:00
|
|
|
end
|