Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions qa/t/2_test_autocomplete.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 21 additions & 4 deletions qa/t/2_test_flags2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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");
}
14 changes: 14 additions & 0 deletions qa/t/lib/QA/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use base qw(Exporter);

get_selenium
check_page_load
wait_for_js

WAIT_TIME
CHROME_MODE
Expand Down Expand Up @@ -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;
Expand Down
Loading