text_modules_examples.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. RSpec.shared_examples 'text modules' do |path:|
  2. let!(:group1) { create :group }
  3. let!(:group2) { create :group }
  4. let!(:text_module_without_group) { create :text_module }
  5. let!(:text_module_group1) { create :text_module, groups: [group1] }
  6. let!(:text_module_group2) { create :text_module, groups: [group2] }
  7. it 'shows when send ::' do
  8. refresh # workaround to get new created objects from db
  9. visit path
  10. within(:active_content) do
  11. find('select[name="group_id"]').select(1)
  12. find(:richtext).send_keys(':')
  13. find(:richtext).send_keys(':')
  14. expect(page).to have_selector(:text_module, text_module_without_group.id)
  15. end
  16. end
  17. it 'does not show when send :enter:' do
  18. visit path
  19. within(:active_content) do
  20. find('select[name="group_id"]').select(1)
  21. find(:richtext).send_keys(':')
  22. find(:richtext).send_keys(:enter)
  23. find(:richtext).send_keys(':')
  24. expect(page).to have_no_selector(:text_module, text_module_without_group.id)
  25. end
  26. end
  27. it 'supports group-dependent text modules' do
  28. # give user access to all groups including those created
  29. # by using FactoryBot outside of the example
  30. group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result|
  31. result[group_name] = 'full'.freeze
  32. end
  33. current_user do |user|
  34. user.group_names_access_map = group_names_access_map
  35. user.save!
  36. end
  37. refresh # workaround to get changed settings from db
  38. visit path
  39. within(:active_content) do
  40. find('select[name="group_id"]').select(group1.name)
  41. find(:richtext).send_keys('::')
  42. expect(page).to have_selector(:text_module, text_module_without_group.id)
  43. expect(page).to have_selector(:text_module, text_module_group1.id)
  44. expect(page).to have_no_selector(:text_module, text_module_group2.id)
  45. find('select[name="group_id"]').select(group2.name)
  46. find(:richtext).send_keys('::')
  47. expect(page).to have_selector(:text_module, text_module_without_group.id)
  48. expect(page).to have_no_selector(:text_module, text_module_group1.id)
  49. expect(page).to have_selector(:text_module, text_module_group2.id)
  50. end
  51. end
  52. end