agents_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Getting Started > Agents', type: :system do
  4. let(:group) { Group.first }
  5. let(:group2) { Group.second }
  6. before do
  7. visit 'getting_started/agents', skip_waiting: true
  8. end
  9. it 'shows email address already used error' do
  10. fill_in 'firstname', with: 'Test'
  11. fill_in 'lastname', with: 'Test'
  12. fill_in 'email', with: 'admin@example.com'
  13. click '.btn--success'
  14. within '.js-danger' do
  15. expect(page)
  16. .to have_text("Email address 'admin@example.com' is already used for another user.")
  17. end
  18. end
  19. it 'toggles groups on (un)checking agent role' do
  20. expect(page).to have_css('[data-attribute-name="group_ids"]')
  21. click 'span', text: 'Agent'
  22. expect(page).to have_no_css('[data-attribute-name="group_ids"]')
  23. click 'span', text: 'Agent'
  24. expect(page).to have_css('[data-attribute-name="group_ids"]')
  25. end
  26. context 'when email is filled in' do
  27. before do
  28. fill_in 'email', with: 'test@example.com'
  29. end
  30. it 'adds roles correctly' do
  31. click 'span', text: 'Admin'
  32. click 'span', text: 'Agent' # unselect preselected role
  33. click '.btn--success'
  34. expect(User.last).to have_attributes(
  35. email: 'test@example.com',
  36. roles: contain_exactly(
  37. Role.find_by(name: 'Admin')
  38. )
  39. )
  40. end
  41. it 'adds group permissions correctly' do
  42. expect(page).to have_no_css '[data-attribute-name="group_ids"] tbody tr[data-id]'
  43. within '.js-groupListNewItemRow' do
  44. click '.js-input'
  45. click 'li', text: group.name
  46. click 'input[value="full"]', visible: :all
  47. click '.js-add'
  48. end
  49. within '.js-groupListNewItemRow' do
  50. click '.js-input'
  51. click 'li', text: group2.name
  52. click 'input[value="read"]', visible: :all
  53. click '.js-add'
  54. end
  55. within "[data-attribute-name='group_ids'] tbody tr[data-id='#{group.id}']" do
  56. click '.js-remove'
  57. end
  58. click '.btn--success'
  59. expect(User.last).to have_attributes(
  60. email: 'test@example.com',
  61. user_groups: contain_exactly(
  62. have_attributes(group: group2, access: 'read')
  63. )
  64. )
  65. end
  66. end
  67. end