dashboard_spec.rb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Dashboard', type: :system do
  4. it 'shows default widgets' do
  5. visit 'dashboard'
  6. expect(page).to have_css('.stat-widgets')
  7. expect(page).to have_css('.ticket_waiting_time > div > div.stat-title', text: %r{∅ Waiting time today}i)
  8. expect(page).to have_css('.ticket_escalation > div > div.stat-title', text: %r{Mood}i)
  9. expect(page).to have_css('.ticket_channel_distribution > div > div.stat-title', text: %r{Channel Distribution}i)
  10. expect(page).to have_css('.ticket_load_measure > div > div.stat-title', text: %r{Assigned}i)
  11. expect(page).to have_css('.ticket_in_process > div > div.stat-title', text: %r{My tickets in process}i)
  12. expect(page).to have_css('.ticket_reopen > div > div.stat-title', text: %r{Reopening rate}i)
  13. end
  14. context 'when customer role is named different', authenticated_as: :authenticate do
  15. def authenticate
  16. Role.find_by(name: 'Customer').update(name: 'Public')
  17. true
  18. end
  19. it 'invites a customer user' do
  20. visit 'dashboard'
  21. find('div.tab[data-area=first-steps-widgets]').click
  22. find('.js-inviteCustomer').click
  23. fill_in 'firstname', with: 'Nick'
  24. fill_in 'lastname', with: 'Braun'
  25. fill_in 'Email', with: 'nick.braun@zammad.org'
  26. click_on 'Invite'
  27. expect(User.find_by(firstname: 'Nick').roles).to eq([Role.find_by(name: 'Public')])
  28. end
  29. end
  30. context 'Session Timeout' do
  31. let(:admin) { create(:admin) }
  32. let(:agent) { create(:agent) }
  33. let(:customer) { create(:customer) }
  34. before do
  35. visit '/'
  36. ensure_websocket(check_if_pinged: false)
  37. sleep 3 # fast relog causes raise conditions in websocket server
  38. end
  39. context 'Logout by frontend plugin - Default', authenticated_as: :authenticate do
  40. def authenticate
  41. Setting.set('session_timeout', { default: '1' })
  42. admin
  43. end
  44. it 'does logout user' do
  45. expect(page).to have_text('Due to inactivity, you will be automatically logged out within the next 30 seconds.')
  46. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  47. end
  48. it 'does not logout user', authenticated_as: :admin do
  49. sleep 1.5
  50. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.', wait: 0)
  51. end
  52. end
  53. context 'Logout by frontend plugin - Setting change', authenticated_as: :admin do
  54. it 'does logout user' do
  55. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.')
  56. Setting.set('session_timeout', { default: '1' })
  57. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  58. end
  59. end
  60. context 'Logout by frontend plugin - Admin', authenticated_as: :authenticate do
  61. def authenticate
  62. Setting.set('session_timeout', { admin: '1', default: '1000' })
  63. admin
  64. end
  65. it 'does logout user' do
  66. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  67. end
  68. end
  69. context 'Logout by frontend plugin - Agent', authenticated_as: :authenticate do
  70. def authenticate
  71. Setting.set('session_timeout', { 'ticket.agent': '1', default: '1000' })
  72. agent
  73. end
  74. it 'does logout user' do
  75. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  76. end
  77. end
  78. context 'Logout by frontend plugin - Customer', authenticated_as: :authenticate do
  79. def authenticate
  80. Setting.set('session_timeout', { 'ticket.customer': '1', default: '1000' })
  81. customer
  82. end
  83. it 'does logout user' do
  84. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  85. end
  86. end
  87. context 'Logout by SessionTimeoutJob - frontend_timeout' do
  88. it 'does logout user', authenticated_as: :admin do
  89. # because of the websocket server running in the same
  90. # process and the checks in the frontend it is really
  91. # hard test the SessionTimeoutJob.perform_now here
  92. # so we only check the session killing code and use
  93. # backend tests for the reset
  94. session = ActiveRecord::SessionStore::Session.all.detect { |s| s.data['user_id'] == admin.id }
  95. SessionTimeoutJob::Session.new(session).frontend_timeout
  96. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  97. end
  98. end
  99. context 'Logout by frontend plugin - Fallback from admin to default', authenticated_as: :authenticate do
  100. def authenticate
  101. Setting.set('session_timeout', { admin: '0', default: '1000' })
  102. admin
  103. end
  104. it 'does not logout user', authenticated_as: :admin do
  105. sleep 1.5
  106. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.', wait: 0)
  107. end
  108. end
  109. context 'Logout by frontend plugin - No logout because timeouts are disabled', authenticated_as: :authenticate do
  110. def authenticate
  111. Setting.set('session_timeout', { admin: '0', default: '0' })
  112. admin
  113. end
  114. it 'does not logout user', authenticated_as: :admin do
  115. sleep 1.5
  116. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.', wait: 0)
  117. end
  118. end
  119. end
  120. end