Maintenance: Ported maintenance mode test to capybara to increase the test stabilization.
This commit is contained in:
parent
edcb483b85
commit
decf868823
4 changed files with 177 additions and 214 deletions
|
@ -60,7 +60,6 @@ if [ "$LEVEL" == '1' ]; then
|
||||||
rm test/browser/integration_test.rb
|
rm test/browser/integration_test.rb
|
||||||
rm test/browser/keyboard_shortcuts_test.rb
|
rm test/browser/keyboard_shortcuts_test.rb
|
||||||
# test/browser/maintenance_app_version_test.rb
|
# test/browser/maintenance_app_version_test.rb
|
||||||
# test/browser/maintenance_mode_test.rb
|
|
||||||
# test/browser/maintenance_session_message_test.rb
|
# test/browser/maintenance_session_message_test.rb
|
||||||
# test/browser/manage_test.rb
|
# test/browser/manage_test.rb
|
||||||
# test/browser/monitoring_test.rb
|
# test/browser/monitoring_test.rb
|
||||||
|
@ -133,7 +132,6 @@ elif [ "$LEVEL" == '2' ]; then
|
||||||
rm test/browser/integration_test.rb
|
rm test/browser/integration_test.rb
|
||||||
rm test/browser/keyboard_shortcuts_test.rb
|
rm test/browser/keyboard_shortcuts_test.rb
|
||||||
rm test/browser/maintenance_app_version_test.rb
|
rm test/browser/maintenance_app_version_test.rb
|
||||||
rm test/browser/maintenance_mode_test.rb
|
|
||||||
rm test/browser/maintenance_session_message_test.rb
|
rm test/browser/maintenance_session_message_test.rb
|
||||||
rm test/browser/manage_test.rb
|
rm test/browser/manage_test.rb
|
||||||
rm test/browser/monitoring_test.rb
|
rm test/browser/monitoring_test.rb
|
||||||
|
@ -206,7 +204,6 @@ elif [ "$LEVEL" == '3' ]; then
|
||||||
rm test/browser/integration_test.rb
|
rm test/browser/integration_test.rb
|
||||||
rm test/browser/keyboard_shortcuts_test.rb
|
rm test/browser/keyboard_shortcuts_test.rb
|
||||||
rm test/browser/maintenance_app_version_test.rb
|
rm test/browser/maintenance_app_version_test.rb
|
||||||
rm test/browser/maintenance_mode_test.rb
|
|
||||||
rm test/browser/maintenance_session_message_test.rb
|
rm test/browser/maintenance_session_message_test.rb
|
||||||
rm test/browser/manage_test.rb
|
rm test/browser/manage_test.rb
|
||||||
rm test/browser/monitoring_test.rb
|
rm test/browser/monitoring_test.rb
|
||||||
|
@ -279,7 +276,6 @@ elif [ "$LEVEL" == '4' ]; then
|
||||||
rm test/browser/integration_test.rb
|
rm test/browser/integration_test.rb
|
||||||
rm test/browser/keyboard_shortcuts_test.rb
|
rm test/browser/keyboard_shortcuts_test.rb
|
||||||
rm test/browser/maintenance_app_version_test.rb
|
rm test/browser/maintenance_app_version_test.rb
|
||||||
rm test/browser/maintenance_mode_test.rb
|
|
||||||
rm test/browser/maintenance_session_message_test.rb
|
rm test/browser/maintenance_session_message_test.rb
|
||||||
rm test/browser/manage_test.rb
|
rm test/browser/manage_test.rb
|
||||||
rm test/browser/monitoring_test.rb
|
rm test/browser/monitoring_test.rb
|
||||||
|
@ -351,7 +347,6 @@ elif [ "$LEVEL" == '5' ]; then
|
||||||
rm test/browser/integration_test.rb
|
rm test/browser/integration_test.rb
|
||||||
rm test/browser/keyboard_shortcuts_test.rb
|
rm test/browser/keyboard_shortcuts_test.rb
|
||||||
rm test/browser/maintenance_app_version_test.rb
|
rm test/browser/maintenance_app_version_test.rb
|
||||||
rm test/browser/maintenance_mode_test.rb
|
|
||||||
rm test/browser/maintenance_session_message_test.rb
|
rm test/browser/maintenance_session_message_test.rb
|
||||||
rm test/browser/manage_test.rb
|
rm test/browser/manage_test.rb
|
||||||
rm test/browser/monitoring_test.rb
|
rm test/browser/monitoring_test.rb
|
||||||
|
@ -426,7 +421,6 @@ elif [ "$LEVEL" == '6' ]; then
|
||||||
# test/browser/integration_test.rb
|
# test/browser/integration_test.rb
|
||||||
# test/browser/keyboard_shortcuts_test.rb
|
# test/browser/keyboard_shortcuts_test.rb
|
||||||
rm test/browser/maintenance_app_version_test.rb
|
rm test/browser/maintenance_app_version_test.rb
|
||||||
rm test/browser/maintenance_mode_test.rb
|
|
||||||
rm test/browser/maintenance_session_message_test.rb
|
rm test/browser/maintenance_session_message_test.rb
|
||||||
rm test/browser/manage_test.rb
|
rm test/browser/manage_test.rb
|
||||||
rm test/browser/monitoring_test.rb
|
rm test/browser/monitoring_test.rb
|
||||||
|
|
84
spec/system/login/maintenance_mode_spec.rb
Normal file
84
spec/system/login/maintenance_mode_spec.rb
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'Login Maintenance Mode', type: :system, authenticated_as: false do
|
||||||
|
context 'with maintenance_mode' do
|
||||||
|
def try_login(username, password)
|
||||||
|
within('#login') do
|
||||||
|
fill_in 'username', with: username
|
||||||
|
fill_in 'password', with: password
|
||||||
|
|
||||||
|
click_button
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with active maintenance_mode' do
|
||||||
|
before { Setting.set 'maintenance_mode', true }
|
||||||
|
|
||||||
|
it 'shows maintenance mode' do
|
||||||
|
open_login_page
|
||||||
|
|
||||||
|
expect(page).to have_css('.js-maintenanceMode')
|
||||||
|
|
||||||
|
try_login('agent1@example.com', 'test')
|
||||||
|
|
||||||
|
expect(page).to have_css('#login .alert')
|
||||||
|
|
||||||
|
refresh
|
||||||
|
|
||||||
|
try_login('nicole.braun@zammad.org', 'test')
|
||||||
|
|
||||||
|
expect(page).to have_css('#login .alert')
|
||||||
|
|
||||||
|
refresh
|
||||||
|
|
||||||
|
try_login('admin@example.com', 'test')
|
||||||
|
|
||||||
|
expect(find('.user-menu .user a')[:title]).to eq('admin@example.com')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'login should work again after deactivation of maintenance mode' do
|
||||||
|
open_login_page
|
||||||
|
|
||||||
|
expect(page).to have_css('.js-maintenanceMode')
|
||||||
|
|
||||||
|
try_login('agent1@example.com', 'test')
|
||||||
|
|
||||||
|
expect(page).to have_css('#login .alert')
|
||||||
|
|
||||||
|
Setting.set 'maintenance_mode', false
|
||||||
|
|
||||||
|
expect(page).to have_no_css('.js-maintenanceMode')
|
||||||
|
|
||||||
|
try_login('agent1@example.com', 'test')
|
||||||
|
|
||||||
|
expect(find('.user-menu .user a')[:title]).to eq('agent1@example.com')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without maintenance_mode' do
|
||||||
|
before { Setting.set 'maintenance_mode', false }
|
||||||
|
|
||||||
|
it 'does not show message' do
|
||||||
|
open_login_page
|
||||||
|
|
||||||
|
expect(page).to have_no_css('.js-maintenanceMode')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows message on the go' do
|
||||||
|
open_login_page
|
||||||
|
|
||||||
|
Setting.set 'maintenance_mode', true
|
||||||
|
|
||||||
|
expect(page).to have_css('.js-maintenanceMode')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def open_login_page
|
||||||
|
visit '/'
|
||||||
|
|
||||||
|
ensure_websocket
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,49 +3,57 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'Manage > Maintenance', type: :system do
|
RSpec.describe 'Manage > Maintenance', type: :system do
|
||||||
|
context 'when maintenance login is used' do
|
||||||
|
context 'when maintenance login will be activated', authenticated_as: :authenticate do
|
||||||
|
def authenticate
|
||||||
|
Setting.set('maintenance_login', false)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
it 'switch maintenance_login on' do
|
it 'switch maintenance_login on' do
|
||||||
Setting.set 'maintenance_login', false
|
|
||||||
|
|
||||||
visit 'system/maintenance'
|
visit 'system/maintenance'
|
||||||
refresh # ensure changed Setting is loaded
|
|
||||||
|
|
||||||
find('.js-loginSetting label').click
|
click '.js-loginSetting label'
|
||||||
find('.js-loginSetting input', visible: :all).check # required for chrome
|
|
||||||
|
|
||||||
wait(10).until { expect(Setting.get('maintenance_login')).to be true }
|
wait(10).until { expect(Setting.get('maintenance_login')).to be true }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when maintenance login will be deactiavted', authenticated_as: :authenticate do
|
||||||
|
def authenticate
|
||||||
|
Setting.set('maintenance_login', true)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
it 'switch maintenance_login off' do
|
it 'switch maintenance_login off' do
|
||||||
Setting.set 'maintenance_login', true
|
|
||||||
|
|
||||||
visit 'system/maintenance'
|
visit 'system/maintenance'
|
||||||
refresh # ensure changed Setting is loaded
|
|
||||||
|
|
||||||
find('.js-loginSetting label').click
|
click '.js-loginSetting label'
|
||||||
find('.js-loginSetting input', visible: :all).uncheck # required for chrome
|
|
||||||
|
|
||||||
wait(10).until { expect(Setting.get('maintenance_login')).to be false }
|
wait(10).until { expect(Setting.get('maintenance_login')).to be false }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when maintenance login message will be used', authenticated_as: :authenticate do
|
||||||
|
def message
|
||||||
|
@message ||= "badum tssss #{rand(99_999)}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def authenticate
|
||||||
|
Setting.set('maintenance_login_message', message)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
it 'shows current maintenance_login_message' do
|
it 'shows current maintenance_login_message' do
|
||||||
message = "badum tssss #{rand(99_999)}"
|
|
||||||
|
|
||||||
Setting.set 'maintenance_login_message', message
|
|
||||||
|
|
||||||
visit 'system/maintenance'
|
visit 'system/maintenance'
|
||||||
refresh # ensure changed Setting is loaded
|
|
||||||
|
|
||||||
expect(find('.js-loginPreview [data-name="message"]')).to have_text message
|
expect(find('.js-loginPreview [data-name="message"]')).to have_text message
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'saves new maintenance_login_message' do
|
it 'saves new maintenance_login_message' do
|
||||||
message_prefix = 'badum'
|
|
||||||
message_suffix = "tssss#{rand(99_999)}"
|
message_suffix = "tssss#{rand(99_999)}"
|
||||||
|
|
||||||
Setting.set 'maintenance_login_message', message_prefix
|
|
||||||
|
|
||||||
visit 'system/maintenance'
|
visit 'system/maintenance'
|
||||||
refresh # ensure changed Setting is loaded
|
|
||||||
|
|
||||||
within(:active_content) do
|
within(:active_content) do
|
||||||
elem = find('#maintenance-message.hero-unit')
|
elem = find('#maintenance-message.hero-unit')
|
||||||
|
@ -56,6 +64,43 @@ RSpec.describe 'Manage > Maintenance', type: :system do
|
||||||
|
|
||||||
find('#global-search').click # unfocus
|
find('#global-search').click # unfocus
|
||||||
|
|
||||||
wait(10).until { expect(Setting.get('maintenance_login_message')).to eq "#{message_prefix}#{message_suffix}" }
|
wait(10).until { expect(Setting.get('maintenance_login_message')).to eq "#{message}#{message_suffix}" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when maintenance mode is used' do
|
||||||
|
context 'when maintenance mode will be activated', authenticated_as: :authenticate do
|
||||||
|
def authenticate
|
||||||
|
Setting.set('maintenance_mode', false)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'switch maintenance_mode on' do
|
||||||
|
visit 'system/maintenance'
|
||||||
|
|
||||||
|
click '.js-modeSetting label'
|
||||||
|
modal_ready
|
||||||
|
click '.content.active .modal .js-submit'
|
||||||
|
modal_disappear
|
||||||
|
|
||||||
|
wait(10).until { expect(Setting.get('maintenance_mode')).to be true }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when maintenance mode will be deactiavted', authenticated_as: :authenticate do
|
||||||
|
def authenticate
|
||||||
|
Setting.set('maintenance_mode', true)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'switch maintenance_mode off' do
|
||||||
|
visit 'system/maintenance'
|
||||||
|
|
||||||
|
click '.js-modeSetting label'
|
||||||
|
|
||||||
|
wait(10).until { expect(Setting.get('maintenance_mode')).to be false }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,160 +0,0 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
||||||
|
|
||||||
require 'browser_test_helper'
|
|
||||||
|
|
||||||
class MaintenanceModeTest < TestCase
|
|
||||||
|
|
||||||
def test_mode
|
|
||||||
browser1 = browser_instance
|
|
||||||
login(
|
|
||||||
browser: browser1,
|
|
||||||
username: 'admin@example.com',
|
|
||||||
password: 'test',
|
|
||||||
url: browser_url,
|
|
||||||
)
|
|
||||||
|
|
||||||
browser2 = browser_instance
|
|
||||||
location(
|
|
||||||
browser: browser2,
|
|
||||||
url: browser_url,
|
|
||||||
)
|
|
||||||
click(
|
|
||||||
browser: browser1,
|
|
||||||
css: 'a[href="#manage"]',
|
|
||||||
)
|
|
||||||
click(
|
|
||||||
browser: browser1,
|
|
||||||
css: 'a[href="#system/maintenance"]',
|
|
||||||
)
|
|
||||||
|
|
||||||
watch_for_disappear(
|
|
||||||
browser: browser2,
|
|
||||||
css: '.js-maintenanceMode',
|
|
||||||
)
|
|
||||||
|
|
||||||
switch(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .js-modeSetting',
|
|
||||||
type: 'on',
|
|
||||||
no_check: true,
|
|
||||||
)
|
|
||||||
|
|
||||||
# check warning
|
|
||||||
modal_ready(browser: browser1)
|
|
||||||
click(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .modal .js-submit',
|
|
||||||
)
|
|
||||||
modal_disappear(browser: browser1)
|
|
||||||
|
|
||||||
watch_for(
|
|
||||||
browser: browser2,
|
|
||||||
css: '.js-maintenanceMode',
|
|
||||||
)
|
|
||||||
|
|
||||||
# try to logon with normal agent, should not work
|
|
||||||
login(
|
|
||||||
browser: browser2,
|
|
||||||
username: 'agent1@example.com',
|
|
||||||
password: 'test',
|
|
||||||
url: browser_url,
|
|
||||||
success: false,
|
|
||||||
)
|
|
||||||
login(
|
|
||||||
browser: browser2,
|
|
||||||
username: 'nicole.braun@zammad.org',
|
|
||||||
password: 'test',
|
|
||||||
url: browser_url,
|
|
||||||
success: false,
|
|
||||||
)
|
|
||||||
|
|
||||||
# logout with admin and logon again
|
|
||||||
logout(
|
|
||||||
browser: browser1,
|
|
||||||
)
|
|
||||||
sleep 4
|
|
||||||
login(
|
|
||||||
browser: browser1,
|
|
||||||
username: 'admin@example.com',
|
|
||||||
password: 'test',
|
|
||||||
url: browser_url,
|
|
||||||
)
|
|
||||||
click(
|
|
||||||
browser: browser1,
|
|
||||||
css: 'a[href="#manage"]',
|
|
||||||
)
|
|
||||||
click(
|
|
||||||
browser: browser1,
|
|
||||||
css: 'a[href="#system/maintenance"]',
|
|
||||||
)
|
|
||||||
|
|
||||||
watch_for(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .js-modeSetting',
|
|
||||||
)
|
|
||||||
switch(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .js-modeSetting',
|
|
||||||
type: 'off',
|
|
||||||
)
|
|
||||||
|
|
||||||
watch_for_disappear(
|
|
||||||
browser: browser2,
|
|
||||||
css: '.js-maintenanceMode',
|
|
||||||
)
|
|
||||||
|
|
||||||
# try to logon with normal agent, should work again
|
|
||||||
login(
|
|
||||||
browser: browser2,
|
|
||||||
username: 'agent1@example.com',
|
|
||||||
password: 'test',
|
|
||||||
url: browser_url,
|
|
||||||
)
|
|
||||||
logout(
|
|
||||||
browser: browser2,
|
|
||||||
)
|
|
||||||
sleep 4
|
|
||||||
login(
|
|
||||||
browser: browser2,
|
|
||||||
username: 'nicole.braun@zammad.org',
|
|
||||||
password: 'test',
|
|
||||||
url: browser_url,
|
|
||||||
)
|
|
||||||
|
|
||||||
switch(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .js-modeSetting',
|
|
||||||
type: 'on',
|
|
||||||
no_check: true,
|
|
||||||
)
|
|
||||||
|
|
||||||
# check warning
|
|
||||||
modal_ready(browser: browser1)
|
|
||||||
click(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .modal .js-submit',
|
|
||||||
)
|
|
||||||
modal_disappear(browser: browser1)
|
|
||||||
|
|
||||||
watch_for(
|
|
||||||
browser: browser2,
|
|
||||||
css: '#login',
|
|
||||||
)
|
|
||||||
watch_for(
|
|
||||||
browser: browser2,
|
|
||||||
css: '.js-maintenanceMode',
|
|
||||||
)
|
|
||||||
|
|
||||||
switch(
|
|
||||||
browser: browser1,
|
|
||||||
css: '.content.active .js-modeSetting',
|
|
||||||
type: 'off',
|
|
||||||
)
|
|
||||||
|
|
||||||
watch_for_disappear(
|
|
||||||
browser: browser2,
|
|
||||||
css: '.js-maintenanceMode',
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
Loading…
Reference in a new issue