Copilot commented on code in PR #7541:
URL: https://github.com/apache/texera/pull/7541#discussion_r3755551800


##########
frontend/src/app/workspace/service/report-generation/report-generation.service.spec.ts:
##########
@@ -291,5 +335,145 @@ describe("ReportGenerationService", () => {
         "Workflow editor element not found"
       );
     });
+
+    /**
+     * Before the editor can be rendered, every <image> in it is refetched and 
inlined as
+     * base64 so the snapshot does not depend on URLs the renderer cannot 
resolve. Both async
+     * sources are replaced with fakes that settle synchronously (XHR) or on a 
microtask
+     * (FileReader), so nothing here depends on the network or on real timing.
+     *
+     * The html2canvas render that follows is left alone — it needs a real 
canvas — so these
+     * assert on what the inlining step did, not on the observable's outcome.
+     */
+    describe("inlining the editor's images", () => {
+      const XLINK_HREF = "xlink:href";
+      const BASE64 = "data:image/png;base64,AAAA";
+
+      let realXhr: typeof globalThis.XMLHttpRequest;
+      let realFileReader: typeof globalThis.FileReader;
+      let editor: HTMLElement;
+      let xhrOutcome: "load" | "error";
+      let readerOutcome: "loadend" | "error";
+      let sentUrls: string[];
+
+      class FakeXhr {
+        public response: unknown = "blob-stand-in";
+        public responseType = "";
+        public onload: (() => void) | null = null;
+        public onerror: (() => void) | null = null;
+        private url = "";
+        open(_method: string, url: string): void {
+          this.url = url;
+        }
+        send(): void {
+          sentUrls.push(this.url);
+          if (xhrOutcome === "load") {
+            this.onload?.();
+          } else {
+            this.onerror?.();
+          }
+        }
+      }
+
+      class FakeFileReader {
+        public result: string | null = null;
+        public onloadend: (() => void) | null = null;
+        public onerror: (() => void) | null = null;
+        readAsDataURL(): void {
+          queueMicrotask(() => {
+            if (readerOutcome === "loadend") {
+              this.result = BASE64;
+              this.onloadend?.();
+            } else {
+              this.onerror?.();
+            }
+          });
+        }
+      }
+
+      /** Adds an SVG <image> to the editor, optionally with a source 
attribute. */
+      function addImage(src?: string): SVGElement {
+        const image = document.createElementNS("http://www.w3.org/2000/svg";, 
"image");
+        if (src !== undefined) {
+          image.setAttribute(XLINK_HREF, src);
+        }
+        editor.appendChild(image);
+        return image;
+      }
+
+      /** Runs the snapshot and resolves once it settles, whichever way 
html2canvas goes. */
+      function runSnapshot(): Promise<void> {
+        return new Promise<void>(resolve => {
+          service.generateWorkflowSnapshot("myflow").subscribe({
+            next: () => resolve(),
+            error: () => resolve(),
+          });
+        });
+      }
+
+      beforeEach(() => {
+        sentUrls = [];
+        xhrOutcome = "load";
+        readerOutcome = "loadend";
+        realXhr = globalThis.XMLHttpRequest;
+        realFileReader = globalThis.FileReader;
+        (globalThis as unknown as { XMLHttpRequest: unknown }).XMLHttpRequest 
= FakeXhr;
+        (globalThis as unknown as { FileReader: unknown }).FileReader = 
FakeFileReader;
+        editor = document.createElement("div");
+        editor.id = "workflow-editor";
+        document.body.appendChild(editor);
+      });
+
+      afterEach(() => {
+        (globalThis as unknown as { XMLHttpRequest: unknown }).XMLHttpRequest 
= realXhr;
+        (globalThis as unknown as { FileReader: unknown }).FileReader = 
realFileReader;
+        editor.remove();
+      });

Review Comment:
   The tests spy on `console.error` but never restore it. That mock will leak 
past these cases and can hide real failures or cause later tests to behave 
differently.
   
   Consider restoring mocks in this describe’s `afterEach` (or explicitly 
`consoleSpy.mockRestore()` in each test).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to