diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 0e2ffae2a..94c3db6b8 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -66,7 +66,6 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb # test/browser/maintenance_app_version_test.rb - # test/browser/maintenance_login_message_test.rb # test/browser/maintenance_mode_test.rb # test/browser/maintenance_session_message_test.rb # test/browser/manage_test.rb @@ -147,7 +146,6 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb rm test/browser/maintenance_app_version_test.rb - rm test/browser/maintenance_login_message_test.rb rm test/browser/maintenance_mode_test.rb rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb @@ -228,7 +226,6 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb rm test/browser/maintenance_app_version_test.rb - rm test/browser/maintenance_login_message_test.rb rm test/browser/maintenance_mode_test.rb rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb @@ -309,7 +306,6 @@ elif [ "$LEVEL" == '4' ]; then rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb rm test/browser/maintenance_app_version_test.rb - rm test/browser/maintenance_login_message_test.rb rm test/browser/maintenance_mode_test.rb rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb @@ -389,7 +385,6 @@ elif [ "$LEVEL" == '5' ]; then rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb rm test/browser/maintenance_app_version_test.rb - rm test/browser/maintenance_login_message_test.rb rm test/browser/maintenance_mode_test.rb rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb @@ -472,7 +467,6 @@ elif [ "$LEVEL" == '6' ]; then # test/browser/integration_test.rb # test/browser/keyboard_shortcuts_test.rb rm test/browser/maintenance_app_version_test.rb - rm test/browser/maintenance_login_message_test.rb rm test/browser/maintenance_mode_test.rb rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb diff --git a/spec/system/admin/maintenance/login_message_spec.rb b/spec/system/admin/maintenance/login_message_spec.rb new file mode 100644 index 000000000..e0550e9a0 --- /dev/null +++ b/spec/system/admin/maintenance/login_message_spec.rb @@ -0,0 +1,62 @@ +require 'rails_helper' + +RSpec.describe 'Admin > Maintenance login message', type: :system do + it 'switch maintenance_login on' do + Setting.set 'maintenance_login', false + + open_page + + find('.js-loginSetting label').click + find('.js-loginSetting input', visible: :all).check # required for chrome + + wait(10).until { expect(Setting.get('maintenance_login')).to be true } + end + + it 'switch maintenance_login off' do + Setting.set 'maintenance_login', true + + open_page + + find('.js-loginSetting label').click + find('.js-loginSetting input', visible: :all).uncheck # required for chrome + + wait(10).until { expect(Setting.get('maintenance_login')).to be false } + end + + it 'shows current maintenance_login_message' do + message = "badum tssss #{rand(99_999)}" + + Setting.set 'maintenance_login_message', message + + open_page + + expect(find('.js-loginPreview [data-name="message"]')).to have_text message + end + + it 'saves new maintenance_login_message' do + message_prefix = 'badum' + message_suffix = "tssss#{rand(99_999)}" + + Setting.set 'maintenance_login_message', message_prefix + + open_page + + within(:active_content) do + elem = find('#maintenance-message.hero-unit') + elem.click + elem.send_keys message_suffix + elem.execute_script "$(this).trigger('blur')" # required for chrome + end + + find('#global-search').click # unfocus + + wait(10).until { expect(Setting.get('maintenance_login_message')).to eq "#{message_prefix}#{message_suffix}" } + end + + def open_page + refresh # make sure initial Setting are applied + + click(:manage) + click(:href, '#system/maintenance') + end +end diff --git a/spec/system/login/message_spec.rb b/spec/system/login/message_spec.rb new file mode 100644 index 000000000..d9b80ad8f --- /dev/null +++ b/spec/system/login/message_spec.rb @@ -0,0 +1,86 @@ +require 'rails_helper' + +RSpec.describe 'Login Message', type: :system, authenticated: false do + context 'with maintenance_login_message' do + let(:message) { "badum tssss #{rand(99_999)}" } + let(:alt_message) { 'lorem ipsum' } + + before { Setting.set 'maintenance_login_message', message } + + context 'with maintenance_login' do + before { Setting.set 'maintenance_login', true } + + it 'shows message' do + open_login_page + + expect(page).to have_text(message) + end + + it 'hides message on the go' do + open_login_page + + Setting.set 'maintenance_login', false + + wait(10).until_disappears { find '.js-maintenanceLogin', text: message } + + expect(page).not_to have_css('.js-maintenanceLogin') + end + + it 'changes message text on the go' do + open_login_page + + Setting.set 'maintenance_login_message', alt_message + + wait(10).until_exists { find '.js-maintenanceLogin', text: alt_message } + + expect(page).to have_css('.js-maintenanceLogin', text: alt_message) + end + end + + context 'without maintenance_login' do + before { Setting.set 'maintenance_login', false } + + it 'does not show message' do + open_login_page + + expect(page).not_to have_text(message) + end + + it 'shows message on the go' do + open_login_page + + Setting.set 'maintenance_login', true + + wait(10).until_exists { find '.js-maintenanceLogin', text: message } + + expect(page).to have_css('.js-maintenanceLogin', text: message) + end + end + end + + def open_login_page + timestamp = Time.zone.now.to_i + + visit '/' + + wait(5).until do + pinged_since?(timestamp) && connection_open? + end + + true + end + + def pinged_since?(timestamp) + Sessions + .list + .values + .map { |elem| elem.dig(:meta, :last_ping) } + .any? { |elem| elem >= timestamp } + end + + def connection_open? + page + .evaluate_script('App.WebSocket.channel()') + .present? + end +end diff --git a/test/browser/maintenance_login_message_test.rb b/test/browser/maintenance_login_message_test.rb deleted file mode 100644 index 3930bf397..000000000 --- a/test/browser/maintenance_login_message_test.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'browser_test_helper' - -class MaintenanceLoginMessageTest < TestCase - - def test_login_message - browser1 = browser_instance - login( - browser: browser1, - username: 'master@example.com', - password: 'test', - url: browser_url, - ) - - click( - browser: browser1, - css: 'a[href="#manage"]', - ) - click( - browser: browser1, - css: 'a[href="#system/maintenance"]', - ) - - string = rand(99_999_999_999_999_999).to_s - message = "test #{string}" - set( - browser: browser1, - css: '.content.active .js-loginPreview [data-name="message"]', - value: message, - ) - click( - browser: browser1, - css: '#global-search', - ) - - browser2 = browser_instance - location( - browser: browser2, - url: browser_url, - ) - watch_for( - browser: browser2, - css: '.login', - ) - exists_not( - browser: browser2, - css: '.js-maintenanceLogin', - ) - - switch( - browser: browser1, - css: '.content.active .js-loginSetting', - type: 'on', - ) - - watch_for( - browser: browser2, - css: '.js-maintenanceLogin', - value: message - ) - - switch( - browser: browser1, - css: '.content.active .js-loginSetting', - type: 'off', - ) - - watch_for_disappear( - browser: browser2, - css: '.js-maintenanceLogin', - timeout: 30, - ) - end - -end