This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/main by this push:
new e30e1603bb test(frontend): cover the heat-map overlay wiring in the
editor (#8629)
e30e1603bb is described below
commit e30e1603bb22c027513718122827749c55f767c8
Author: Prateek Ganigi <[email protected]>
AuthorDate: Wed Nov 4 22:42:12 2026 +0000
test(frontend): cover the heat-map overlay wiring in the editor (#8629)
### What changes were proposed in this PR?
The heat-map overlay's pure logic is well covered, but the editor-side
wiring shipped without specs in #6213. This adds them. Test-only: no
production code changes, so no behaviour change and nothing to
screenshot.
22 tests covering `handleHeatmapOverlay`, `repaintHeatmapColors`,
`restoreAllOperatorFills` and `handleHeatmapHover`, in four groups:
| Group | Covers |
| --- | --- |
| Painting | Spread on view select, repaint on new metrics, inert while
off, no-metrics and not-measurable-for-view operators painted as
no-data, operators added while the overlay is on and off |
| Turning off | Fills restored respecting each operator's disabled
state, `.heatmap-active` toggled, an open tooltip cleared |
| Disable/enable repaint | The #6213 regression, both directions, plus
the overlay-off case |
| Hover tooltip | Metric and score, inert while off, non-operator cells
ignored, em dash for missing metrics and for an unmeasurable view,
position relative to the editor, mouseleave clearing, both
change-detection skips |
The tests drive the real paper and the real `JointUIService` and assert
actual `rect.body/fill` values against `scoreToColor` and
`HEATMAP_NO_DATA_COLOR`. A spy on `applyHeatmapColor` would pass even
when `changeOperatorDisableStatus` overwrites the fill afterwards, which
is the exact failure the disable/enable regression exists to catch.
Metrics are published through `statisticsSubject` rather than pushed
onto the derived stream, so the scoring under test is the one the
service actually derives.
The `ngOnDestroy` view reset already has a spec and is not duplicated
here.
### Any related issues, documentation, discussions?
Closes #7491. Follow-up from #6213. Part of umbrella #5772.
### How was this PR tested?
The specs are the change. Each one was verified to fail for its own
reason by deleting the behaviour it covers and re-running:
| Deleted from `workflow-editor.component.ts` | Tests that failed |
| --- | --- |
| The `getDisabledOperatorsChangedStream` repaint | 2 |
| The operator-add repaint | 1 |
| `restoreAllOperatorFills()` on overlay off | 1 |
| The `.heatmap-active` class toggle | 1 |
| The hover `hasOperator` guard | 1 |
| The tooltip clear on overlay off | 1 |
```
cd frontend && ng test --watch=false --include
"**/workflow-editor.component.spec.ts"
```
139 passing, up from 117. Statement coverage of the wiring (lines
429-564) is 46/46, and the file overall is 626/627.
Full frontend suite: 6203 passing, 1 skipped. `tsc --noEmit` (strict),
`eslint ./src` and Prettier are clean.
### Was this PR authored or co-authored using generative AI tooling?
This PR was co-authored by Claude, in compliance with ASF.
---------
Co-authored-by: Xuan Gu <[email protected]>
---
.../workflow-editor.component.spec.ts | 281 +++++++++++++++++++++
1 file changed, 281 insertions(+)
diff --git
a/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts
b/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts
index 3b419e683a..41fdc95e4c 100644
---
a/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts
+++
b/frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts
@@ -19,6 +19,7 @@
import { WorkflowActionService } from
"../../service/workflow-graph/model/workflow-action.service";
import { HeatmapView } from "../../service/heatmap/heatmap-scoring";
+import { HEATMAP_NO_DATA_COLOR, scoreToColor } from
"../../service/heatmap/heatmap-color";
import { UndoRedoService } from "../../service/undo-redo/undo-redo.service";
import { DragDropService } from "../../service/drag-drop/drag-drop.service";
import { WorkflowUtilService } from
"../../service/workflow-graph/util/workflow-util.service";
@@ -2417,4 +2418,284 @@ describe("WorkflowEditorComponent editor wiring", () =>
{
expect(detectChanges).toHaveBeenCalledTimes(1);
});
});
+
+ describe("heat-map overlay", () => {
+ const HOT = scoreToColor(1);
+ const COLD = scoreToColor(0);
+ const ENABLED_FILL = "#FFFFFF";
+ const DISABLED_FILL = "#E0E0E0";
+
+ const wrapper = () => workflowActionService.getJointGraphWrapper();
+ const fillOf = (operatorID: string) =>
component.paper.getModelById(operatorID).attr("rect.body/fill");
+
+ /**
+ * Drives the real statistics -> performance-metrics chain rather than
pushing metrics
+ * directly, so the scoring the overlay reads is the one the service
derives.
+ */
+ function publishStatistics(byOperator: Record<string, { dataNs?: number;
inRows?: number; outRows?: number }>) {
+ const payload: Record<string, unknown> = {};
+ for (const [operatorID, m] of Object.entries(byOperator)) {
+ payload[operatorID] = {
+ ...emptyStatistics,
+ aggregatedDataProcessingTime: m.dataNs ?? 0,
+ aggregatedInputRowCount: m.inRows ?? 0,
+ aggregatedOutputRowCount: m.outRows ?? 0,
+ };
+ }
+ (workflowStatusService as any).statisticsSubject.next(payload);
+ }
+
+ /** scan is the hot operator, result the cold one, under the Runtime view.
*/
+ function addTwoOperatorsWithSpread() {
+ workflowActionService.addOperator(mockScanPredicate, mockPoint);
+ workflowActionService.addOperator(mockResultPredicate, mockPoint);
+ publishStatistics({
+ [mockScanPredicate.operatorID]: { dataNs: 1_000_000_000, inRows: 100,
outRows: 10 },
+ [mockResultPredicate.operatorID]: { dataNs: 0, inRows: 10, outRows: 10
},
+ });
+ }
+
+ function hoverOver(operatorID: string, clientX = 0, clientY = 0): void {
+ const view = component.paper.findViewByModel(operatorID);
+ (component.paper as any).trigger("element:mouseenter", view, { clientX,
clientY });
+ }
+
+ describe("painting", () => {
+ it("paints the heat spread as soon as a view is selected", () => {
+ addTwoOperatorsWithSpread();
+
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(HOT);
+ expect(fillOf(mockResultPredicate.operatorID)).toEqual(COLD);
+ });
+
+ it("repaints when new metrics arrive while a view is active", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ // The spread inverts: result becomes the slow one.
+ publishStatistics({
+ [mockScanPredicate.operatorID]: { dataNs: 0 },
+ [mockResultPredicate.operatorID]: { dataNs: 1_000_000_000 },
+ });
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(COLD);
+ expect(fillOf(mockResultPredicate.operatorID)).toEqual(HOT);
+ });
+
+ it("leaves fills alone while no view is active, even as metrics stream
in", () => {
+ addTwoOperatorsWithSpread();
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(ENABLED_FILL);
+ expect(fillOf(mockResultPredicate.operatorID)).toEqual(ENABLED_FILL);
+ });
+
+ it("paints an operator with no metrics as no-data rather than coldest",
() => {
+ // Absent from the payload entirely: it must not anchor the scale
minimum.
+ workflowActionService.addOperator(mockScanPredicate, mockPoint);
+ workflowActionService.addOperator(mockResultPredicate, mockPoint);
+ publishStatistics({ [mockScanPredicate.operatorID]: { dataNs:
1_000_000_000 } });
+
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+
expect(fillOf(mockResultPredicate.operatorID)).toEqual(HEATMAP_NO_DATA_COLOR);
+ });
+
+ it("paints an operator the active view cannot measure as no-data", () =>
{
+ // I/O imbalance is undefined without input rows (a source), which is
a different
+ // thing from measuring zero.
+ addTwoOperatorsWithSpread();
+ publishStatistics({
+ [mockScanPredicate.operatorID]: { inRows: 0, outRows: 500 },
+ [mockResultPredicate.operatorID]: { inRows: 100, outRows: 1 },
+ });
+
+ wrapper().setHeatmapView(HeatmapView.IoImbalance);
+
+
expect(fillOf(mockScanPredicate.operatorID)).toEqual(HEATMAP_NO_DATA_COLOR);
+ expect(fillOf(mockResultPredicate.operatorID)).toEqual(HOT);
+ });
+
+ it("paints an operator added while the overlay is on", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ workflowActionService.addOperator(mockSentimentPredicate, mockPoint);
+
+
expect(fillOf(mockSentimentPredicate.operatorID)).toEqual(HEATMAP_NO_DATA_COLOR);
+ });
+
+ it("leaves an operator added while the overlay is off with its default
fill", () => {
+ addTwoOperatorsWithSpread();
+
+ workflowActionService.addOperator(mockSentimentPredicate, mockPoint);
+
+
expect(fillOf(mockSentimentPredicate.operatorID)).toEqual(ENABLED_FILL);
+ });
+ });
+
+ describe("turning the overlay off", () => {
+ it("restores default fills, respecting each operator's disabled state",
() => {
+ addTwoOperatorsWithSpread();
+
workflowActionService.disableOperators([mockResultPredicate.operatorID]);
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ wrapper().setHeatmapView(null);
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(ENABLED_FILL);
+ expect(fillOf(mockResultPredicate.operatorID)).toEqual(DISABLED_FILL);
+ });
+
+ it("toggles the transition-scoping class with the overlay", () => {
+ const editor = (component as any).editor as HTMLElement;
+
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+ expect(editor.classList.contains("heatmap-active")).toBe(true);
+
+ wrapper().setHeatmapView(null);
+ expect(editor.classList.contains("heatmap-active")).toBe(false);
+ });
+
+ it("clears a tooltip left open when the overlay is switched off", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+ hoverOver(mockScanPredicate.operatorID);
+ expect(component.heatmapTooltip).not.toBeNull();
+
+ wrapper().setHeatmapView(null);
+
+ expect(component.heatmapTooltip).toBeNull();
+ });
+ });
+
+ describe("disable/enable repaint", () => {
+ // Regression for the fix in #6213: changeOperatorDisableStatus rewrites
the body fill
+ // with colors this overlay owns, so without the repaint the operator
goes grey/white
+ // mid-overlay and stays that way on an otherwise idle workflow.
+ it("repaints with heat colors after an operator is disabled", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ workflowActionService.disableOperators([mockScanPredicate.operatorID]);
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(HOT);
+ });
+
+ it("repaints with heat colors after an operator is re-enabled", () => {
+ addTwoOperatorsWithSpread();
+ workflowActionService.disableOperators([mockScanPredicate.operatorID]);
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ workflowActionService.enableOperators([mockScanPredicate.operatorID]);
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(HOT);
+ });
+
+ it("lets the disabled fill through while the overlay is off", () => {
+ addTwoOperatorsWithSpread();
+
+ workflowActionService.disableOperators([mockScanPredicate.operatorID]);
+
+ expect(fillOf(mockScanPredicate.operatorID)).toEqual(DISABLED_FILL);
+ });
+ });
+
+ describe("hover tooltip", () => {
+ it("reports the metric and heat score of the hovered operator", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ hoverOver(mockScanPredicate.operatorID);
+
+ expect(component.heatmapTooltip).toMatchObject({
+ title: "Runtime",
+ metricLabel: "1.00 s",
+ heatLabel: "100%",
+ });
+ });
+
+ it("stays hidden while the overlay is off", () => {
+ addTwoOperatorsWithSpread();
+
+ hoverOver(mockScanPredicate.operatorID);
+
+ expect(component.heatmapTooltip).toBeNull();
+ });
+
+ it("ignores a cell that is not an operator", () => {
+ addTwoOperatorsWithSpread();
+ workflowActionService.addCommentBox(commentBox);
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ hoverOver(commentBox.commentBoxID);
+
+ expect(component.heatmapTooltip).toBeNull();
+ });
+
+ it("shows an em dash for an operator with no metrics at all", () => {
+ // Both labels read "—": neither absence can be mistaken for a
measured zero.
+ workflowActionService.addOperator(mockScanPredicate, mockPoint);
+ workflowActionService.addOperator(mockResultPredicate, mockPoint);
+ publishStatistics({ [mockResultPredicate.operatorID]: { dataNs:
1_000_000_000 } });
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+
+ hoverOver(mockScanPredicate.operatorID);
+
+ expect(component.heatmapTooltip).toMatchObject({ metricLabel: "—",
heatLabel: "—" });
+ });
+
+ it("shows an em dash for a view the operator cannot be measured in", ()
=> {
+ // Metrics exist, but I/O imbalance is undefined without input rows,
so the metric
+ // is a dash while the operator is still known.
+ addTwoOperatorsWithSpread();
+ publishStatistics({ [mockScanPredicate.operatorID]: { inRows: 0,
outRows: 500 } });
+ wrapper().setHeatmapView(HeatmapView.IoImbalance);
+
+ hoverOver(mockScanPredicate.operatorID);
+
+ expect(component.heatmapTooltip).toMatchObject({ title: "I/O
imbalance", metricLabel: "—", heatLabel: "—" });
+ });
+
+ it("positions the tooltip relative to the editor, offset off the
cursor", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+ const rect = ((component as any).editor as
HTMLElement).getBoundingClientRect();
+
+ hoverOver(mockScanPredicate.operatorID, 200, 150);
+
+ expect(component.heatmapTooltip).toMatchObject({ x: 200 - rect.left +
12, y: 150 - rect.top + 12 });
+ });
+
+ it("clears the tooltip on mouseleave", () => {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+ hoverOver(mockScanPredicate.operatorID);
+
+ (component.paper as any).trigger("element:mouseleave");
+
+ expect(component.heatmapTooltip).toBeNull();
+ });
+
+ it("skips the change-detection pass when there is nothing to clear", ()
=> {
+ addTwoOperatorsWithSpread();
+ wrapper().setHeatmapView(HeatmapView.Runtime);
+ const detectChanges = vi.spyOn((component as any).changeDetectorRef,
"detectChanges");
+
+ (component.paper as any).trigger("element:mouseleave");
+
+ expect(detectChanges).not.toHaveBeenCalled();
+ });
+
+ it("stays inert on mouseleave while the overlay is off", () => {
+ addTwoOperatorsWithSpread();
+ const detectChanges = vi.spyOn((component as any).changeDetectorRef,
"detectChanges");
+
+ (component.paper as any).trigger("element:mouseleave");
+
+ expect(component.heatmapTooltip).toBeNull();
+ expect(detectChanges).not.toHaveBeenCalled();
+ });
+ });
+ });
});