Skip to content

Commit 197890f

Browse files
authored
Merge pull request os-autoinst#6482 from Martchus/test-details-test
Improve details of test details test
2 parents 02fa3b4 + 119274a commit 197890f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

t/ui/18-tests-details.t

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use FindBin;
1010
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common/lib";
1111
use Test::Mojo;
1212
use Test::Warnings qw(:all :report_warnings);
13+
use Mojo::Base -signatures;
1314
use Mojo::JSON qw(decode_json encode_json);
1415
use Mojo::File qw(path);
1516
use Mojo::IOLoop;
@@ -40,7 +41,7 @@ my $needle_dir_fixture = $schema->resultset('NeedleDirs')->find(1);
4041
my $needle_dir = prepare_clean_needles_dir;
4142
prepare_default_needle($needle_dir);
4243

43-
sub prepare_database {
44+
sub prepare_database () {
4445
# set assigned_worker_id to test whether worker still displayed when job set to done
4546
# manually for Selenium test
4647
$jobs->find(99963)->update({assigned_worker_id => 1});
@@ -75,9 +76,11 @@ my $baseurl = $driver->get_current_url;
7576
sub current_tab { $driver->find_element('.nav.nav-tabs .active')->get_text }
7677

7778
# returns the contents of the candidates combo box as hash (key: tag, value: array of needle names)
78-
sub find_candidate_needles {
79+
sub find_candidate_needles ($enabled_expected = 1) {
7980
# ensure the candidates menu is visible
80-
my $candidates_menu = wait_for_element(selector => '#candidatesMenu', is_displayed => 1) or return {};
81+
my $candidates_menu = wait_for_element(selector => '#candidatesMenu', is_displayed => 1);
82+
fail 'unable to locate candidates menu' and return {} unless $candidates_menu;
83+
is $candidates_menu->is_enabled, $enabled_expected, 'candidates menu is enabled/disabled';
8184
return {} unless $candidates_menu->is_enabled;
8285

8386
# save implicit waiting time as long as we are only looking for elements
@@ -209,9 +212,7 @@ subtest 'filtering' => sub {
209212
is($count_headings->(), 3, 'module headings shown again');
210213
};
211214

212-
sub check_report_links {
213-
my ($failed_module, $failed_step, $container) = @_;
214-
215+
sub check_report_links ($failed_module, $failed_step, $container = undef) {
215216
my @report_links
216217
= $container
217218
? $driver->find_child_elements($container, '.report')
@@ -286,9 +287,9 @@ subtest 'reason and log details on incomplete jobs' => sub {
286287
->text_like(qr/cannot provide hints/, 'investigation status content shown as table');
287288
};
288289

289-
sub update_status {
290+
sub update_status (@args) {
290291
$driver->execute_script('window.enableStatusUpdates = true; updateStatus(); window.enableStatusUpdates = false;');
291-
wait_until @_, 10;
292+
wait_until @args, 10;
292293
}
293294

294295
subtest 'running job' => sub {
@@ -377,7 +378,7 @@ subtest 'running job' => sub {
377378
subtest 'missing text results are attempted to be reloaded' => sub {
378379
my $step_detail_element = $driver->find_element('#module_aplay .links');
379380
ok $step_detail_element, 'step detail present' or return;
380-
like $step_detail_element->get_text, qr/Unable to read/, '"Unable to read" shown in the first place';
381+
like $step_detail_element->get_text, qr/Unable to read/, '"Unable to read" shown in the first place';
381382
# pretend the text result has been uploaded
382383
$aplay_text_result->spew('some text result');
383384
update_status sub {
@@ -627,25 +628,24 @@ my $ntext = <<EOM;
627628
EOM
628629
$needle_dir->child("$_.json")->spew($ntext) for qw(sudo-passwordprompt-lxde sudo-passwordprompt);
629630

630-
sub test_with_error {
631-
my ($needle_to_modify, $error, $tags, $expect, $test_name) = @_;
632-
631+
sub test_with_error ($needle_to_modify, $error, $tags, $expect, $test_name) {
633632
# modify the fixture test data: parse JSON -> modify -> write JSON
634633
if (defined $needle_to_modify || defined $tags) {
635634
my $details_file = path('t/data/openqa/testresults/00099/'
636635
. '00099946-opensuse-13.1-DVD-i586-Build0091-textmode/details-yast2_lan.json');
637636
my $details = decode_json($details_file->slurp);
638637
my $detail = $details->[0];
639638
$detail->{needles}->[$needle_to_modify]->{error} = $error if defined $needle_to_modify && defined $error;
640-
$detail->{tags} = $tags if defined $tags;
639+
$detail->{tags} = $tags;
641640
$details_file->spew(encode_json($details));
642641
}
643642

644643
# check whether candidates are displayed as expected
645644
my $random_number = int(rand(100000));
646645
$driver->get("/tests/99946?prevent_caching=$random_number#step/yast2_lan/1");
647646
wait_for_ajax(msg => 'step of yast2_lan test module loaded');
648-
is_deeply(find_candidate_needles, $expect, $test_name // 'candidates displayed as expected');
647+
my $candidates = find_candidate_needles(@$tags > 0);
648+
is_deeply $candidates, $expect, $test_name // 'candidates displayed as expected' or always_explain $candidates;
649649
}
650650

651651
subtest 'test candidate list' => sub {
@@ -664,6 +664,7 @@ subtest 'test candidate list' => sub {
664664

665665
$expected_candidates{'sudo-passwordprompt'} = ['68%: sudo-passwordprompt-lxde', '52%: sudo-passwordprompt'];
666666
test_with_error(1, 0.1, \@tags, \%expected_candidates, '68%, 52%');
667+
667668
$expected_candidates{'sudo-passwordprompt'} = ['100%: sudo-passwordprompt-lxde', '52%: sudo-passwordprompt'];
668669
test_with_error(1, 0, \@tags, \%expected_candidates, '100%, 52%');
669670

0 commit comments

Comments
 (0)