live_users_spec.rb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > Ticket > Viewers > Live Users', app: :mobile, authenticated_as: :agent, type: :system do
  4. let(:group) { Group.find_by(name: 'Users') }
  5. let(:agent) { create(:agent, groups: [group]) }
  6. let(:another_agent) { create(:agent, groups: [group]) }
  7. let(:third_agent) { create(:agent, groups: [group]) }
  8. let(:customer) { create(:customer) }
  9. let(:ticket) { create(:ticket, customer: customer, group: group) }
  10. def wait_for_viewers_subscription(number: 1)
  11. wait_for_gql('shared/entities/ticket/graphql/subscriptions/ticketLiveUserUpdates.graphql', number: number)
  12. end
  13. def open_viewers_dialog()
  14. visit "/tickets/#{ticket.id}"
  15. wait_for_viewers_subscription
  16. find_button('Show ticket viewers').click
  17. end
  18. def update_taskbar_item(taskbar_item, state, agent_id, number)
  19. # Special case: By design, it is only allowed to update the taskbar of the current user.
  20. # We need to work around this, otherwise this test would fail.
  21. UserInfo.current_user_id = agent_id
  22. taskbar_item.update!(state: state)
  23. UserInfo.current_user_id = agent.id
  24. wait_for_viewers_subscription(number: number)
  25. end
  26. context 'when opening viewers', authenticated_as: :agent do
  27. it 'shows the users currently looking at the ticket' do
  28. taskbar_item = create(:taskbar, user_id: another_agent.id, key: "Ticket-#{ticket.id}", app: 'mobile')
  29. open_viewers_dialog
  30. # No idle viewers.
  31. expect(page).to have_no_text('Opened in tabs')
  32. # One active viewer, without editing.
  33. expect(page)
  34. .to have_text('Viewing ticket')
  35. .and have_no_text(agent.fullname)
  36. .and have_text(another_agent.fullname)
  37. .and have_no_css('.icon.icon-avatar-indicator-editing-mobile')
  38. # Checking pencil icon.
  39. update_taskbar_item(taskbar_item, { editing: true }, another_agent.id, 2)
  40. expect(page).to have_css('.icon.icon-avatar-indicator-editing-mobile')
  41. # Checking idle.
  42. travel_to 10.minutes.ago
  43. update_taskbar_item(taskbar_item, { editing: false }, another_agent.id, 3)
  44. travel_back
  45. expect(page)
  46. .to have_text('Opened in tabs')
  47. .and have_no_text(agent.fullname)
  48. .and have_no_text('Viewing ticket')
  49. .and have_text(another_agent.fullname)
  50. .and have_no_css('.icon.icon-avatar-indicator-editing-mobile')
  51. end
  52. it 'shows the users that start looking at the ticket' do
  53. visit "/tickets/#{ticket.id}"
  54. expect(page).to have_no_button('Show ticket viewers')
  55. taskbar_item = create(:taskbar, user_id: third_agent.id, key: "Ticket-#{ticket.id}", app: 'mobile')
  56. update_taskbar_item(taskbar_item, { editing: true }, third_agent.id, 1)
  57. open_viewers_dialog
  58. expect(page)
  59. .to have_text('Viewing ticket')
  60. .and have_text(third_agent.fullname)
  61. .and have_css('.icon.icon-avatar-indicator-editing-mobile')
  62. end
  63. context 'when editing is started on mobile' do
  64. it 'updates the other session' do
  65. visit "/tickets/#{ticket.id}"
  66. using_session(:customer) do
  67. login(
  68. username: another_agent.login,
  69. password: 'test',
  70. )
  71. visit "/tickets/#{ticket.id}"
  72. end
  73. open_viewers_dialog
  74. expect(page)
  75. .to have_text(another_agent.fullname)
  76. .and have_no_css('.icon.icon-avatar-indicator-editing-mobile')
  77. using_session(:customer) do
  78. visit "/tickets/#{ticket.id}/information"
  79. wait_for_form_to_settle('form-ticket-edit')
  80. within_form(form_updater_gql_number: 1) do
  81. find_input('Ticket title').type('New Title')
  82. end
  83. end
  84. wait_for_viewers_subscription(number: 2)
  85. expect(page)
  86. .to have_text('Viewing ticket')
  87. .and have_text(another_agent.fullname)
  88. .and have_css('.icon.icon-avatar-indicator-editing-mobile')
  89. end
  90. end
  91. context 'when editing is started on desktop' do
  92. it 'updates the other session' do
  93. visit "/tickets/#{ticket.id}"
  94. using_session(:customer) do
  95. login(
  96. username: another_agent.login,
  97. password: 'test',
  98. remember_me: false,
  99. app: :desktop,
  100. )
  101. visit "/#ticket/zoom/#{ticket.id}", app: :desktop
  102. end
  103. open_viewers_dialog
  104. expect(page)
  105. .to have_text(another_agent.fullname)
  106. .and have_no_css('.icon.icon-avatar-indicator-editing-desktop')
  107. using_session(:customer) do
  108. within :active_content, '.tabsSidebar' do
  109. select 'closed', from: 'State'
  110. end
  111. end
  112. wait_for_viewers_subscription(number: 2)
  113. expect(page)
  114. .to have_text('Viewing ticket')
  115. .and have_text(another_agent.fullname)
  116. .and have_css('.icon.icon-avatar-indicator-editing-desktop')
  117. end
  118. end
  119. context 'when current user is using both desktop and mobile' do
  120. it 'shows correct icons' do
  121. visit "/tickets/#{ticket.id}"
  122. using_session(:customer) do
  123. login(
  124. username: agent.login,
  125. password: 'test',
  126. remember_me: false,
  127. app: :desktop,
  128. )
  129. visit "/#ticket/zoom/#{ticket.id}", app: :desktop
  130. within :active_content, '.tabsSidebar' do
  131. select 'closed', from: 'State'
  132. end
  133. end
  134. open_viewers_dialog
  135. expect(page)
  136. .to have_text('Viewing ticket')
  137. .and have_text(agent.fullname)
  138. .and have_css('.icon.icon-avatar-indicator-editing-desktop')
  139. end
  140. end
  141. end
  142. end