text_modules_examples.rb 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. RSpec.shared_examples 'text modules' do |path:|
  3. let!(:agent_fixed_name) { create :agent, firstname: 'FFFF1', lastname: 'GGGG1', groups: [Group.find_by(name: 'Users')] }
  4. let!(:group1) { create :group }
  5. let!(:group2) { create :group }
  6. let!(:text_module_without_group) { create :text_module }
  7. let!(:text_module_group1) { create :text_module, groups: [group1] }
  8. let!(:text_module_group2) { create :text_module, groups: [group2] }
  9. it 'shows when send ::' do
  10. refresh # workaround to get new created objects from db
  11. visit path
  12. within(:active_content) do
  13. find('select[name="group_id"]').select(1)
  14. find(:richtext).send_keys(':')
  15. find(:richtext).send_keys(':')
  16. expect(page).to have_selector(:text_module, text_module_without_group.id)
  17. end
  18. end
  19. it 'does not break after usage of Ctrl/Command+Backspace' do
  20. visit path
  21. within(:active_content) do
  22. find(:richtext).send_keys(':')
  23. find(:richtext).send_keys(':')
  24. find(:richtext).send_keys('bur')
  25. # The click is needed to get the focus back to the field for chrome.
  26. find(:richtext).click
  27. if Gem::Platform.local.os.eql? 'darwin'
  28. find(:richtext).send_keys(%i[command backspace])
  29. else
  30. find(:richtext).send_keys(%i[control backspace])
  31. end
  32. find(:richtext).send_keys('Some other text')
  33. find(:richtext).send_keys(:enter)
  34. expect(find(:richtext)).to have_text 'Some other text'
  35. end
  36. end
  37. it 'does not show when send :enter:' do
  38. visit path
  39. within(:active_content) do
  40. find('select[name="group_id"]').select(1)
  41. find(:richtext).send_keys(':')
  42. find(:richtext).send_keys(:enter)
  43. find(:richtext).send_keys(':')
  44. expect(page).to have_no_selector(:text_module, text_module_without_group.id)
  45. end
  46. end
  47. it 'does not break search on backspace' do
  48. visit path
  49. within(:active_content) do
  50. find('select[name="group_id"]').select(1)
  51. find(:richtext).send_keys('@@agen')
  52. find(:richtext).send_keys(:backspace)
  53. expect(page).to have_no_text('No results found')
  54. end
  55. end
  56. it 'does delete empty mentions (issue #3636 / FF only)' do
  57. visit path
  58. within(:active_content) do
  59. find('select[name="group_id"]').select('Users')
  60. find(:richtext).send_keys('@@FFFF1')
  61. find(:richtext).send_keys(:enter)
  62. find(:richtext).send_keys(:enter)
  63. (agent_fixed_name.firstname.length + agent_fixed_name.lastname.length + 2).times do
  64. find(:richtext).send_keys(:backspace)
  65. end
  66. expect(find(:richtext).all('a[data-mention-user-id]', visible: :all).count).to eq(0)
  67. end
  68. end
  69. it 'does delete empty mentions (issue #3636 / simulation)' do
  70. visit path
  71. within(:active_content) do
  72. find('select[name="group_id"]').select('Users')
  73. find(:richtext).send_keys('@@FFFF1')
  74. find(:richtext).send_keys(:enter)
  75. find(:richtext).send_keys(:enter)
  76. find(:richtext).send_keys('test')
  77. page.execute_script("$('a[data-mention-user-id]').first().html('<br>')")
  78. find(:richtext).send_keys(:backspace)
  79. expect(find(:richtext).all('a[data-mention-user-id]', visible: :all).count).to eq(0)
  80. end
  81. end
  82. it 'does not delete parts of the text on multiple mentions (issue #3717)' do
  83. visit path
  84. within(:active_content) do
  85. find('select[name="group_id"]').select('Users')
  86. find(:richtext).send_keys('Testing Testy')
  87. find(:richtext).send_keys('@@FFFF1')
  88. find(:richtext).send_keys(:enter)
  89. find(:richtext).send_keys(:enter)
  90. find(:richtext).send_keys('Testing Testy ')
  91. find(:richtext).send_keys('@@FFFF1')
  92. find(:richtext).send_keys(:enter)
  93. expect(find(:richtext).text).to include('Testing TestyFFFF1 GGGG1')
  94. expect(find(:richtext).text).to include('Testing Testy FFFF1 GGGG1')
  95. end
  96. end
  97. it 'does not delete line breaks of text with mentions (issue #3717)' do
  98. visit path
  99. within(:active_content) do
  100. find('select[name="group_id"]').select('Users')
  101. find(:richtext).send_keys('@@FFFF1')
  102. find(:richtext).send_keys(:enter)
  103. find(:richtext).send_keys(' Testing Testy')
  104. find(:richtext).send_keys(:enter)
  105. find(:richtext).send_keys(:enter)
  106. find(:richtext).send_keys(:backspace)
  107. find(:richtext).send_keys('@@FFFF1')
  108. find(:richtext).send_keys(:enter)
  109. expect(find(:richtext).text).to include("FFFF1 GGGG1 Testing Testy\nFFFF1 GGGG1")
  110. end
  111. end
  112. it 'supports group-dependent text modules' do
  113. # give user access to all groups including those created
  114. # by using FactoryBot outside of the example
  115. group_names_access_map = Group.all.pluck(:name).index_with do |_group_name|
  116. 'full'.freeze
  117. end
  118. current_user do |user|
  119. user.group_names_access_map = group_names_access_map
  120. user.save!
  121. end
  122. refresh # workaround to get changed settings from db
  123. visit path
  124. within(:active_content) do
  125. find('select[name="group_id"]').select(group1.name)
  126. find(:richtext).send_keys('::')
  127. expect(page).to have_selector(:text_module, text_module_without_group.id)
  128. expect(page).to have_selector(:text_module, text_module_group1.id)
  129. expect(page).to have_no_selector(:text_module, text_module_group2.id)
  130. find('select[name="group_id"]').select(group2.name)
  131. find(:richtext).send_keys('::')
  132. expect(page).to have_selector(:text_module, text_module_without_group.id)
  133. expect(page).to have_no_selector(:text_module, text_module_group1.id)
  134. expect(page).to have_selector(:text_module, text_module_group2.id)
  135. end
  136. end
  137. end