readonly_spec.rb 7.1 KB

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