aglinxinyuan commented on code in PR #7241:
URL: https://github.com/apache/texera/pull/7241#discussion_r3695217094
##########
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:
Agreed — fixed in ee52720fca, using the `vi.spyOn(...).mockReturnValue(...)`
approach you suggested.
The suite now owns a `ReplaySubject<joint.dia.Paper>(1)` and stubs the
getter to return `mainPaper$.asObservable()`, so it depends only on the
declared `Observable<Paper>` type. `attachMainPaper` pushes through the subject
it owns.
Confirmed the concern is real rather than theoretical:
`getMainJointPaperAttachedStream()` is declared `Observable<joint.dia.Paper>`
(joint-graph-wrapper.ts:213) and just returns the backing field, so the cast
worked purely by implementation accident. Switching it to `.asObservable()`
would have made `.next()` undefined at runtime — a silent break, since the cast
type-checks either way.
`ReplaySubject(1)` rather than a plain `Subject` so a paper attached before
the component subscribes in `ngAfterViewInit` is still delivered. All 16 tests
still pass.
--
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]