maintenance_mode_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Login Maintenance Mode', type: :system, authenticated_as: false do
  4. context 'with maintenance_mode' do
  5. def try_login(username, password)
  6. within('#login') do
  7. fill_in 'username', with: username
  8. fill_in 'password', with: password
  9. click_button
  10. end
  11. end
  12. context 'with active maintenance_mode' do
  13. before { Setting.set 'maintenance_mode', true }
  14. it 'shows maintenance mode' do
  15. open_login_page
  16. expect(page).to have_css('.js-maintenanceMode')
  17. try_login('agent1@example.com', 'test')
  18. expect(page).to have_css('#login .alert')
  19. refresh
  20. try_login('nicole.braun@zammad.org', 'test')
  21. expect(page).to have_css('#login .alert')
  22. refresh
  23. try_login('admin@example.com', 'test')
  24. expect(find('.user-menu .user a')[:title]).to eq('admin@example.com')
  25. end
  26. it 'login should work again after deactivation of maintenance mode' do
  27. open_login_page
  28. expect(page).to have_css('.js-maintenanceMode')
  29. try_login('agent1@example.com', 'test')
  30. expect(page).to have_css('#login .alert')
  31. Setting.set 'maintenance_mode', false
  32. expect(page).to have_no_css('.js-maintenanceMode', wait: 30)
  33. try_login('agent1@example.com', 'test')
  34. expect(find('.user-menu .user a')[:title]).to eq('agent1@example.com')
  35. end
  36. end
  37. context 'without maintenance_mode' do
  38. before { Setting.set 'maintenance_mode', false }
  39. it 'does not show message' do
  40. open_login_page
  41. expect(page).to have_no_css('.js-maintenanceMode')
  42. end
  43. it 'shows message on the go' do
  44. open_login_page
  45. Setting.set 'maintenance_mode', true
  46. expect(page).to have_css('.js-maintenanceMode', wait: 30)
  47. end
  48. end
  49. end
  50. def open_login_page
  51. visit '/'
  52. ensure_websocket
  53. end
  54. end