From 892db4672f71b6ac404d8dc6b0128b302c735a8f Mon Sep 17 00:00:00 2001
From: John Hope <jhope@gitlab.com>
Date: Wed, 30 Aug 2023 15:43:26 +0000
Subject: [PATCH] Fix flaky ee/spec/features/epics/update_epic_spec.rb by
 accepting alert

---
 ee/spec/features/epics/update_epic_spec.rb     | 11 ++++-------
 spec/support/capybara_wait_for_all_requests.rb |  4 +++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/ee/spec/features/epics/update_epic_spec.rb b/ee/spec/features/epics/update_epic_spec.rb
index 2f522dbd289c4..ef4e282887b3e 100644
--- a/ee/spec/features/epics/update_epic_spec.rb
+++ b/ee/spec/features/epics/update_epic_spec.rb
@@ -60,8 +60,7 @@
         expect(find('.issuable-details .description')).to have_content('New epic description')
       end
 
-      it 'updates the epic and keep the description saved across reload',
-        quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/408227' do
+      it 'updates the epic and keep the description saved across reload' do
         fill_in 'issue-description', with: 'New epic description'
 
         page.within('.detail-page-description') do
@@ -69,12 +68,10 @@
           expect(find('.md-preview-holder')).to have_content('New epic description')
         end
 
-        visit group_epic_path(group, epic)
-
-        # Deal with the beforeunload browser popup
-        page.driver.browser.switch_to.alert.accept
+        visit group_epic_path(group, epic) do
+          page.driver.browser.switch_to.alert.accept
+        end
 
-        wait_for_requests
         find('.js-issuable-edit').click
 
         page.within('.detail-page-description') do
diff --git a/spec/support/capybara_wait_for_all_requests.rb b/spec/support/capybara_wait_for_all_requests.rb
index 36b63619b0899..9c74a1cab92d8 100644
--- a/spec/support/capybara_wait_for_all_requests.rb
+++ b/spec/support/capybara_wait_for_all_requests.rb
@@ -9,9 +9,11 @@ module WaitForAllRequestsAfterVisitPage
       include CapybaraHelpers
       include WaitForRequests
 
-      def visit(visit_uri)
+      def visit(visit_uri, &block)
         super
 
+        yield if block
+
         wait_for_all_requests
       end
     end
-- 
GitLab