dashboard_spec.rb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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: /∅ Waiting time today/i)
  7. expect(page).to have_css('.ticket_escalation > div > div.stat-title', text: /Mood/i)
  8. expect(page).to have_css('.ticket_channel_distribution > div > div.stat-title', text: /Channel Distribution/i)
  9. expect(page).to have_css('.ticket_load_measure > div > div.stat-title', text: /Assigned/i)
  10. expect(page).to have_css('.ticket_in_process > div > div.stat-title', text: /Your tickets in process/i)
  11. expect(page).to have_css('.ticket_reopen > div > div.stat-title', text: /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('Sign in', wait: 15)
  44. end
  45. it 'does not logout user', authenticated_as: :admin do
  46. sleep 1.5
  47. expect(page).to have_no_text('Sign in', wait: 0)
  48. end
  49. end
  50. context 'Logout by frontend plugin - Setting change', authenticated_as: :admin do
  51. it 'does logout user' do
  52. expect(page).to have_no_text('Sign in')
  53. Setting.set('session_timeout', { default: '1' })
  54. expect(page).to have_text('Sign in', wait: 15)
  55. end
  56. end
  57. context 'Logout by frontend plugin - Admin', authenticated_as: :authenticate do
  58. def authenticate
  59. Setting.set('session_timeout', { admin: '1', default: '1000' })
  60. admin
  61. end
  62. it 'does logout user' do
  63. expect(page).to have_text('Sign in', wait: 15)
  64. end
  65. end
  66. context 'Logout by frontend plugin - Agent', authenticated_as: :authenticate do
  67. def authenticate
  68. Setting.set('session_timeout', { 'ticket.agent': '1', default: '1000' })
  69. agent
  70. end
  71. it 'does logout user' do
  72. expect(page).to have_text('Sign in', wait: 15)
  73. end
  74. end
  75. context 'Logout by frontend plugin - Customer', authenticated_as: :authenticate do
  76. def authenticate
  77. Setting.set('session_timeout', { 'ticket.customer': '1', default: '1000' })
  78. customer
  79. end
  80. it 'does logout user' do
  81. expect(page).to have_text('Sign in', wait: 15)
  82. end
  83. end
  84. context 'Logout by SessionTimeoutJob - destroy_session' do
  85. it 'does logout user', authenticated_as: :admin do
  86. # because of the websocket server running in the same
  87. # process and the checks in the frontend it is really
  88. # hard test the SessionTimeoutJob.perform_now here
  89. # so we only check the session killing code and use
  90. # backend tests for the rest
  91. session = ActiveRecord::SessionStore::Session.all.detect { |s| s.data['user_id'] == admin.id }
  92. SessionTimeoutJob.destroy_session(admin, session)
  93. expect(page).to have_text('Sign in', wait: 15)
  94. end
  95. end
  96. end
  97. end