dashboard_spec.rb 5.2 KB

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