dashboard_spec.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # Copyright (C) 2012-2022 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. ensure_websocket(check_if_pinged: false)
  36. sleep 3 # fast relog causes raise conditions in websocket server
  37. end
  38. context 'Logout by frontend plugin - Default', authenticated_as: :authenticate do
  39. def authenticate
  40. Setting.set('session_timeout', { default: '1' })
  41. admin
  42. end
  43. it 'does logout user' do
  44. expect(page).to have_text('Due to inactivity, you will be automatically logged out within the next 30 seconds.')
  45. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  46. end
  47. it 'does not logout user', authenticated_as: :admin do
  48. sleep 1.5
  49. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.', wait: 0)
  50. end
  51. end
  52. context 'Logout by frontend plugin - Setting change', authenticated_as: :admin do
  53. it 'does logout user' do
  54. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.')
  55. Setting.set('session_timeout', { default: '1' })
  56. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  57. end
  58. end
  59. context 'Logout by frontend plugin - Admin', authenticated_as: :authenticate do
  60. def authenticate
  61. Setting.set('session_timeout', { admin: '1', default: '1000' })
  62. admin
  63. end
  64. it 'does logout user' do
  65. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  66. end
  67. end
  68. context 'Logout by frontend plugin - Agent', authenticated_as: :authenticate do
  69. def authenticate
  70. Setting.set('session_timeout', { 'ticket.agent': '1', default: '1000' })
  71. agent
  72. end
  73. it 'does logout user' do
  74. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  75. end
  76. end
  77. context 'Logout by frontend plugin - Customer', authenticated_as: :authenticate do
  78. def authenticate
  79. Setting.set('session_timeout', { 'ticket.customer': '1', default: '1000' })
  80. customer
  81. end
  82. it 'does logout user' do
  83. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  84. end
  85. end
  86. context 'Logout by SessionTimeoutJob - frontend_timeout' do
  87. it 'does logout user', authenticated_as: :admin do
  88. # because of the websocket server running in the same
  89. # process and the checks in the frontend it is really
  90. # hard test the SessionTimeoutJob.perform_now here
  91. # so we only check the session killing code and use
  92. # backend tests for the reset
  93. session = ActiveRecord::SessionStore::Session.all.detect { |s| s.data['user_id'] == admin.id }
  94. SessionTimeoutJob::Session.new(session).frontend_timeout
  95. expect(page).to have_text('Due to inactivity, you have been automatically logged out.')
  96. end
  97. end
  98. context 'Logout by frontend plugin - Fallback from admin to default', authenticated_as: :authenticate do
  99. def authenticate
  100. Setting.set('session_timeout', { admin: '0', default: '1000' })
  101. admin
  102. end
  103. it 'does not logout user', authenticated_as: :admin do
  104. sleep 1.5
  105. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.', wait: 0)
  106. end
  107. end
  108. context 'Logout by frontend plugin - No logout because timeouts are disabled', authenticated_as: :authenticate do
  109. def authenticate
  110. Setting.set('session_timeout', { admin: '0', default: '0' })
  111. admin
  112. end
  113. it 'does not logout user', authenticated_as: :admin do
  114. sleep 1.5
  115. expect(page).to have_no_text('Due to inactivity, you have been automatically logged out.', wait: 0)
  116. end
  117. end
  118. end
  119. end