text_modules_examples.rb 2.1 KB

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