github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/spyglass/lenses/junit/lens.ts (about) 1 const addSectionExpanders = (): void => { 2 const expanders = document.querySelectorAll<HTMLTableRowElement>('tr.section-expander'); 3 for (const expander of Array.from(expanders)) { 4 expander.onclick = () => { 5 const tbody = expander.parentElement.nextElementSibling; 6 const icon = expander.querySelector('i')!; 7 if (tbody.classList.contains('hidden-tests')) { 8 tbody.classList.remove('hidden-tests'); 9 icon.innerText = 'expand_less'; 10 } else { 11 tbody.classList.add('hidden-tests'); 12 icon.innerText = 'expand_more'; 13 } 14 spyglass.contentUpdated(); 15 }; 16 } 17 }; 18 19 const addTestExpanders = (): void => { 20 const rows = document.querySelectorAll<HTMLTableRowElement>('.failure-name,.flaky-name'); 21 for (const row of Array.from(rows)) { 22 row.onclick = () => { 23 const sibling = row.nextElementSibling; 24 const icon = row.querySelector('i')!; 25 if (sibling.classList.contains('hidden')) { 26 sibling.classList.remove('hidden'); 27 icon.innerText = 'expand_less'; 28 } else { 29 sibling.classList.add('hidden'); 30 icon.innerText = 'expand_more'; 31 } 32 spyglass.contentUpdated(); 33 }; 34 } 35 }; 36 37 const addStdoutStderrOpeners = (): void => { 38 const links = document.querySelectorAll<HTMLAnchorElement>('a.open-stdout-stderr'); 39 for (const link of Array.from(links)) { 40 link.onclick = (e) => { 41 e.preventDefault(); 42 const text = (link.nextElementSibling as HTMLElement).innerHTML; 43 const blob = new Blob([` 44 <head> 45 <meta charset="UTF-8"> 46 <title>Logs</title> 47 </head> 48 <body style="background-color: #303030; color: white; font-family: monospace; white-space: pre-wrap;">${text}</body>`], {type: 'text/html'}); 49 window.open(URL.createObjectURL(blob)); 50 }; 51 } 52 }; 53 54 const loaded = (): void => { 55 addTestExpanders(); 56 addStdoutStderrOpeners(); 57 addSectionExpanders(); 58 }; 59 60 window.addEventListener('DOMContentLoaded', loaded);