Maintenance: Stabilize Capybara tests, fix usage of wait().

This commit is contained in:
Martin Gruner 2021-12-10 13:37:47 +01:00
parent 41d72e92e9
commit 525476d539
11 changed files with 35 additions and 38 deletions

View file

@ -31,7 +31,7 @@ RSpec.configure do |config|
visit '/'
wait(4).until_exists do
wait.until_exists do
current_login
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)