Browse Source

Maintenance: Remove implicit visit to home page in system tests.

Dusan Vuckovic 2 years ago
parent
commit
2e5e4ff1bf

+ 1 - 0
app/controllers/sessions_controller.rb

@@ -59,6 +59,7 @@ class SessionsController < ApplicationController
   def destroy
   def destroy
     if %w[test development].include?(Rails.env) && ENV['FAKE_SELENIUM_LOGIN_USER_ID'].present?
     if %w[test development].include?(Rails.env) && ENV['FAKE_SELENIUM_LOGIN_USER_ID'].present?
       ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil # rubocop:disable Rails/EnvironmentVariableAccess
       ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil # rubocop:disable Rails/EnvironmentVariableAccess
+      ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil # rubocop:disable Rails/EnvironmentVariableAccess
     end
     end
 
 
     reset_session
     reset_session

+ 2 - 7
spec/support/capybara/authenticated.rb

@@ -13,6 +13,7 @@ RSpec.configure do |config|
   config.before(:each, type: :system) do |example|
   config.before(:each, type: :system) do |example|
 
 
     ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
     ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
+    ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
 
 
     # there is no way to authenticated in a not set up system
     # there is no way to authenticated in a not set up system
     next if !example.metadata.fetch(:set_up, true)
     next if !example.metadata.fetch(:set_up, true)
@@ -30,14 +31,8 @@ RSpec.configure do |config|
       ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = User.find_by(email: credentials[:username]).id.to_s
       ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = User.find_by(email: credentials[:username]).id.to_s
 
 
       if example.metadata[:app] != :mobile
       if example.metadata[:app] != :mobile
-        visit '/'
-
-        wait.until_exists do
-          current_login
-        end
+        ENV['FAKE_SELENIUM_LOGIN_PENDING'] = 'true'
       end
       end
-
-      await_empty_ajax_queue
     end
     end
   end
   end
 end
 end

+ 18 - 2
spec/support/capybara/common_actions.rb

@@ -23,6 +23,7 @@ module CommonActions
   # return [nil]
   # return [nil]
   def login(username:, password:, remember_me: false, app: self.class.metadata[:app])
   def login(username:, password:, remember_me: false, app: self.class.metadata[:app])
     ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
     ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
+    ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
 
 
     if !page.current_path || page.current_path.exclude?('login')
     if !page.current_path || page.current_path.exclude?('login')
       visit '/', skip_waiting: true
       visit '/', skip_waiting: true
@@ -112,6 +113,8 @@ module CommonActions
   #
   #
   def logout(app: self.class.metadata[:app])
   def logout(app: self.class.metadata[:app])
     ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
     ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
+    ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
+
     visit('logout')
     visit('logout')
 
 
     case app
     case app
@@ -147,8 +150,7 @@ module CommonActions
         super(route)
         super(route)
       end
       end
     elsif !route.start_with?('/')
     elsif !route.start_with?('/')
-      route = case app
-              when :mobile
+      route = if app == :mobile || route.start_with?('#')
                 "/#{route}"
                 "/#{route}"
               else
               else
                 "/##{route}"
                 "/##{route}"
@@ -173,6 +175,8 @@ module CommonActions
     else
     else
       return if route && (!route.start_with?('/#') || route == '/#logout')
       return if route && (!route.start_with?('/#') || route == '/#logout')
 
 
+      wait_for_pending_login(skip_waiting)
+
       # make sure all AJAX requests are done
       # make sure all AJAX requests are done
       await_empty_ajax_queue
       await_empty_ajax_queue
 
 
@@ -376,6 +380,18 @@ module CommonActions
       end
       end
     end
     end
   end
   end
+
+  private
+
+  def wait_for_pending_login(skip_waiting)
+    return if !ENV['FAKE_SELENIUM_LOGIN_PENDING']
+
+    # When visiting the first route after login, confirm currently logged in user.
+    ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
+    wait.until_exists { current_login } if !skip_waiting
+
+    nil
+  end
 end
 end
 
 
 RSpec.configure do |config|
 RSpec.configure do |config|

+ 2 - 0
spec/support/capybara/selenium_driver.rb

@@ -39,6 +39,7 @@ Capybara.register_driver(:zammad_chrome) do |app|
   end
   end
 
 
   ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
   ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
+  ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
 
 
   Capybara::Selenium::Driver.new(app, **driver_args).tap do |driver|
   Capybara::Selenium::Driver.new(app, **driver_args).tap do |driver|
     # Selenium 4 installs a default file_detector which finds wrong files/directories such as zammad/test.
     # Selenium 4 installs a default file_detector which finds wrong files/directories such as zammad/test.
@@ -73,6 +74,7 @@ Capybara.register_driver(:zammad_firefox) do |app|
   end
   end
 
 
   ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
   ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
+  ENV['FAKE_SELENIUM_LOGIN_PENDING'] = nil
 
 
   Capybara::Selenium::Driver.new(app, **driver_args).tap do |driver|
   Capybara::Selenium::Driver.new(app, **driver_args).tap do |driver|
     # Selenium 4 installs a default file_detector which finds wrong files/directories such as zammad/test.
     # Selenium 4 installs a default file_detector which finds wrong files/directories such as zammad/test.

+ 4 - 0
spec/system/basic/assets_spec.rb

