readonly_spec.rb 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket Access Zoom', authenticated_as: :user, type: :system do
  4. let(:group) { create(:group) }
  5. let!(:ticket) do
  6. create(:ticket, group: group).tap do |ticket|
  7. ticket.tag_add('Tag', 1)
  8. create(:link, from: create(:ticket, group: group), to: ticket)
  9. create(:ticket_article, ticket: ticket)
  10. end
  11. end
  12. let(:user) do
  13. create(:agent).tap do |agent|
  14. agent.user_groups.create! group: group, access: group_access
  15. end
  16. end
  17. let(:name) { attribute.name }
  18. let(:data_type) { attribute.data_type }
  19. let(:display) { attribute.display }
  20. let(:value) { data_option['options'].values.first }
  21. let(:data_option) do
  22. {
  23. 'default' => '',
  24. 'options' => { 'value_1' => 'value_1', 'value_2' => 'value_2', 'value_3' => 'value_3' },
  25. 'relation' => '', 'nulloption' => true, 'multiple' => false,
  26. 'null' => true, 'translate' => true, 'maxlength' => 255
  27. }
  28. end
  29. let(:multi_data_option) do
  30. data_option.merge({ 'multiple' => true })
  31. end
  32. before do
  33. visit "ticket/zoom/#{ticket.id}"
  34. end
  35. shared_examples 'elements' do
  36. it 'verify all elements available' do
  37. %w[TAGS LINKS].each do |element|
  38. expect(page).to have_content(element)
  39. end
  40. end
  41. end
  42. context 'with full access' do
  43. let(:group_access) { :full }
  44. include_examples 'elements'
  45. it 'shows tag, and link modification buttons' do
  46. expect(page).to have_css('.tags .icon-diagonal-cross')
  47. expect(page).to have_content('+ Add Tag')
  48. expect(page).to have_css('.links .icon-diagonal-cross')
  49. expect(page).to have_content('+ Add Link')
  50. end
  51. context 'with select, treeselect, multiselect and multi-treeselect fields', authenticated_as: :authenticated, db_strategy: :reset do
  52. def authenticated
  53. attribute
  54. ObjectManager::Attribute.migration_execute
  55. user
  56. end
  57. shared_examples 'allow agents to select another value' do
  58. it 'allows agents to select another value' do
  59. within attribute_selector do
  60. expect(page).to have_content(%r{#{display}}i)
  61. find(".controls select[name=#{name}]", visible: :all).select value
  62. expect(page).to have_select(name, selected: value, visible: :all)
  63. end
  64. end
  65. end
  66. shared_examples 'allows agents to select a treeselect/multi-treeselect value' do
  67. it 'allows agents to select another value' do
  68. within attribute_selector { expect(page).to have_content(%r{#{display}}i) }
  69. dropdown_toggle
  70. within attribute_selector do
  71. find(".js-optionsList > .js-option[data-value=#{value}]", visible: :all).click
  72. expect(page).to have_element
  73. end
  74. end
  75. end
  76. context 'with a select field' do
  77. let(:attribute) { create(:object_manager_attribute_select, :required_screen, data_option: data_option) }
  78. include_examples 'allow agents to select another value'
  79. end
  80. context 'with a multiselect field' do
  81. let(:attribute) { create(:object_manager_attribute_multiselect, :required_screen, data_option: multi_data_option) }
  82. include_examples 'allow agents to select another value'
  83. end
  84. context 'with a tree select field' do
  85. let(:attribute) { create(:object_manager_attribute_tree_select, :required_screen, data_option: data_option) }
  86. let(:have_element) { have_field(name, with: value, visible: :all) }
  87. include_examples 'allows agents to select a treeselect/multi-treeselect value'
  88. end
  89. context 'with a multi tree select field' do
  90. let(:attribute) { create(:object_manager_attribute_multi_tree_select, :required_screen, data_option: multi_data_option) }
  91. let(:have_element) { have_select(name, selected: value, visible: :all) }
  92. include_examples 'allows agents to select a treeselect/multi-treeselect value'
  93. end
  94. end
  95. end
  96. context 'with read access' do
  97. let(:group_access) { :read }
  98. include_examples 'elements'
  99. it 'shows no tag and link modification buttons' do
  100. expect(page).to have_no_selector('.tags .icon-diagonal-cross')
  101. expect(page).to have_no_content('+ Add Tag')
  102. expect(page).to have_no_selector('.links .icon-diagonal-cross')
  103. expect(page).to have_no_content('+ Add Link')
  104. end
  105. it 'shows no ticket actions' do
  106. expect(page).to have_no_selector('.js-submit')
  107. expect(page).to have_no_selector('.js-secondaryActionButtonLabel')
  108. expect(page).to have_no_selector('.js-ArticleAction[data-type=internal]')
  109. expect(page).to have_no_selector('.js-highlight')
  110. end
  111. it 'shows no ticket sidebar ticket actions' do
  112. click '.sidebar .js-headline'
  113. expect(page).to have_no_text('Change Customer')
  114. expect(page).to have_no_text('Merge')
  115. end
  116. it 'shows no ticket sidebar customer ticket actions' do
  117. click '.tabsSidebar-tab[data-tab=customer]'
  118. click '.sidebar .js-headline'
  119. expect(page).to have_no_text('Change Customer')
  120. end
  121. context 'with select, treeselect, multiselect and multi-treeselect fields', authenticated_as: :authenticated, db_strategy: :reset do
  122. def authenticated
  123. attribute
  124. ObjectManager::Attribute.migration_execute
  125. user
  126. end
  127. shared_examples 'does not allow agents to select another value' do
  128. it 'does not allow agents to select another value' do
  129. within attribute_selector do
  130. expect(page).to have_content(%r{#{display}}i)
  131. find(".controls select[name=#{name}]", visible: :all).select value, disabled: true
  132. expect(page).to have_no_select(name, selected: value, visible: :all, disabled: :all)
  133. end
  134. end
  135. end
  136. shared_examples 'does not allow agents to select another treeselect/multi-treeselect value' do
  137. it 'does not allow agents to select another value' do
  138. within attribute_selector do
  139. expect(page).to have_content(%r{#{display}}i)
  140. find('.controls .dropdown .dropdown-toggle').click
  141. expect(page).to have_no_css(".js-optionsList > .js-option[data-value=#{value}]", wait: 15)
  142. end
  143. end
  144. end
  145. context 'with a select field' do
  146. let(:attribute) { create(:object_manager_attribute_select, :required_screen, data_option: data_option) }
  147. include_examples 'does not allow agents to select another value'
  148. end
  149. context 'with a multiselect field' do
  150. let(:attribute) { create(:object_manager_attribute_multiselect, :required_screen, data_option: multi_data_option) }
  151. include_examples 'does not allow agents to select another value'
  152. end
  153. context 'with a tree select field' do
  154. let(:attribute) { create(:object_manager_attribute_tree_select, :required_screen, data_option: data_option) }
  155. include_examples 'does not allow agents to select another treeselect/multi-treeselect value'
  156. end
  157. context 'with a multi tree select field' do
  158. let(:attribute) { create(:object_manager_attribute_multi_tree_select, :required_screen, data_option: multi_data_option) }
  159. include_examples 'does not allow agents to select another treeselect/multi-treeselect value'
  160. end
  161. end
  162. end
  163. def dropdown_toggle
  164. loop do
  165. find('.controls .dropdown .dropdown-toggle').click
  166. break if find_all(".js-optionsList > .js-option[data-value=#{value}]", allow_reload: true, wait: 0).any?
  167. # If we could not find the dropdown options, we sleep and try again.
  168. sleep 0.1
  169. end
  170. end
  171. def attribute_selector
  172. ".sidebar-content .#{data_type}[data-attribute-name=#{name}]"
  173. end
  174. end