mengw15 commented on code in PR #7541:
URL: https://github.com/apache/texera/pull/7541#discussion_r3755678656
##########
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:
Valid — two of these tests spy on `console.error` and nothing restored it,
so it would outlive them. Applied `vi.restoreAllMocks()` in the block's
`afterEach`.
Heads-up on the autofix commit that accompanied this: it reindented the
whole `afterEach` to column 0, which fails `yarn --cwd frontend format:ci` (the
repo's lint step) and turned all three frontend jobs red. I've superseded it
with the same change at the correct indentation; `format:ci` is clean locally.
--
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]