From 525476d539ad27f0e3d09a4c5c75eaca9b6b1e7a Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Fri, 10 Dec 2021 13:37:47 +0100 Subject: [PATCH] Maintenance: Stabilize Capybara tests, fix usage of wait(). --- spec/support/capybara/authenticated.rb | 2 +- spec/support/capybara/browser_test_helper.rb | 8 ++++---- spec/support/capybara/common_actions.rb | 6 +++--- spec/system/form_spec.rb | 4 ++-- spec/system/login/maintenance_mode_spec.rb | 4 ++-- spec/system/login/message_spec.rb | 6 +++--- spec/system/system/maintenance/app_version_spec.rb | 9 +++------ spec/system/system/maintenance_spec.rb | 10 +++++----- spec/system/ticket/create_spec.rb | 12 ++++++------ .../ticket/inserting_knowledge_base_answer_spec.rb | 2 +- spec/system/ticket/zoom_spec.rb | 10 +++++----- 11 files changed, 35 insertions(+), 38 deletions(-) diff --git a/spec/support/capybara/authenticated.rb b/spec/support/capybara/authenticated.rb index bf60a0bf3..09bec6282 100644 --- a/spec/support/capybara/authenticated.rb +++ b/spec/support/capybara/authenticated.rb @@ -31,7 +31,7 @@ RSpec.configure do |config| visit '/' - wait(4).until_exists do + wait.until_exists do current_login end end diff --git a/spec/support/capybara/browser_test_helper.rb b/spec/support/capybara/browser_test_helper.rb index b211de1cf..fa89d20dc 100644 --- a/spec/support/capybara/browser_test_helper.rb +++ b/spec/support/capybara/browser_test_helper.rb @@ -63,7 +63,7 @@ module BrowserTestHelper # @see BrowserTestHelper::Waiter # # @example - # wait(5).until { ... } + # wait.until { ... } # # @example # wait(5, interval: 0.5).until { ... } @@ -161,7 +161,7 @@ module BrowserTestHelper # in the given block. # # @example - # wait(5).until_exists { find('[data-title="example"]') } + # wait.until_exists { find('[data-title="example"]') } # def until_exists self.until do @@ -181,7 +181,7 @@ module BrowserTestHelper # in the given block. # # @example - # wait(5).until_disappear { find('[data-title="example"]') } + # wait.until_disappear { find('[data-title="example"]') } # def until_disappears self.until do @@ -200,7 +200,7 @@ module BrowserTestHelper # This method loops a given block until the result of it is constant. # # @example - # wait(5).until_constant { find('.total').text } + # wait.until_constant { find('.total').text } # def until_constant previous = nil diff --git a/spec/support/capybara/common_actions.rb b/spec/support/capybara/common_actions.rb index f920d5914..ff0c332c9 100644 --- a/spec/support/capybara/common_actions.rb +++ b/spec/support/capybara/common_actions.rb @@ -37,7 +37,7 @@ module CommonActions click_button end - wait(4).until_exists do + wait.until_exists do current_login end @@ -224,14 +224,14 @@ module CommonActions wrapper = all('div.ticket-article-item').last wrapper.find('.article-content .textBubble').click - wait(3).until do + wait.until do wrapper.find('.article-content-meta .article-meta.top').in_fixed_position end end end def use_template(template) - wait(4).until do + wait.until do field = find('#form-template select[name="id"]') option = field.find(:option, template.name) option.select_option diff --git a/spec/system/form_spec.rb b/spec/system/form_spec.rb index 97485fdbf..ab27c697f 100644 --- a/spec/system/form_spec.rb +++ b/spec/system/form_spec.rb @@ -133,7 +133,7 @@ RSpec.describe 'Form', type: :system, authenticated_as: true do before do visit 'channels/form' check 'form_ticket_create', { allow_label_click: true } - wait(10).until { Setting.get('form_ticket_create') == true } + wait.until { Setting.get('form_ticket_create') == true } end context 'when form is inline' do @@ -168,7 +168,7 @@ RSpec.describe 'Form', type: :system, authenticated_as: true do before do visit 'channels/form' uncheck 'form_ticket_create', { allow_label_click: true } - wait(10).until { Setting.get('form_ticket_create') == false } + wait.until { Setting.get('form_ticket_create') == false } visit path end diff --git a/spec/system/login/maintenance_mode_spec.rb b/spec/system/login/maintenance_mode_spec.rb index 9bb0bc06c..65d65d4e7 100644 --- a/spec/system/login/maintenance_mode_spec.rb +++ b/spec/system/login/maintenance_mode_spec.rb @@ -49,7 +49,7 @@ RSpec.describe 'Login Maintenance Mode', type: :system, authenticated_as: false Setting.set 'maintenance_mode', false - expect(page).to have_no_css('.js-maintenanceMode') + expect(page).to have_no_css('.js-maintenanceMode', wait: 30) try_login('agent1@example.com', 'test') @@ -71,7 +71,7 @@ RSpec.describe 'Login Maintenance Mode', type: :system, authenticated_as: false Setting.set 'maintenance_mode', true - expect(page).to have_css('.js-maintenanceMode') + expect(page).to have_css('.js-maintenanceMode', wait: 30) end end end diff --git a/spec/system/login/message_spec.rb b/spec/system/login/message_spec.rb index 78b4b0c6d..a71fe5bb2 100644 --- a/spec/system/login/message_spec.rb +++ b/spec/system/login/message_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'Login Message', type: :system, authenticated_as: false do Setting.set 'maintenance_login', false - expect(page).to have_no_css('.js-maintenanceLogin', text: message) + expect(page).to have_no_css('.js-maintenanceLogin', text: message, wait: 30) end it 'changes message text on the go' do @@ -31,7 +31,7 @@ RSpec.describe 'Login Message', type: :system, authenticated_as: false do Setting.set 'maintenance_login_message', alt_message - expect(page).to have_css('.js-maintenanceLogin', text: alt_message) + expect(page).to have_css('.js-maintenanceLogin', text: alt_message, wait: 30) end end @@ -49,7 +49,7 @@ RSpec.describe 'Login Message', type: :system, authenticated_as: false do Setting.set 'maintenance_login', true - expect(page).to have_css('.js-maintenanceLogin', text: message) + expect(page).to have_css('.js-maintenanceLogin', text: message, wait: 30) end end end diff --git a/spec/system/system/maintenance/app_version_spec.rb b/spec/system/system/maintenance/app_version_spec.rb index 50714c0c1..63d6af264 100644 --- a/spec/system/system/maintenance/app_version_spec.rb +++ b/spec/system/system/maintenance/app_version_spec.rb @@ -6,13 +6,10 @@ RSpec.describe 'System > Maintenance - App Version', type: :system do it 'check that new version modal dialog is present' do visit 'ticket/zoom/1' - page.execute_script 'App.Event.trigger("maintenance", {type:"app_version", app_version:"1234:false"} )' + AppVersion.set(false, 'app_version') + AppVersion.set(true, 'app_version') - expect(page).to have_no_text('new version', wait: 10) - - page.execute_script 'App.Event.trigger("maintenance", {type:"app_version", app_version:"1234:true"} )' - - modal_ready timeout: 10 + modal_ready timeout: 30 within '.modal-dialog' do expect(page).to have_text('new version') diff --git a/spec/system/system/maintenance_spec.rb b/spec/system/system/maintenance_spec.rb index edf7fa097..323de54a4 100644 --- a/spec/system/system/maintenance_spec.rb +++ b/spec/system/system/maintenance_spec.rb @@ -15,7 +15,7 @@ RSpec.describe 'System > Maintenance', type: :system do click '.js-loginSetting label' - wait(10).until { expect(Setting.get('maintenance_login')).to be true } + wait.until { expect(Setting.get('maintenance_login')).to be true } end end @@ -30,7 +30,7 @@ RSpec.describe 'System > Maintenance', type: :system do click '.js-loginSetting label' - wait(10).until { expect(Setting.get('maintenance_login')).to be false } + wait.until { expect(Setting.get('maintenance_login')).to be false } end end @@ -64,7 +64,7 @@ RSpec.describe 'System > Maintenance', type: :system do find('#global-search').click # unfocus - wait(10).until { expect(Setting.get('maintenance_login_message')).to eq "#{message}#{message_suffix}" } + wait.until { expect(Setting.get('maintenance_login_message')).to eq "#{message}#{message_suffix}" } end end end @@ -84,7 +84,7 @@ RSpec.describe 'System > Maintenance', type: :system do click '.content.active .modal .js-submit' modal_disappear - wait(10).until { expect(Setting.get('maintenance_mode')).to be true } + wait.until { expect(Setting.get('maintenance_mode')).to be true } end end @@ -99,7 +99,7 @@ RSpec.describe 'System > Maintenance', type: :system do click '.js-modeSetting label' - wait(10).until { expect(Setting.get('maintenance_mode')).to be false } + wait.until { expect(Setting.get('maintenance_mode')).to be false } end end end diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index ef7c7d27d..7dda9175e 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -768,17 +768,17 @@ RSpec.describe 'Ticket Create', type: :system do find('[name=customer_id_completion]').fill_in with: 'zam' expect(page).to have_selector("li.js-organization[data-organization-id='#{organization.id}']") page.find("li.js-organization[data-organization-id='#{organization.id}']").click - wait(5).until { page.all("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li", visible: :all).count == 12 } # 10 users + back + show more button + wait.until { page.all("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li", visible: :all).count == 12 } # 10 users + back + show more button expect(page).to have_selector("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li.js-showMoreMembers[organization-member-limit='10']") scroll_into_view('li.js-showMoreMembers') page.find("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li.js-showMoreMembers").click - wait(5).until { page.all("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li", visible: :all).count == 27 } # 25 users + back + show more button + wait.until { page.all("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li", visible: :all).count == 27 } # 25 users + back + show more button expect(page).to have_selector("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li.js-showMoreMembers[organization-member-limit='25']") scroll_into_view('li.js-showMoreMembers') page.find("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li.js-showMoreMembers").click - wait(5).until { page.all("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li", visible: :all).count == 52 } # 50 users + back + show more button + wait.until { page.all("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li", visible: :all).count == 52 } # 50 users + back + show more button scroll_into_view('li.js-showMoreMembers') expect(page).to have_selector("ul.recipientList-organizationMembers[organization-id='#{organization.id}'] li.js-showMoreMembers.hidden", visible: :all, wait: 20) @@ -797,7 +797,7 @@ RSpec.describe 'Ticket Create', type: :system do await_empty_ajax_queue page.find('input#fileUpload_1', visible: :all).set(Rails.root.join('test/data/mail/mail002.box')) await_empty_ajax_queue - wait(5).until { page.all('div.attachment-delete.js-delete', visible: :all).count == 2 } + wait.until { page.all('div.attachment-delete.js-delete', visible: :all).count == 2 } expect(page).to have_text('mail001.box') expect(page).to have_text('mail002.box') @@ -810,7 +810,7 @@ RSpec.describe 'Ticket Create', type: :system do # even tho it worked fine end await_empty_ajax_queue - wait(5).until { page.all('div.attachment-delete.js-delete', visible: :all).count == 1 } + wait.until { page.all('div.attachment-delete.js-delete', visible: :all).count == 1 } expect(page).to have_text('mail001.box') expect(page).to have_no_text('mail002.box') @@ -829,7 +829,7 @@ RSpec.describe 'Ticket Create', type: :system do end it 'does show an empty list of owners' do - wait(5).until { page.all('select[name=owner_id] option').count == 1 } + wait.until { page.all('select[name=owner_id] option').count == 1 } expect(page.all('select[name=owner_id] option').count).to eq(1) end end diff --git a/spec/system/ticket/inserting_knowledge_base_answer_spec.rb b/spec/system/ticket/inserting_knowledge_base_answer_spec.rb index 228bba35c..d049b4819 100644 --- a/spec/system/ticket/inserting_knowledge_base_answer_spec.rb +++ b/spec/system/ticket/inserting_knowledge_base_answer_spec.rb @@ -43,7 +43,7 @@ RSpec.describe 'inserting Knowledge Base answer', type: :system, searchindex: tr within(:active_content) do within(:richtext) do - wait(5).until do + wait.until do elem = first('img') script = 'return arguments[0].naturalWidth;' height = Capybara.current_session.driver.browser.execute_script(script, elem.native) diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 3aae35a8f..c7ede74ba 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -1992,11 +1992,11 @@ RSpec.describe 'Ticket zoom', type: :system do end def wait_for_upload_present - wait(5).until { Taskbar.find_by(key: "Ticket-#{ticket.id}").attributes_with_association_ids['attachments'].present? } + wait.until { Taskbar.find_by(key: "Ticket-#{ticket.id}").attributes_with_association_ids['attachments'].present? } end def wait_for_upload_blank - wait(5).until { Taskbar.find_by(key: "Ticket-#{ticket.id}").attributes_with_association_ids['attachments'].blank? } + wait.until { Taskbar.find_by(key: "Ticket-#{ticket.id}").attributes_with_association_ids['attachments'].blank? } end def switch_language_german @@ -2272,14 +2272,14 @@ RSpec.describe 'Ticket zoom', type: :system do it 'does open automatically when body is given from sidebar' do find('.js-textarea').send_keys('test') - wait(5).until { Taskbar.find_by(key: "Ticket-#{ticket.id}").state.dig('article', 'body').present? } + wait.until { Taskbar.find_by(key: "Ticket-#{ticket.id}").state.dig('article', 'body').present? } refresh expect(page).to have_selector('form.article-add.is-open') end it 'does open automatically when attachment is given from sidebar' do page.find('input#fileUpload_1', visible: :all).set(Rails.root.join('test/data/mail/mail001.box')) - wait(5).until { Taskbar.find_by(key: "Ticket-#{ticket.id}").attributes_with_association_ids['attachments'].present? } + wait.until { Taskbar.find_by(key: "Ticket-#{ticket.id}").attributes_with_association_ids['attachments'].present? } refresh expect(page).to have_selector('form.article-add.is-open') end @@ -2310,7 +2310,7 @@ RSpec.describe 'Ticket zoom', type: :system do it 'does clear agent1 on select of group 2' do select group2.name, from: 'Group' - wait(5).until { page.find('select[name=owner_id]').value != agent1.id.to_s } + wait.until { page.find('select[name=owner_id]').value != agent1.id.to_s } expect(page.find('select[name=owner_id]').value).to eq('') expect(page.all('select[name=owner_id] option').map(&:value)).not_to include(agent1.id.to_s) expect(page.all('select[name=owner_id] option').map(&:value)).to include(agent2.id.to_s)