diff --git a/src/main/resources/hudson/tasks/test/AbstractTestResultAction/show-failures.js b/src/main/resources/hudson/tasks/test/AbstractTestResultAction/show-failures.js new file mode 100644 index 000000000..bd84bb7ad --- /dev/null +++ b/src/main/resources/hudson/tasks/test/AbstractTestResultAction/show-failures.js @@ -0,0 +1,33 @@ +/** +* Displays all the tests failures, and hides the link allowing to display them from UI. +*/ +function showFailures() { + // Displaying all the hidden elements from the page (those are the failed tests) + let hiddenElements = document.getElementsByClassName("hidden"); + + // DEV MEMO: + // hiddenElements is not an array but an HTMLCollection. + // To allow using forEach, we need an array, so I'm using the spread operator below to get that. + [...hiddenElements].forEach(element => { element.style.display = ""; }); + + // Now hiding the link from UI allowing to show all failed tests + let showFailuresLink = document.getElementById("showLink"); + showFailuresLink.style.display = "none"; +} + +// Adding an onclick listener to the link in UI allowing to display all failed tests +// DEV MEMO: +// We are doing it after DOM content is loaded as a good practice to ensure we are not slowing down +// the page rendering. In that particular situation the addition of the onclick handler shouldn't +// really impact the page performances, but rather stick with good practices. + +document.addEventListener('DOMContentLoaded', (event) => { + + // Retrieving the link from UI allowing to show all failed tests + // Note: we are retrieving the link by its ID to match how it was already done + // in the showFailures method above. + const showFailuresLink = document.getElementById("showLink"); + + showFailuresLink.onclick = (_) => showFailures(); + +}); diff --git a/src/main/resources/hudson/tasks/test/AbstractTestResultAction/summary.jelly b/src/main/resources/hudson/tasks/test/AbstractTestResultAction/summary.jelly index a06c09509..382400558 100644 --- a/src/main/resources/hudson/tasks/test/AbstractTestResultAction/summary.jelly +++ b/src/main/resources/hudson/tasks/test/AbstractTestResultAction/summary.jelly @@ -26,17 +26,7 @@ THE SOFTWARE. - + @@ -75,8 +65,7 @@ THE SOFTWARE. ${%Show all failed tests} ${">>>"} + href="#showFailuresLink">${%Show all failed tests} ${">>>"}