From ea2cb2d466d0f147d18e39b1745dca68c3cc273a Mon Sep 17 00:00:00 2001 From: Xavier L'Hour Date: Thu, 15 Oct 2026 23:12:28 +0200 Subject: [PATCH] Bug 2082654 - 2_test_flags2.t picks a component before the bug page has loaded the new product's components --- qa/t/2_test_autocomplete.t | 12 ------------ qa/t/2_test_flags2.t | 25 +++++++++++++++++++++---- qa/t/lib/QA/Util.pm | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/qa/t/2_test_autocomplete.t b/qa/t/2_test_autocomplete.t index 0eb4ec39d2..bef3b08b42 100644 --- a/qa/t/2_test_autocomplete.t +++ b/qa/t/2_test_autocomplete.t @@ -95,15 +95,3 @@ sub check_autocomplete { "$desc suggestions stay hidden after the field loses focus"); } } - -# Poll a script returning a true value for up to 5 seconds. -sub wait_for_js { - my ($sel, $script) = @_; - my $result; - for (0 .. 50) { - $result = $sel->driver->execute_script($script); - last if $result; - select(undef, undef, undef, 0.1); - } - return $result; -} diff --git a/qa/t/2_test_flags2.t b/qa/t/2_test_flags2.t index cd993ecb7b..616f01aa41 100644 --- a/qa/t/2_test_flags2.t +++ b/qa/t/2_test_flags2.t @@ -182,8 +182,7 @@ $sel->is_element_present_ok( # Now move the bug into the 'Another Product' product. # Both the bug and attachment flags should survive. -$sel->select_ok("product", "label=Another Product"); -$sel->select_ok("component", "label=c1"); +change_product($sel, "Another Product", "c1"); $sel->type_ok("comment", "Moving to Another Product / c1. The flag should be preserved."); $sel->click_ok('bottom-save-btn'); @@ -315,8 +314,7 @@ $sel->selected_label_is("flag-$flag2_id", "+"); # But moving the bug into TestProduct will delete the flag # as the flag setter is not in the editbugs group. -$sel->select_ok("product", "label=TestProduct"); -$sel->select_ok("component", "label=TestComponent"); +change_product($sel, "TestProduct", "TestComponent"); $sel->type_ok("comment", "selenium flag will be lost. I don't have editbugs privs."); $sel->click_ok('bottom-save-btn'); @@ -361,3 +359,22 @@ foreach my $flagtype ( "Flag type $flag_name deleted"); } logout($sel); + +# On the bug page, changing the product disables the component select and +# reloads its options asynchronously, so wait for the wanted component before +# selecting it. +sub change_product { + my ($sel, $product, $component) = @_; + $sel->select_ok("product", "label=$product"); + ok( + wait_for_js( + $sel, qq{ + const select = document.getElementById('component'); + return !select.disabled + && [...select.options].some(o => o.text === '$component'); + } + ), + "Components of $product are loaded" + ); + $sel->select_ok("component", "label=$component"); +} diff --git a/qa/t/lib/QA/Util.pm b/qa/t/lib/QA/Util.pm index 19355c3b34..6fb398df17 100644 --- a/qa/t/lib/QA/Util.pm +++ b/qa/t/lib/QA/Util.pm @@ -59,6 +59,7 @@ use base qw(Exporter); get_selenium check_page_load + wait_for_js WAIT_TIME CHROME_MODE @@ -328,6 +329,19 @@ sub expand_all_modules { } } +# Poll a script returning a true value for up to 5 seconds, for page content +# that is updated asynchronously. Returns the script's last result. +sub wait_for_js { + my ($sel, $script) = @_; + my $result; + for (0 .. 50) { + $result = $sel->driver->execute_script($script); + last if $result; + select(undef, undef, undef, 0.1); + } + return $result; +} + # Go to admin.cgi. sub go_to_admin { my $sel = shift;