From acc33dd606ad20c63da84de5f9ea3b55a51e498f Mon Sep 17 00:00:00 2001
From: Katsuya Hidaka <hidakatsuya@gmail.com>
Date: Thu, 6 Feb 2025 22:09:01 +0900
Subject: Fix random failures in InlineAutocompleteTest due to interference
 from requests in the previous test

---
 test/system/inline_autocomplete_test.rb | 35 +++++++++++++++----------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/test/system/inline_autocomplete_test.rb b/test/system/inline_autocomplete_test.rb
index 4b2271b79..286ea90a7 100644
--- a/test/system/inline_autocomplete_test.rb
+++ b/test/system/inline_autocomplete_test.rb
@@ -40,8 +40,9 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
     log_user('admin', 'admin')
     visit 'projects/ecookbook/issues/new'
 
-    fill_in 'Description', :with => '##Closed'
+    fill_in 'Description', :with => '##Cl'
 
+    assert_selector '.tribute-container li', count: 3
     within('.tribute-container') do
       assert page.has_text? 'Bug #12: Closed issue on a locked version'
       assert page.has_text? 'Bug #11: Closed issue on a closed version'
@@ -57,12 +58,13 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
     log_user('jsmith', 'jsmith')
     visit 'issues/new'
 
-    fill_in 'Description', :with => '#Closed'
+    fill_in 'Description', :with => '#Cl'
 
+    assert_selector '.tribute-container li', count: 3
     within('.tribute-container') do
       assert page.has_text? 'Bug #12: Closed issue on a locked version'
       assert page.has_text? 'Bug #11: Closed issue on a closed version'
-      assert_not page.has_text? 'Bug #1: Cannot print recipes'
+      assert page.has_text? 'Bug #8: Closed issue'
     end
   end
 
@@ -152,10 +154,14 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
       assert page.has_text? 'Page_with_sections'
     end
 
-    fill_in 'Description', :with => '[[page'
+    fill_in 'Description', :with => '[[p'
+
+    assert_selector '.tribute-container li', count: 3
     within('.tribute-container') do
       assert page.has_text? 'Page_with_sections'
+      assert page.has_text? 'Page_with_an_inline_image'
       assert page.has_text? 'Another_page'
+
       assert_not page.has_text? 'Child_1_1'
 
       first('li').click
@@ -169,8 +175,9 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
     log_user('jsmith', 'jsmith')
     visit 'projects/1/issues/new'
 
-    fill_in 'Description', :with => '#This'
+    fill_in 'Description', :with => '#Th'
 
+    assert_selector '.tribute-container li', count: 1
     within('.tribute-container') do
       assert page.has_text? "Bug ##{issue.id}: This issue has a <select> element"
     end
@@ -181,19 +188,18 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
     visit '/issues/1/edit'
 
     find('#issue_notes').click
-    fill_in 'issue[notes]', :with => '@lopper'
+    fill_in 'issue[notes]', :with => '@'
 
-    within('.tribute-container') do
-      assert page.has_text? "Dave Lopper"
-    end
+    assert_selector '.tribute-container li', minimum: 1
 
     page.find('#issue_status_id').select('Feedback')
 
     find('#issue_notes').click
-    fill_in 'issue[notes]', :with => '@lopper'
+    fill_in 'issue[notes]', :with => '@j'
 
+    assert_selector '.tribute-container li', count: 1
     within('.tribute-container') do
-      assert page.has_text? "Dave Lopper"
+      assert page.has_text? 'John Smith'
     end
   end
 
@@ -202,14 +208,15 @@ class InlineAutocompleteSystemTest < ApplicationSystemTestCase
     visit '/issues/bulk_edit?ids[]=1&ids[]=2'
 
     find('#notes').click
-    fill_in 'notes', :with => '@lopper'
+    fill_in 'notes', :with => '@j'
 
+    assert_selector '.tribute-container li', count: 1
     within('.tribute-container') do
-      assert page.has_text? 'Dave Lopper'
+      assert page.has_text? 'John Smith'
       first('li').click
     end
 
-    assert_equal '@dlopper ', find('#notes').value
+    assert_equal '@jsmith ', find('#notes').value
   end
 
   def test_inline_autocomplete_for_users_on_issues_without_edit_issue_permission
-- 
2.45.2