@@ -10,6 +10,10 @@ RSpec.describe 'Assets', type: :system, db_strategy: :reset do
   let(:ticket)       { create(:ticket, owner: agent, group: Group.find_by(name: 'Users'), customer: customer, created_by: admin) }
   let(:ticket)       { create(:ticket, owner: agent, group: Group.find_by(name: 'Users'), customer: customer, created_by: admin) }
 
 
   context 'groups' do
   context 'groups' do
+    before do
+      visit '/'
+    end
+
     def group_note
     def group_note
       page.execute_script('return App.Group.first().note')
       page.execute_script('return App.Group.first().note')
     end
     end

+ 1 - 3
spec/system/basic/richtext_spec.rb

@@ -5,9 +5,7 @@ require 'rails_helper'
 RSpec.describe 'Richtext', type: :system do
 RSpec.describe 'Richtext', type: :system do
 
 
   before do
   before do
-    click(:href, '#current_user')
-    click(:href, '#layout_ref')
-    click(:href, '#layout_ref/richtext')
+    visit '#layout_ref/richtext'
   end
   end
 
 
   context 'Richtext' do
   context 'Richtext' do

+ 1 - 1
spec/system/channels/telegram_spec.rb

@@ -2,7 +2,7 @@
 
 
 require 'rails_helper'
 require 'rails_helper'
 
 
-RSpec.describe 'Manage > Channels > Telgram', type: :system, integration: true, required_envs: %w[TELEGRAM_TOKEN] do
+RSpec.describe 'Manage > Channels > Telegram', type: :system, integration: true, required_envs: %w[TELEGRAM_TOKEN] do
   before { visit '/#channels/telegram' }
   before { visit '/#channels/telegram' }
 
 
   it 'does connect and add the token' do
   it 'does connect and add the token' do

+ 14 - 0
spec/system/chat_spec.rb

@@ -294,6 +294,8 @@ RSpec.describe 'Chat Handling', type: :system do
 
 
   context 'when changing chat preferences for current agent' do
   context 'when changing chat preferences for current agent' do
     it 'use chat phrase preference', authenticated_as: :authenticate do
     it 'use chat phrase preference', authenticated_as: :authenticate do
+      visit '/'
+
       enable_agent_chat
       enable_agent_chat
 
 
       click '.active .js-settings'
       click '.active .js-settings'
@@ -338,6 +340,10 @@ RSpec.describe 'Chat Handling', type: :system do
   end
   end
 
 
   context 'when jquery variant is used' do
   context 'when jquery variant is used' do
+    before do
+      visit '/'
+    end
+
     context 'when normal mode is used' do
     context 'when normal mode is used' do
       include_examples 'chat messages'
       include_examples 'chat messages'
       include_examples 'timeouts'
       include_examples 'timeouts'
@@ -354,6 +360,10 @@ RSpec.describe 'Chat Handling', type: :system do
   context 'when no-jquery variant is used' do
   context 'when no-jquery variant is used' do
     let(:chat_url_type) { 'znuny-no-jquery' }
     let(:chat_url_type) { 'znuny-no-jquery' }
 
 
+    before do
+      visit '/'
+    end
+
     context 'when normal mode is used' do
     context 'when normal mode is used' do
       include_examples 'chat messages'
       include_examples 'chat messages'
       include_examples 'timeouts'
       include_examples 'timeouts'
@@ -382,6 +392,10 @@ RSpec.describe 'Chat Handling', type: :system do
       end
       end
     end
     end
 
 
+    before do
+      visit '/'
+    end
+
     context 'with jquery' do
     context 'with jquery' do
       include_examples 'test issue #2471'
       include_examples 'test issue #2471'
     end
     end

+ 2 - 0
spec/system/cti_spec.rb

@@ -38,6 +38,7 @@ RSpec.describe 'Caller log', type: :system, authenticated_as: :authenticate do
 
 
   context 'when cti integration is on' do
   context 'when cti integration is on' do
     it 'shows the phone menu in nav bar' do
     it 'shows the phone menu in nav bar' do
+      visit '/'
 
 
       within '#navigation .menu' do
       within '#navigation .menu' do
         expect(page).to have_link('Phone', href: '#cti')
         expect(page).to have_link('Phone', href: '#cti')
@@ -49,6 +50,7 @@ RSpec.describe 'Caller log', type: :system, authenticated_as: :authenticate do
     let(:cti_on) { false }
     let(:cti_on) { false }
 
 
     it 'does not show the phone menu in nav bar' do
     it 'does not show the phone menu in nav bar' do
+      visit '/'
 
 
       within '#navigation .menu' do
       within '#navigation .menu' do
         expect(page).to have_no_link('Phone', href: '#cti')
         expect(page).to have_no_link('Phone', href: '#cti')

+ 1 - 0
spec/system/dashboard_spec.rb

@@ -40,6 +40,7 @@ RSpec.describe 'Dashboard', type: :system do
     let(:customer) { create(:customer) }
     let(:customer) { create(:customer) }
 
 
     before do
     before do
+      visit '/'
       ensure_websocket(check_if_pinged: false)
       ensure_websocket(check_if_pinged: false)
       sleep 3 # fast relog causes raise conditions in websocket server
       sleep 3 # fast relog causes raise conditions in websocket server
     end
     end

Some files were not shown because too many files changed in this diff