message_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Login Message', type: :system, authenticated_as: false do
  4. context 'with maintenance_login_message' do
  5. let(:message) { "badum tssss #{SecureRandom.uuid}" }
  6. let(:alt_message) { 'lorem ipsum' }
  7. before { Setting.set 'maintenance_login_message', message }
  8. context 'with maintenance_login' do
  9. before { Setting.set 'maintenance_login', true }
  10. it 'shows message' do
  11. open_login_page
  12. expect(page).to have_css('.js-maintenanceLogin', text: message)
  13. end
  14. it 'hides message on the go' do
  15. open_login_page
  16. expect(page).to have_css('.js-maintenanceLogin', text: message)
  17. Setting.set 'maintenance_login', false
  18. expect(page).to have_no_css('.js-maintenanceLogin', text: message, wait: 30)
  19. end
  20. it 'changes message text on the go' do
  21. open_login_page
  22. expect(page).to have_css('.js-maintenanceLogin', text: message)
  23. Setting.set 'maintenance_login_message', alt_message
  24. expect(page).to have_css('.js-maintenanceLogin', text: alt_message, wait: 30)
  25. end
  26. end
  27. context 'without maintenance_login' do
  28. before { Setting.set 'maintenance_login', false }
  29. it 'does not show message' do
  30. open_login_page
  31. expect(page).to have_no_text(message)
  32. end
  33. it 'shows message on the go' do
  34. open_login_page
  35. Setting.set 'maintenance_login', true
  36. expect(page).to have_css('.js-maintenanceLogin', text: message, wait: 30)
  37. end
  38. end
  39. end
  40. def open_login_page
  41. visit '/'
  42. ensure_websocket
  43. # Wait until the event binding for the 'config_update_local' is present.
  44. # TODO: If this works we can maybe move the check for event bindings in a helper function.
  45. wait.until do
  46. page.evaluate_script("Object.keys(App.Event._allBindings()).find((key) => {
  47. return App.Event._allBindings()[key].filter((item) => {
  48. return item.event === 'config_update_local' || item.event === 'ui:rerender';
  49. }).length === 2;
  50. })")
  51. end
  52. end
  53. end