macros_examples.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'macros' do |path:|
  3. let!(:group1) { create(:group) }
  4. let!(:group2) { create(:group) }
  5. let!(:macro_without_group) { create(:macro) }
  6. let!(:macro_group1) { create(:macro, groups: [group1]) }
  7. let!(:macro_group2) { create(:macro, groups: [group2]) }
  8. it 'supports group-dependent macros' do
  9. visit '/'
  10. # give user access to all groups including those created
  11. # by using FactoryBot outside of the example
  12. group_names_access_map = Group.pluck(:name).index_with do |_group_name|
  13. 'full'.freeze
  14. end
  15. current_user do |user|
  16. user.group_names_access_map = group_names_access_map
  17. user.save!
  18. end
  19. # refresh browser to get macro accessable
  20. refresh
  21. visit path
  22. within(:active_content) do
  23. # select group
  24. set_tree_select_value('group_id', group1.name)
  25. open_macro_list
  26. expect(page).to have_selector(:macro, macro_without_group.id)
  27. expect(page).to have_selector(:macro, macro_group1.id)
  28. expect(page).to have_no_selector(:macro, macro_group2.id)
  29. # select group
  30. set_tree_select_value('group_id', group2.name)
  31. open_macro_list
  32. expect(page).to have_selector(:macro, macro_without_group.id)
  33. expect(page).to have_no_selector(:macro, macro_group1.id)
  34. expect(page).to have_selector(:macro, macro_group2.id)
  35. end
  36. end
  37. end