From b1590ed189060cf92660347d1cbd63569cbb3b1a Mon Sep 17 00:00:00 2001 From: Ioannis Bonatakis Date: Mon, 30 Sep 2024 22:48:49 +0200 Subject: [PATCH] Add option to restart jobs upon comment submission - Renamed `addComments` to `bulkJobsAction` to handle both commenting and restarting jobs. - Added button-specific actions using `form.clickedButton`. - Updated `fetchWithCSRF` logic to dynamically determine request URLs based on the button clicked. - Introduced separate success and error messages for restarting and commenting actions. - Updated HTML to include "Restart and Comment" and "Comment" buttons with individual data URLs. - Adjusted modal to allow submission of comments or restarts through the correct action handlers. These updates enhance the user experience by allowing users to either comment on jobs, or perform restart with a comment simultaneously from the overview page. Comments always add to the original job of the overview page. By integrating this functionality we provide a workflow for users managing multiple jobs on the overview page. https://progress.opensuse.org/issues/166559 Signed-off-by: Ioannis Bonatakis --- assets/javascripts/overview.js | 37 +++++++++++--- t/ui/10-tests_overview.t | 70 ++++++++++++++++++-------- templates/webapi/test/overview.html.ep | 21 +++++--- 3 files changed, 93 insertions(+), 35 deletions(-) diff --git a/assets/javascripts/overview.js b/assets/javascripts/overview.js index 003f65f6cbcd..71e531a9a7b2 100644 --- a/assets/javascripts/overview.js +++ b/assets/javascripts/overview.js @@ -287,11 +287,13 @@ function showAddCommentsDialog() { modal.show(); } -function addComments(form) { +function bulkJobsAction(form) { const text = form.elements.text.value; if (!text.length) { return window.alert("The comment text mustn't be empty."); } + const actionBtn = form.clickedButton.value; + let reqUrl = form.clickedButton.dataset.url || form.action; const progressIndication = document.getElementById('add-comments-progress-indication'); const controls = document.getElementById('add-comments-controls'); progressIndication.style.display = 'flex'; @@ -301,17 +303,38 @@ function addComments(form) { controls.style.display = 'inline'; window.addCommentsModal.hide(); }; - fetchWithCSRF(form.action, {method: 'POST', body: new FormData(form)}) + + let infoTxt = + 'The comments have been created. Reload the page to show changes.'; + let errTxt = 'The comments could not be added:'; + if (actionBtn == 'restartAndCommentJobs') { + infoTxt = 'Reload the page to show restarted jobs.'; + errTx = 'Failed to restart jobs: '; + } + fetchWithCSRF(reqUrl, {method: 'POST', body: new FormData(form)}) .then(response => { if (!response.ok) throw `Server returned ${response.status}: ${response.statusText}`; - addFlash( - 'info', - 'The comments have been created. Reload the page to show changes.' - ); + addFlash('info', infoTxt); done(); }) .catch(error => { - addFlash('danger', `The comments could not be added: ${error}`); + addFlash('danger', `${errTxt} ${error}`); done(); }); + + if (actionBtn == 'restartAndCommentJobs') { + //const commenttUrl = document.getElementById('CommentJobsBtn').dataset.url; + reqUrl = document.getElementById('CommentJobsBtn').dataset.url; + console.log('iob ' + reqUrl); + fetchWithCSRF(reqUrl, {method: 'POST', body: new FormData(form)}) + .then(response => { + if (!response.ok) throw `Server returned ${response.status}: ${response.statusText}`; + addFlash('info', 'The comments have been created on the previous jobs'); + done(); + }) + .catch(error => { + addFlash('danger', `The comments could not be added: ${error}`); + done(); + }); + } } diff --git a/t/ui/10-tests_overview.t b/t/ui/10-tests_overview.t index e3dc27eb633a..aea99fd448ef 100644 --- a/t/ui/10-tests_overview.t +++ b/t/ui/10-tests_overview.t @@ -543,18 +543,35 @@ subtest 'filter by result and state' => sub { ok !$driver->find_element_by_id('filter-failed')->is_selected, 'other checkbox not checked'; }; + +subtest "job template names displayed on 'Test result overview' page" => sub { + $driver->get('/group_overview/1002'); + is($driver->find_element('.progress-bar-unfinished')->get_text(), + '1 unfinished', 'The number of unfinished jobs is right'); + + $driver->get('/tests/overview?distri=opensuse&version=13.1&build=0091&groupid=1002'); + my @tds = $driver->find_elements('#results_DVD tbody tr .name'); + is($tds[0]->get_text(), 'kde_variant', 'job template name kde_variant displayed correctly'); + + my @descriptions = $driver->find_elements('td.name a', 'css'); + is(scalar @descriptions, 2, 'only test suites with description content are shown as links'); + disable_bootstrap_animations; + $descriptions[0]->click(); + is(wait_for_element(selector => '.popover-header')->get_text, 'kde_variant', 'description popover shows content'); +}; + subtest 'add comments' => sub { - my @buttons = $driver->find_elements('button[title="Add comments"]'); + my @buttons = $driver->find_elements('button[title="Add comments or restart Jobs"]'); is @buttons, 0, 'button for adding comments not present if not logged-in'; $driver->find_element_by_link_text('Login')->click; $driver->get('/tests/overview?state=done&result=failed'); disable_bootstrap_animations; - $driver->find_element('button[title="Add comments"]')->click; + $driver->find_element('button[title="Add comments or restart Jobs"]')->click; my $comment_text = 'comment via add-comments'; - my $submit_button = $driver->find_element('#add-comments-controls button[type="submit"]'); - $driver->find_element_by_id('text')->send_keys($comment_text); - is $submit_button->get_text, 'Submit comment on all 2 jobs', 'submit button displayed with number of jobs'; + my $submit_button = $driver->find_element('#add-comments-controls button[id="CommentJobsBtn"]'); + $driver->find_element_by_id('text')->send_keys($comment_text); #sleep(300); + is $submit_button->get_text, 'Comment on all 2 jobs', 'submit button displayed with number of jobs'; $submit_button->click; wait_for_ajax msg => 'comments created'; like $driver->find_element_by_id('flash-messages')->get_text, qr/The comments have been created. Reload/, @@ -565,23 +582,32 @@ subtest 'add comments' => sub { 'comments created on all relevant jobs'; is $comments->search({job_id => {-not_in => \@failed_job_ids}, text => $comment_text})->count, 0, 'comments not created on other jobs'; -}; - -subtest "job template names displayed on 'Test result overview' page" => sub { - $driver->get('/group_overview/1002'); - is($driver->find_element('.progress-bar-failed')->get_text(), '1 failed', 'The number of failed jobs is right'); - is($driver->find_element('.progress-bar-unfinished')->get_text(), - '1 unfinished', 'The number of unfinished jobs is right'); - - $driver->get('/tests/overview?distri=opensuse&version=13.1&build=0091&groupid=1002'); - my @tds = $driver->find_elements('#results_DVD tbody tr .name'); - is($tds[0]->get_text(), 'kde_variant', 'job template name kde_variant displayed correctly'); - my @descriptions = $driver->find_elements('td.name a', 'css'); - is(scalar @descriptions, 2, 'only test suites with description content are shown as links'); - disable_bootstrap_animations; - $descriptions[0]->click(); - is(wait_for_element(selector => '.popover-header')->get_text, 'kde_variant', 'description popover shows content'); + subtest 'restart jobs with comment' => sub { + my @buttons = $driver->find_elements('button[title="Add comments or restart Jobs"]'); + use Data::Dumper; + #diag(Dumper($jobs)); + $driver->get('/tests/overview?state=done&result=failed'); + disable_bootstrap_animations; + $driver->find_element('button[title="Add comments or restart Jobs"]')->click; + my $comment_text = 'comment current jobs and restart'; + my $submit_button = $driver->find_element('#add-comments-controls button[id="restartAndCommentJobsBtn"]'); + $driver->find_element_by_id('text')->send_keys($comment_text); + is $submit_button->get_text, 'Restart and Comment 2 jobs', 'submit button displayed with number of jobs'; + $submit_button->click; + wait_for_ajax msg => 'comments created'; + like $driver->find_element_by_id('flash-messages')->get_text, qr/Reload the page to show restarted jobs/, + 'info about successful restart shown'; # 99990 99946 //*[@id="flash-messages"]/div[1]/span/a + #like $driver->find_element_by_id('flash-messages')->get_text, qr/Reload the page to show restarted Jobs/, + # 'info about successful comment submition shown'; + my @failed_job_ids = map { $_->id } $jobs->search({result => FAILED})->all; + is $comments->search({job_id => {-in => \@failed_job_ids}, text => $comment_text})->count, 2, + 'comments created on all relevant jobs'; + is $comments->search({job_id => {-not_in => \@failed_job_ids}, text => $comment_text})->count, 0, + 'comments not created on other jobs'; + my $running_job_ids = map { $_->id } $jobs->search({state => RUNNING})->all; + is $running_job_ids, 2, 'all relevant jobs restarted'; + }; }; subtest "job dependencies displayed on 'Test result overview' page" => sub { @@ -591,7 +617,7 @@ subtest "job dependencies displayed on 'Test result overview' page" => sub { my @child_elements = $driver->find_child_elements($deps, 'a'); my $details = $child_elements[0]; like $details->get_attribute('href'), qr{tests/99963\#dependencies}, 'job href is shown correctly'; - is $details->get_attribute('title'), "1 parallel parent\ndependency passed", 'dependency is shown correctly'; + is $details->get_attribute('title'), "1 parallel parent\ndependency failed", 'dependency is shown correctly'; my $parent_ele = $driver->find_element('td#res_DVD_i586_kde .parents_children'); $driver->move_to(element => $parent_ele); diff --git a/templates/webapi/test/overview.html.ep b/templates/webapi/test/overview.html.ep index 28b00a37b3e1..fae9fd482ab1 100644 --- a/templates/webapi/test/overview.html.ep +++ b/templates/webapi/test/overview.html.ep @@ -42,7 +42,8 @@
% my $allow_commenting = @$job_ids && current_user; % if ($allow_commenting) { - % } @@ -217,7 +218,7 @@