notifications_spec.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Profile > Notifications', authenticated_as: :user, type: :system do
  4. let(:user) { create(:agent) }
  5. context 'with default notification settings' do
  6. before do
  7. visit 'profile/notifications'
  8. end
  9. it 'shows selected notifications' do
  10. user.preferences
  11. .dig('notification_config', 'matrix')
  12. .each do |key, value|
  13. expect(page).to have_field("matrix.#{key}.criteria.owned_by_me", checked: value[:criteria][:owned_by_me], visible: :all)
  14. expect(page).to have_field("matrix.#{key}.criteria.owned_by_nobody", checked: value[:criteria][:owned_by_nobody], visible: :all)
  15. expect(page).to have_field("matrix.#{key}.criteria.subscribed", checked: value[:criteria][:subscribed], visible: :all)
  16. expect(page).to have_field("matrix.#{key}.criteria.no", checked: value[:criteria][:no], visible: :all)
  17. expect(page).to have_field("matrix.#{key}.channel", checked: value[:channel][:email], visible: :all)
  18. end
  19. end
  20. it 'can change notifications' do
  21. find('input[name="matrix.escalation.criteria.owned_by_me"]', visible: :all).click
  22. find('input[name="matrix.escalation.channel"]', visible: :all).click
  23. find('#content_permanent_Profile form .btn--primary').click
  24. await_empty_ajax_queue
  25. expect(user.reload.preferences).to include(
  26. notification_config: include(
  27. matrix: include(
  28. escalation: include(
  29. criteria: include(owned_by_me: false),
  30. channel: include(email: false, online: true)
  31. ),
  32. update: include(
  33. criteria: include(owned_by_me: true),
  34. channel: include(email: true, online: true)
  35. )
  36. )
  37. )
  38. )
  39. end
  40. end
  41. context 'with custom notification settings' do
  42. before do
  43. user.preferences[:notification_config][:matrix][:escalation][:criteria][:owned_by_me] = false
  44. user.save!
  45. visit 'profile/notifications'
  46. end
  47. it 'can reset notifications' do
  48. find('#content_permanent_Profile form .js-reset').click
  49. in_modal do
  50. click_on 'Yes'
  51. end
  52. expect(page).to have_field('matrix.escalation.criteria.owned_by_me', checked: true, visible: :all)
  53. expect(user.reload.preferences).to include(
  54. notification_config: include(matrix: include(escalation: include(criteria: include(owned_by_me: true))))
  55. )
  56. end
  57. end
  58. describe 'limiting notifications by groups' do
  59. let(:group_a) { create(:group) }
  60. let(:group_b) { create(:group) }
  61. context 'when limit is not enabled' do
  62. before do
  63. user.update! groups: [group_a, group_b]
  64. visit 'profile/notifications'
  65. end
  66. it 'allows to limit notifications in specific groups' do
  67. expect(find('#profile-groups-limit', visible: :all)).not_to be_checked
  68. click '.zammad-switch'
  69. find('#content_permanent_Profile form .btn--primary').click
  70. await_empty_ajax_queue
  71. expect(user.reload.preferences).to include(
  72. notification_config: include(
  73. group_ids: [group_a.id.to_s, group_b.id.to_s]
  74. )
  75. )
  76. expect(find('#profile-groups-limit', visible: :all)).to be_checked
  77. end
  78. end
  79. context 'when limit is enabled' do
  80. before do
  81. user.groups = [group_a, group_b]
  82. user.preferences[:notification_config][:group_ids] = [group_a.id.to_s]
  83. user.save!
  84. visit 'profile/notifications'
  85. end
  86. it 'clears groups limit' do
  87. expect(find('#profile-groups-limit', visible: :all)).to be_checked
  88. click '.zammad-switch'
  89. find('#content_permanent_Profile form .btn--primary').click
  90. await_empty_ajax_queue
  91. expect(user.reload.preferences[:notification_config]).not_to have_key(:group_ids)
  92. expect(find('#profile-groups-limit', visible: :all)).not_to be_checked
  93. end
  94. it 'clears limit when all groups are unchecked' do
  95. expect(find('#profile-groups-limit', visible: :all)).to be_checked
  96. expect(page).to have_no_text('Disabling the notifications from all groups will turn off the limit.')
  97. find("input[name='group_ids'][value='#{group_a.id}']", visible: :all).click
  98. expect(page).to have_text('Disabling the notifications from all groups will turn off the limit.')
  99. find('#content_permanent_Profile form .btn--primary').click
  100. await_empty_ajax_queue
  101. expect(user.reload.preferences[:notification_config]).not_to have_key(:group_ids)
  102. expect(find('#profile-groups-limit', visible: :all)).not_to be_checked
  103. end
  104. end
  105. end
  106. end