roles_spec.rb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/examples/pagination_examples'
  4. RSpec.describe 'Manage > Role', type: :system do
  5. context 'ajax pagination' do
  6. include_examples 'pagination', model: :role, klass: Role, path: 'manage/roles'
  7. end
  8. # https://github.com/zammad/zammad/issues/4100
  9. context 'creating a new role' do
  10. let(:group) { Group.first }
  11. let(:group2) { Group.second }
  12. before do
  13. visit '#manage/roles'
  14. within(:active_content) do
  15. find('[data-type=new]').click
  16. end
  17. end
  18. it 'handles permission checkboxes correctly' do
  19. in_modal do
  20. scroll_into_view 'input[data-permission-name="ticket.agent"]'
  21. click 'input[data-permission-name="ticket.agent"]', visible: :all
  22. scroll_into_view '[data-attribute-name="group_ids"]'
  23. within '.js-groupListNewItemRow' do
  24. click '.js-input'
  25. click 'li', text: group.name
  26. click 'input[value="full"]', visible: :all
  27. expect(find('input[value="full"]', visible: :all)).to be_checked
  28. click 'input[value="read"]', visible: :all
  29. expect(find('input[value="full"]', visible: :all)).not_to be_checked
  30. expect(find('input[value="read"]', visible: :all)).to be_checked
  31. click 'input[value="full"]', visible: :all
  32. expect(find('input[value="full"]', visible: :all)).to be_checked
  33. expect(find('input[value="read"]', visible: :all)).not_to be_checked
  34. end
  35. end
  36. end
  37. end
  38. context 'updating an existing role' do
  39. let(:role) { create(:role, :agent) }
  40. let(:row) { find "table tbody tr[data-id='#{role.id}']" }
  41. let(:group) { Group.first }
  42. let(:group2) { Group.second }
  43. before do
  44. role
  45. visit '#manage/roles'
  46. within(:active_content) do
  47. row.click
  48. end
  49. end
  50. it 'adds group permissions correctly' do
  51. in_modal do
  52. scroll_into_view '[data-attribute-name="group_ids"]'
  53. expect(page).to have_no_css 'table.settings-list tbody tr[data-id]'
  54. within '.js-groupListNewItemRow' do
  55. click '.js-input'
  56. click 'li', text: group.name
  57. click 'input[value="full"]', visible: :all
  58. click '.js-add'
  59. end
  60. expect(page).to have_css "table.settings-list tbody tr[data-id='#{group.id}']"
  61. within '.js-groupListNewItemRow' do
  62. click '.js-input'
  63. click 'li', text: group2.name
  64. click 'input[value="read"]', visible: :all
  65. end
  66. click_on 'Submit'
  67. end
  68. # only the first group is added
  69. # because add button is not clicked for the 2nd group
  70. expect(role.reload.role_groups).to contain_exactly(
  71. have_attributes(group: group, access: 'full')
  72. )
  73. end
  74. context 'when role already has a group configured', authenticated_as: :authenticate do
  75. def authenticate
  76. role.groups << group
  77. role.groups << group2
  78. true
  79. end
  80. it 'toggles groups on (un)checking agent group' do
  81. in_modal do
  82. scroll_into_view '[data-attribute-name="group_ids"]'
  83. expect(page).to have_css('[data-attribute-name="group_ids"]')
  84. click 'span', text: 'Agent tickets'
  85. expect(page).to have_no_css('[data-attribute-name="group_ids"]')
  86. click 'span', text: 'Agent tickets'
  87. expect(page).to have_css('[data-attribute-name="group_ids"]')
  88. end
  89. end
  90. it 'removes group correctly' do
  91. in_modal do
  92. scroll_into_view 'table.settings-list'
  93. within "table.settings-list tbody tr[data-id='#{group.id}']" do
  94. click '.js-remove'
  95. end
  96. click_on 'Submit'
  97. end
  98. expect(role.reload.role_groups).to contain_exactly(
  99. have_attributes(group: group2, access: 'full')
  100. )
  101. end
  102. end
  103. end
  104. end