online_notifications_spec.rb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Desktop > Ticket > Online Notifications', app: :desktop_view, authenticated_as: :agent, type: :system do
  4. let(:group) { create(:group) }
  5. let(:agent) { create(:agent, groups: [group]) }
  6. let(:agent_b) { create(:agent, groups: [group]) }
  7. let(:ticket) { create(:ticket, group:, title: 'Ticket A') }
  8. let(:ticket_b) { create(:ticket, group:, title: 'Ticket B') }
  9. let(:online_notification) { create(:online_notification, user: agent, created_by: agent_b, updated_by: agent_b, o: ticket, type_name: 'update') }
  10. let(:online_notification_new_ticket) { create(:online_notification, user: agent, created_by: agent_b, updated_by: agent_b, o: ticket_b, type_name: 'create') }
  11. context 'when receiving a new ticket notification' do
  12. before do
  13. online_notification
  14. visit '/'
  15. # Initial subscription request will fetch the new online notification,
  16. # which is why we must wait for the update flag instead of the start.
  17. wait_for_subscription_update('onlineNotificationsCount', number: 1)
  18. end
  19. it 'receives an online notification' do
  20. expect(find('[aria-label="Unseen notifications count"]')).to have_text('1')
  21. find('button[aria-label="Show notifications"]').click
  22. within('[role="region"]') do
  23. expect(page).to have_text("#{agent_b.fullname} updated ticket Ticket A")
  24. click_on 'mark all as read'
  25. wait_for_mutation('onlineNotificationMarkAllAsSeen')
  26. end
  27. find('button[aria-label="Show notifications"]').click
  28. within('[role="region"]') do
  29. expect(page).to have_css('a', text: "#{agent_b.fullname} updated ticket Ticket A", style: { opacity: '0.3' })
  30. end
  31. find("[aria-label='#{Capybara::Selector::CSS.escape(agent.fullname)}']").click
  32. click_on 'Profile settings'
  33. click_on 'Notifications'
  34. find('label', text: 'New ticket - All tickets').click
  35. find('label', text: 'Ticket update - All tickets').click
  36. click_on 'Save Notifications'
  37. wait_for_mutation('userCurrentNotificationPreferencesUpdate', number: 1)
  38. expect(agent.preferences['notification_config']['matrix']).to include(
  39. 'create' => include(
  40. 'criteria' => include('owned_by_me' => true, 'owned_by_nobody' => true, 'subscribed' => true, 'no' => false),
  41. 'channel' => include('email' => true, 'online' => true)
  42. ),
  43. 'update' => include(
  44. 'criteria' => include('owned_by_me' => true, 'owned_by_nobody' => true, 'subscribed' => true, 'no' => false),
  45. 'channel' => include('email' => true, 'online' => true)
  46. ),
  47. 'reminder_reached' => include(
  48. 'criteria' => include('owned_by_me' => true, 'owned_by_nobody' => false, 'subscribed' => false, 'no' => false),
  49. 'channel' => include('email' => true, 'online' => true)
  50. ),
  51. 'escalation' => include(
  52. 'criteria' => include('owned_by_me' => true, 'owned_by_nobody' => false, 'subscribed' => false, 'no' => false),
  53. 'channel' => include('email' => true, 'online' => true)
  54. )
  55. )
  56. online_notification_new_ticket
  57. wait_for_subscription_update('onlineNotificationsCount', number: 2)
  58. expect(find('[aria-label="Unseen notifications count"]')).to have_text('1')
  59. find('button[aria-label="Show notifications"]').click
  60. within('[role="region"]') do
  61. click_on "#{agent_b.fullname} created ticket Ticket B"
  62. end
  63. wait_for_mutation('onlineNotificationSeen')
  64. wait_for_subscription_update('onlineNotificationsCount', number: 3)
  65. expect(page).to have_current_path("/desktop/tickets/#{ticket_b.id}")
  66. find('button[aria-label="Show notifications"]').click
  67. within('[role="region"]') do
  68. expect(page).to have_css('a', text: "#{agent_b.fullname} created ticket Ticket B", style: { opacity: '0.3' })
  69. end
  70. end
  71. end
  72. end