Copilot commented on code in PR #7241:
URL: https://github.com/apache/texera/pull/7241#discussion_r3695197797
##########
frontend/src/app/workspace/component/workflow-editor/mini-map/mini-map.component.spec.ts:
##########
@@ -49,13 +130,276 @@ describe("MiniMapComponent", () => {
}).compileComponents();
});
+ // The fixture is created but NOT change-detected here: ngAfterViewInit reads
+ // the mini-map container's size and the persisted flag, so each test sets
its
+ // own environment up before triggering it.
beforeEach(() => {
fixture = TestBed.createComponent(MiniMapComponent);
- TestBed.inject(WorkflowActionService);
- fixture.detectChanges();
+ component = fixture.componentInstance;
+ workflowActionService = TestBed.inject(WorkflowActionService);
+ panelService = TestBed.inject(PanelService);
});
+ /** Gives the mini-map container a size, which jsdom otherwise reports as 0.
*/
+ function sizeMiniMapContainer(width: number, height: number): HTMLElement {
+ const map = fixture.nativeElement.querySelector("#mini-map") as
HTMLElement;
+ Object.defineProperty(map, "offsetWidth", { value: width, configurable:
true });
+ Object.defineProperty(map, "offsetHeight", { value: height, configurable:
true });
+ return map;
+ }
+
+ /**
+ * The mini-map reads the main editor's element out of the document by id, so
+ * mount a stand-in with an explicit size and viewport rect.
+ */
+ function mountWorkflowEditorStub(width: number, height: number, left:
number, top: number): HTMLDivElement {
+ const editor = document.createElement("div");
+ editor.id = "workflow-editor";
+ Object.defineProperty(editor, "offsetWidth", { value: width, configurable:
true });
+ Object.defineProperty(editor, "offsetHeight", { value: height,
configurable: true });
+ editor.getBoundingClientRect = () => ({ left, top, right: left + width,
bottom: top + height }) as DOMRect;
+ document.body.appendChild(editor);
+ editorStub = editor;
+ return editor;
+ }
+
+ /** Publishes `paper` on the stream the mini-map subscribes to in
ngAfterViewInit. */
+ function attachMainPaper(paper: StubPaper): void {
+
(workflowActionService.getJointGraphWrapper().getMainJointPaperAttachedStream()
as Subject<joint.dia.Paper>).next(
+ paper as unknown as joint.dia.Paper
+ );
Review Comment:
`attachMainPaper` is calling `.next()` by casting the return of
`getMainJointPaperAttachedStream()` (declared as `Observable<Paper>`) to a
`Subject`. This couples the spec to `JointGraphWrapper`'s current
implementation detail (a `ReplaySubject`), and will fail (or silently stop
emitting) if the wrapper is ever changed to return `asObservable()`.
Consider stubbing the stream via `vi.spyOn(jointGraphWrapper,
"getMainJointPaperAttachedStream").mockReturnValue(mainPaper$.asObservable())`
and emitting through `mainPaper$`, or exposing a test helper API for attaching
a paper.
--
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]