maintenance_mode_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Login Maintenance Mode', authenticated_as: false, type: :system 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_on 'Sign in'
  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. await_empty_ajax_queue
  47. expect(page).to have_css('.js-maintenanceMode', wait: 30)
  48. end
  49. end
  50. end
  51. def open_login_page
  52. visit '/'
  53. ensure_websocket
  54. end
  55. end