From fa8588855c07fe130cc3dfeaf08346c2399185a7 Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Fri, 8 Oct 2021 12:34:31 +0200 Subject: [PATCH] Maintenance: Port maintenance session message test to capybara. (cherry picked from commit 22cd8f33769453cb325b7971cf3a7f651a96e730) --- script/build/test_slice_tests.sh | 6 - .../maintenance/app_version_spec.rb} | 10 +- .../maintenance/session_message_spec.rb | 78 ++++++++ .../maintenance_session_message_test.rb | 181 ------------------ 4 files changed, 85 insertions(+), 190 deletions(-) rename spec/system/{maintenance_app_version_spec.rb => system/maintenance/app_version_spec.rb} (60%) create mode 100644 spec/system/system/maintenance/session_message_spec.rb delete mode 100644 test/browser/maintenance_session_message_test.rb diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 11e68e141..3e5a5646f 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -50,7 +50,6 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/first_steps_test.rb rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb - # test/browser/maintenance_session_message_test.rb # test/browser/manage_test.rb # test/browser/monitoring_test.rb rm test/browser/integration_sipgate_test.rb @@ -107,7 +106,6 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/first_steps_test.rb rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb - rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb rm test/browser/monitoring_test.rb rm test/browser/integration_sipgate_test.rb @@ -164,7 +162,6 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/first_steps_test.rb rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb - rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb rm test/browser/monitoring_test.rb rm test/browser/integration_sipgate_test.rb @@ -221,7 +218,6 @@ elif [ "$LEVEL" == '4' ]; then rm test/browser/first_steps_test.rb rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb - rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb rm test/browser/monitoring_test.rb rm test/browser/integration_sipgate_test.rb @@ -277,7 +273,6 @@ elif [ "$LEVEL" == '5' ]; then rm test/browser/first_steps_test.rb rm test/browser/integration_test.rb rm test/browser/keyboard_shortcuts_test.rb - rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb rm test/browser/monitoring_test.rb rm test/browser/integration_sipgate_test.rb @@ -336,7 +331,6 @@ elif [ "$LEVEL" == '6' ]; then # test/browser/first_steps_test.rb # test/browser/integration_test.rb # test/browser/keyboard_shortcuts_test.rb - rm test/browser/maintenance_session_message_test.rb rm test/browser/manage_test.rb rm test/browser/monitoring_test.rb # rm test/browser/integration_sipgate_test.rb diff --git a/spec/system/maintenance_app_version_spec.rb b/spec/system/system/maintenance/app_version_spec.rb similarity index 60% rename from spec/system/maintenance_app_version_spec.rb rename to spec/system/system/maintenance/app_version_spec.rb index 35561f4e0..7cba49e35 100644 --- a/spec/system/maintenance_app_version_spec.rb +++ b/spec/system/system/maintenance/app_version_spec.rb @@ -2,14 +2,18 @@ require 'rails_helper' -RSpec.describe 'Maintenance App Version', type: :system do - it 'check that new version is present' do +RSpec.describe 'System > Maintenance - App Version', type: :system do + it 'check that new version modal dialog is present' do page.execute_script 'App.Event.trigger("maintenance", {type:"app_version", app_version:"1234:false"} )' expect(page).to have_no_text('new version') page.execute_script 'App.Event.trigger("maintenance", {type:"app_version", app_version:"1234:true"} )' - expect(page).to have_text('new version') + modal_ready(timeout: 10) + + within '.modal-dialog' do + expect(page).to have_text('new version') + end end end diff --git a/spec/system/system/maintenance/session_message_spec.rb b/spec/system/system/maintenance/session_message_spec.rb new file mode 100644 index 000000000..3e6747580 --- /dev/null +++ b/spec/system/system/maintenance/session_message_spec.rb @@ -0,0 +1,78 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'System > Maintenance - Session Message', type: :system do + let(:agent) { User.find_by(login: 'agent1@example.com') } + let(:session_message_title) { 'Testing Session Message Title' } + let(:session_message_text) { "message 1äöüß Session Message Title\n\n\nhttps://zammad.org" } + + def check_sesion_message_content(title, text) + expect(page).to have_text(title) + expect(page).to have_text(text) + end + + context 'when maintenance session message is used and a open session exists' do + before do + using_session(:second_browser) do + login( + username: agent.login, + password: 'test', + ) + end + end + + it 'check that the maintenance session message appears' do + visit 'system/maintenance' + + within :active_content do + fill_in 'head', with: session_message_title + find('.js-Message .js-textarea[data-name="message"]').send_keys(session_message_text) + + click '.js-Message button.js-submit' + end + + using_session(:second_browser) do + modal_ready + + within '.modal-dialog' do + check_sesion_message_content(session_message_title, session_message_text) + + click 'div.modal-header .js-close' + end + + modal_disappear + end + + within :active_content do + expect(page).to have_no_text(session_message_title) + expect(page).to have_no_text(session_message_text) + end + end + + it 'check that the maintenance session message appears with browser reload' do + message_title = "#{session_message_title} #2" + message_text = "#{session_message_text} #2" + + visit 'system/maintenance' + + within :active_content do + fill_in 'head', with: "#{message_title} #2" + find('.js-Message .js-textarea[data-name="message"]').send_keys("#{message_text} #2") + check 'reload', { allow_label_click: true } + + click '.js-Message button.js-submit' + end + + using_session(:second_browser) do + modal_ready + + within '.modal-dialog' do + check_sesion_message_content(message_title, message_text) + + expect(page).to have_text('Continue session') + end + end + end + end +end diff --git a/test/browser/maintenance_session_message_test.rb b/test/browser/maintenance_session_message_test.rb deleted file mode 100644 index 3363823a6..000000000 --- a/test/browser/maintenance_session_message_test.rb +++ /dev/null @@ -1,181 +0,0 @@ -# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ - -require 'browser_test_helper' - -class MaintenanceSessionMessageTest < TestCase - def test_message - string = SecureRandom.uuid - title_html = "test #{string}" - title_text = "test #{string}<\/b>" - message_html = "message 1äöüß #{string}\n\n\nhttps://zammad.org" - message_text = "message 1äöüß #{string}\n\n\nhttps://zammad.org" - - # check #1 - browser1 = browser_instance - login( - browser: browser1, - username: 'admin@example.com', - password: 'test', - url: browser_url, - ) - - browser2 = browser_instance - login( - browser: browser2, - username: 'agent1@example.com', - password: 'test', - url: browser_url, - ) - click( - browser: browser1, - css: 'a[href="#manage"]', - ) - click( - browser: browser1, - css: 'a[href="#system/maintenance"]', - ) - - set( - browser: browser1, - css: '.content.active .js-Message input[name="head"]', - value: title_html, - ) - set( - browser: browser1, - css: '.content.active .js-Message .js-textarea[data-name="message"]', - value: message_html, - ) - - click( - browser: browser1, - css: '.content.active .js-Message button.js-submit', - ) - - modal_ready(browser: browser2) - watch_for( - browser: browser2, - css: '.modal', - value: title_text, - ) - watch_for( - browser: browser2, - css: '.modal', - value: message_text, - ) - - match_not( - browser: browser1, - css: 'body', - value: message_text, - ) - - click( - browser: browser2, - css: 'div.modal-header .js-close', - ) - modal_disappear(browser: browser2) - - # check #2 - click( - browser: browser1, - css: 'a[href="#manage"]', - ) - click( - browser: browser1, - css: 'a[href="#system/maintenance"]', - ) - - set( - browser: browser1, - css: '.content.active .js-Message input[name="head"]', - value: "#{title_html} #2", - ) - set( - browser: browser1, - css: '.content.active .js-Message .js-textarea[data-name="message"]', - value: "#{message_html} #2", - ) - - click( - browser: browser1, - css: '.content.active .js-Message button.js-submit', - ) - - modal_ready(browser: browser2) - watch_for( - browser: browser2, - css: '.modal', - value: "#{title_text} #2", - ) - watch_for( - browser: browser2, - css: '.modal', - value: "#{message_text} #2", - ) - - match_not( - browser: browser1, - css: 'body', - value: message_text, - ) - - click( - browser: browser2, - css: 'div.modal-header .js-close', - ) - modal_disappear(browser: browser2) - - # check #3 - click( - browser: browser1, - css: 'a[href="#manage"]', - ) - click( - browser: browser1, - css: 'a[href="#system/maintenance"]', - ) - - set( - browser: browser1, - css: '.content.active .js-Message input[name="head"]', - value: "#{title_html} #3", - ) - set( - browser: browser1, - css: '.content.active .js-Message .js-textarea[data-name="message"]', - value: "#{message_html} #3", - ) - click( - browser: browser1, - css: '.content.active .js-Message input[name="reload"]', - ) - click( - browser: browser1, - css: '.content.active .js-Message button.js-submit', - ) - - modal_ready(browser: browser2) - watch_for( - browser: browser2, - css: '.modal', - value: "#{title_text} #3", - ) - watch_for( - browser: browser2, - css: '.modal', - value: "#{message_text} #3", - ) - watch_for( - browser: browser2, - css: '.modal', - value: 'Continue session', - ) - - match_not( - browser: browser1, - css: 'body', - value: message_text, - ) - end - -end