From 969586b165347d388da8bc0a8776dc3903dabb50 Mon Sep 17 00:00:00 2001 From: Ko Nagase Date: Sun, 12 May 2024 23:12:29 +0900 Subject: [PATCH 2/2] Stabilize inline autocomplete system test --- test/application_system_test_case.rb | 10 ++++++++++ test/system/inline_autocomplete_test.rb | 16 ++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 4a6fd0d30..248c896d9 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -105,6 +105,16 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase end files.last end + + def fill_in_with_delay(locator, with:, delay: 0.01) + find(:fillable_field, locator).set('') + if with.is_a?(String) && with.length > 0 + with.chars.each do |char| + find(:fillable_field, locator).send_keys(char) + sleep delay + end + end + end end FileUtils.mkdir_p ApplicationSystemTestCase::DOWNLOADS_PATH diff --git a/test/system/inline_autocomplete_test.rb b/test/system/inline_autocomplete_test.rb index 3334151ff..e94927ae8 100644 --- a/test/system/inline_autocomplete_test.rb +++ b/test/system/inline_autocomplete_test.rb @@ -47,7 +47,7 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase log_user('admin', 'admin') visit 'projects/ecookbook/issues/new' - fill_in 'Description', :with => '##12' + fill_in_with_delay 'Description', :with => '##12' within('.tribute-container') do assert page.has_text? 'Bug #12: Closed issue on a locked version' @@ -62,7 +62,7 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase log_user('jsmith', 'jsmith') visit 'issues/new' - fill_in 'Description', :with => '#Closed' + fill_in_with_delay 'Description', :with => '#Closed' within('.tribute-container') do assert page.has_text? 'Bug #12: Closed issue on a locked version' @@ -150,14 +150,14 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase log_user('jsmith', 'jsmith') visit 'issues/new' - fill_in 'Description', :with => '[[' + fill_in_with_delay 'Description', :with => '[[' within('.tribute-container') do assert page.has_text? 'Child_1_1' assert page.has_text? 'Page_with_sections' end - fill_in 'Description', :with => '[[page' + fill_in_with_delay 'Description', :with => '[[page' within('.tribute-container') do assert page.has_text? 'Page_with_sections' assert page.has_text? 'Another_page' @@ -174,7 +174,7 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase log_user('jsmith', 'jsmith') visit 'projects/1/issues/new' - fill_in 'Description', :with => '#This' + fill_in_with_delay 'Description', :with => '#This' within('.tribute-container') do assert page.has_text? "Bug ##{issue.id}: This issue has a