update_spec.rb 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. require 'rails_helper'
  2. require 'system/examples/text_modules_examples'
  3. require 'system/examples/macros_examples'
  4. RSpec.describe 'Ticket Update', type: :system do
  5. let(:group) { Group.find_by(name: 'Users') }
  6. let(:ticket) { create(:ticket, group: group) }
  7. # Regression test for issue #2242 - mandatory fields can be empty (or "-") on ticket update
  8. context 'when updating a ticket without its required select attributes' do
  9. it 'frontend checks reject the update', db_strategy: :reset do
  10. # setup and migrate a required select attribute
  11. attribute = create_attribute(:object_manager_attribute_select,
  12. screens: attributes_for(:required_screen),
  13. data_option: {
  14. options: {
  15. 'name 1': 'name 1',
  16. 'name 2': 'name 2',
  17. },
  18. default: '',
  19. null: false,
  20. relation: '',
  21. maxlength: 255,
  22. nulloption: true,
  23. })
  24. # create a new ticket and attempt to update its state without the required select attribute
  25. visit "#ticket/zoom/#{ticket.id}"
  26. within(:active_content) do
  27. expect(page).to have_selector('.js-objectNumber', text: ticket.number)
  28. select('closed', from: 'state_id')
  29. click('.js-attributeBar .js-submit')
  30. expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
  31. end
  32. # the update should have failed and thus the ticket is still in the new state
  33. expect(ticket.reload.state.name).to eq('new')
  34. within(:active_content) do
  35. # update should work now
  36. find(".edit [name=#{attribute.name}]").select('name 2')
  37. click('.js-attributeBar .js-submit')
  38. expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
  39. end
  40. ticket.reload
  41. expect(ticket[attribute.name]).to eq('name 2')
  42. expect(ticket.state.name).to eq('closed')
  43. end
  44. end
  45. context 'when updating a ticket with macro' do
  46. context 'when required tree_select field is present' do
  47. it 'performs no validation (#2492)', db_strategy: :reset do
  48. # setup and migrate a required select attribute
  49. attribute = create_attribute(:object_manager_attribute_tree_select,
  50. screens: attributes_for(:required_screen),
  51. data_option: {
  52. options: [
  53. {
  54. name: 'name 1',
  55. value: 'name 1',
  56. },
  57. {
  58. name: 'name 2',
  59. value: 'name 2',
  60. },
  61. ],
  62. default: '',
  63. null: false,
  64. relation: '',
  65. maxlength: 255,
  66. nulloption: true,
  67. })
  68. attribute_value = 'name 2'
  69. state = Ticket::State.by_category(:closed).first
  70. macro = create(:macro,
  71. perform: {
  72. 'ticket.state_id' => {
  73. value: state.id,
  74. },
  75. "ticket.#{attribute.name}" => {
  76. value: attribute_value,
  77. },
  78. },
  79. ux_flow_next_up: 'none',)
  80. # refresh browser to get macro accessible
  81. refresh
  82. # create a new ticket and attempt to update its state without the required select attribute
  83. visit "#ticket/zoom/#{ticket.id}"
  84. within(:active_content) do
  85. expect(page).to have_selector('.js-objectNumber', text: ticket.number)
  86. expect(page).to have_field(attribute.name, with: '', visible: :hidden)
  87. expect(page).to have_select('state_id',
  88. selected: 'new',
  89. options: ['new', 'closed', 'open', 'pending close', 'pending reminder'])
  90. click('.js-openDropdownMacro')
  91. click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
  92. expect(page).not_to have_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
  93. end
  94. expect(page).to have_field(attribute.name, with: attribute_value, visible: :hidden)
  95. expect(page).to have_select('state_id',
  96. selected: 'closed',
  97. options: ['closed', 'open', 'pending close', 'pending reminder'])
  98. # the update should not have failed and thus the ticket is in closed state
  99. ticket.reload
  100. expect(ticket[attribute.name]).to eq(attribute_value)
  101. expect(ticket.state.name).to eq(state.name)
  102. end
  103. end
  104. context 'when macro has article configured' do
  105. it 'creates an article with the configured attributes' do
  106. state = Ticket::State.find_by(name: 'closed')
  107. macro = create(:macro,
  108. perform: {
  109. 'ticket.state_id' => {
  110. value: state.id,
  111. },
  112. 'article.note' => {
  113. 'body' => 'test body',
  114. 'internal' => 'true',
  115. 'subject' => 'test sub'
  116. },
  117. },
  118. ux_flow_next_up: 'none',)
  119. # refresh browser to get macro accessible
  120. refresh
  121. # create a new ticket and attempt to update its state without the required select attribute
  122. visit "#ticket/zoom/#{ticket.id}"
  123. within(:active_content) do
  124. expect(page).to have_selector('.js-objectNumber', text: ticket.number)
  125. expect(page).to have_select('state_id',
  126. selected: 'new',
  127. options: ['new', 'closed', 'open', 'pending close', 'pending reminder'])
  128. click('.js-openDropdownMacro')
  129. click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
  130. expect(page).not_to have_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
  131. end
  132. expect(page).to have_selector('.content.active .article-content', text: 'test body')
  133. expect(page).to have_select('state_id',
  134. selected: 'closed',
  135. options: ['closed', 'open', 'pending close', 'pending reminder'])
  136. # the update should not have failed and thus the ticket is in closed state
  137. ticket.reload
  138. expect(ticket.state.name).to eq(state.name)
  139. article = ticket.articles.last
  140. expect(article).to be_present
  141. expect(article.body).to eq('test body')
  142. expect(article.subject).to eq('test sub')
  143. expect(article.internal).to eq(true)
  144. end
  145. end
  146. end
  147. # Issue #2469 - Add information "Ticket merged" to History
  148. context 'when merging tickets' do
  149. it 'tickets history of both tickets should show the merge event' do
  150. user = create :user
  151. origin_ticket = create :ticket, group: group
  152. target_ticket = create :ticket, group: group
  153. origin_ticket.merge_to(ticket_id: target_ticket.id, user_id: user.id)
  154. visit "#ticket/zoom/#{origin_ticket.id}"
  155. within(:active_content) do
  156. expect(page).to have_css('.js-actions .dropdown-toggle', wait: 3)
  157. click '.js-actions .dropdown-toggle'
  158. click '.js-actions .dropdown-menu [data-type="ticket-history"]'
  159. expect(page).to have_css('.modal', wait: 3)
  160. modal = find('.modal')
  161. expect(modal).to have_content "This ticket was merged into ticket ##{target_ticket.number}"
  162. expect(modal).to have_link "##{target_ticket.number}", href: "#ticket/zoom/#{target_ticket.id}"
  163. visit "#ticket/zoom/#{target_ticket.id}"
  164. expect(page).to have_css('.js-actions .dropdown-toggle', wait: 3)
  165. click '.js-actions .dropdown-toggle'
  166. click '.js-actions .dropdown-menu [data-type="ticket-history"]'
  167. expect(page).to have_css('.modal', wait: 3)
  168. modal = find('.modal')
  169. expect(modal).to have_content("Ticket ##{origin_ticket.number} was merged into this ticket")
  170. expect(modal).to have_link "##{origin_ticket.number}", href: "#ticket/zoom/#{origin_ticket.id}"
  171. end
  172. end
  173. end
  174. context 'when using text modules' do
  175. include_examples 'text modules', path: "#ticket/zoom/#{Ticket.first.id}"
  176. end
  177. context 'when using macros' do
  178. include_examples 'macros', path: "#ticket/zoom/#{Ticket.first.id}"
  179. end
  180. end