fix(tests): preload first screenshot to avoid jump
What changed, and why it matters
This commit changes only test-reporting helper code used to generate HTML pages and animated GIFs for UI test results. It preloads the first screenshot so the displayed image does not visibly jump when the page loads. There is no change to the Trezor firmware, wallet logic, cryptography, or any code that runs on the device.
No security action needed. This is a test-reporting UI fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies two files under tests/ui_tests/reporting: create-gif.js and testreport.py. In create-gif.js, the GIF element is now reused if it already exists in the DOM, and it is only inserted if not already present. In testreport.py, the _header() helper is refactored to accept a TestResult object and directory name, and it now emits an initial
linked to the first screenshot so the JavaScript can preload it. These are purely cosmetic/test-infrastructure changes.
Changed components
tests/ui_tests/reporting/create-gif.jstests/ui_tests/reporting/testreport.pyInspect captured patch +22 / −8
diff --git a/tests/ui_tests/reporting/create-gif.js b/tests/ui_tests/reporting/create-gif.js
index 5153baac..bedcc1b7 100644
--- a/tests/ui_tests/reporting/create-gif.js
+++ b/tests/ui_tests/reporting/create-gif.js
@@ -40,8 +40,11 @@ function createGif() {
const btnClass = 'gifBtn';
// Gif itself
- const gif = document.createElement('img');
- gif.id = 'gif';
+ let gif = document.getElementById("gif");
+ if (!gif) {
+ gif = document.createElement('img');
+ gif.id = 'gif';
+ }
// Update the image source and the slider value according to the current index
// Lazy-loading all the lazy-loaded images
@@ -171,12 +174,16 @@ function createGif() {
// Insert everything above the <hr> or at the top of the page when missing
const hr = document.querySelector('hr');
if (hr) {
- hr.parentNode.insertBefore(gif, hr);
+ if (!document.contains(gif)) {
+ hr.parentNode.insertBefore(gif, hr);
+ }
hr.parentNode.insertBefore(buttonContainer, hr);
hr.parentNode.insertBefore(inputContainer, hr);
hr.parentNode.insertBefore(sliderContainer, hr);
} else {
- document.body.insertBefore(gif, document.body.firstChild);
+ if (!document.contains(gif)) {
+ document.body.insertBefore(gif, document.body.firstChild);
+ }
document.body.insertBefore(buttonContainer, document.body.firstChild);
document.body.insertBefore(inputContainer, document.body.firstChild);
document.body.insertBefore(sliderContainer, document.body.firstChild);
diff --git a/tests/ui_tests/reporting/testreport.py b/tests/ui_tests/reporting/testreport.py
index 77694676..9cf65a2f 100644
--- a/tests/ui_tests/reporting/testreport.py
+++ b/tests/ui_tests/reporting/testreport.py
@@ -44,8 +44,10 @@ ALL_SCREENS = "all_screens.html"
ALL_UNIQUE_SCREENS = "all_unique_screens.html"
-def _header(test_name: str, expected_hash: str | None, actual_hash: str) -> None:
- h1(test_name)
+def _header(result: TestResult, dir: str) -> None:
+ expected_hash, actual_hash = result.expected_hash, result.actual_hash
+
+ h1(result.test.id)
with div():
if actual_hash == expected_hash:
p(
@@ -64,6 +66,11 @@ def _header(test_name: str, expected_hash: str | None, actual_hash: str) -> None
)
p("Expected: ", expected_hash or "(new test case)")
p("Actual: ", actual_hash)
+
+ if result.images:
+ first_screen = result.images[0]
+ html.image_link(first_screen, TESTREPORT_PATH / dir, img_id="gif")
+
hr()
@@ -337,7 +344,7 @@ def failed(result: TestResult) -> Path:
with doc:
- _header(result.test.id, result.expected_hash, result.actual_hash)
+ _header(result, "failed")
with div(id="markbox", _class="script-hidden"):
p("Mark the test result as:")
@@ -389,7 +396,7 @@ def recorded(result: TestResult, header: str = "Recorded", dir: str = "passed")
with doc.head:
script(type="text/javascript", src="../testreport.js")
with doc:
- _header(result.test.id, result.actual_hash, result.actual_hash)
+ _header(result, dir)
with table(border=1):
with tr():
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.