This is an automated email from the ASF dual-hosted git repository.
xuang7 pushed a commit to branch
backport/8968-block-clicks-on-disabled-context-menu-it-v1.2
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to
refs/heads/backport/8968-block-clicks-on-disabled-context-menu-it-v1.2 by this
push:
new ba66893bc7 resolve the backport conflict in
context-menu.component.spec.ts
ba66893bc7 is described below
commit ba66893bc799a1a54e77ce25c6d33ed91d598bff
Author: Xuan Gu <[email protected]>
AuthorDate: Tue Nov 3 23:20:12 2026 -0500
resolve the backport conflict in context-menu.component.spec.ts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../context-menu/context-menu.component.spec.ts | 635 ---------------------
1 file changed, 635 deletions(-)
diff --git
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
index 2cf40101fe..8bf8a0516f 100644
---
a/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
+++
b/frontend/src/app/workspace/component/workflow-editor/context-menu/context-menu/context-menu.component.spec.ts
@@ -31,7 +31,6 @@ import { of } from "rxjs";
import { ReactiveFormsModule } from "@angular/forms";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { NzDropDownModule } from "ng-zorro-antd/dropdown";
-import { NzMenuItemComponent } from "ng-zorro-antd/menu";
import { ValidationWorkflowService } from
"src/app/workspace/service/validation/validation-workflow.service";
import { NzModalModule, NzModalService } from "ng-zorro-antd/modal";
import { commonTestProviders } from
"../../../../../common/testing/test-utils"; // Import NzModalModule and
NzModalService
@@ -260,638 +259,4 @@ describe("ContextMenuComponent", () => {
expect(texeraGraphSpy.isOperatorDisabled).toHaveBeenCalledWith("op1");
});
});
-<<<<<<< HEAD
-=======
-
- describe("onCopy / onPaste", () => {
- it("should delegate onCopy to
OperatorMenuService.saveHighlightedElements", () => {
- component.onCopy();
-
-
expect(operatorMenuService.saveHighlightedElements).toHaveBeenCalledTimes(1);
- expect(operatorMenuService.performPasteOperation).not.toHaveBeenCalled();
- });
-
- it("should delegate onPaste to OperatorMenuService.performPasteOperation",
() => {
- component.onPaste();
-
-
expect(operatorMenuService.performPasteOperation).toHaveBeenCalledTimes(1);
-
expect(operatorMenuService.saveHighlightedElements).not.toHaveBeenCalled();
- });
- });
-
- describe("onCut", () => {
- it("should copy the highlighted elements before deleting them", () => {
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
-
- component.onCut();
-
-
expect(operatorMenuService.saveHighlightedElements).toHaveBeenCalledTimes(1);
-
expect(workflowActionService.deleteOperatorsAndLinks).toHaveBeenCalledWith(["op1"]);
- // cut is defined as copy followed by delete, so the ordering is behavior
-
expect(operatorMenuService.saveHighlightedElements.mock.invocationCallOrder[0]).toBeLessThan(
-
workflowActionService.deleteOperatorsAndLinks.mock.invocationCallOrder[0]
- );
- });
- });
-
- describe("hasHighlightedLinks", () => {
- it("should return false when no links are highlighted", () => {
- jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue([]);
-
- expect(component.hasHighlightedLinks()).toBe(false);
- });
-
- it("should return true when at least one link is highlighted", () => {
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(["link-1"]);
-
- expect(component.hasHighlightedLinks()).toBe(true);
- });
- });
-
- describe("onDelete", () => {
- let texeraGraphSpy: Mocked<WorkflowGraph>;
-
- beforeEach(() => {
- texeraGraphSpy = workflowActionService.getTexeraGraph() as unknown as
Mocked<WorkflowGraph>;
- });
-
- it("should delete highlighted operators, standalone links, and comment
boxes in one bundled action", () => {
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1",
"op2"]);
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(["link-9"]);
-
jointGraphWrapperSpy.getCurrentHighlightedCommentBoxIDs.mockReturnValue(["box-1"]);
- texeraGraphSpy.hasLinkWithID.mockReturnValue(true);
-
- component.onDelete();
-
- expect(texeraGraphSpy.bundleActions).toHaveBeenCalledTimes(1);
-
expect(workflowActionService.deleteOperatorsAndLinks).toHaveBeenCalledWith(["op1",
"op2"]);
-
expect(workflowActionService.deleteLinkWithID).toHaveBeenCalledWith("link-9");
-
expect(workflowActionService.deleteCommentBox).toHaveBeenCalledWith("box-1");
- });
-
- it("should perform every deletion inside the bundleActions callback", ()
=> {
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(["link-9"]);
-
jointGraphWrapperSpy.getCurrentHighlightedCommentBoxIDs.mockReturnValue(["box-1"]);
- texeraGraphSpy.hasLinkWithID.mockReturnValue(true);
- // if bundleActions never runs the callback, nothing at all may be
deleted
- texeraGraphSpy.bundleActions.mockImplementation(() => {});
-
- component.onDelete();
-
-
expect(workflowActionService.deleteOperatorsAndLinks).not.toHaveBeenCalled();
- expect(workflowActionService.deleteLinkWithID).not.toHaveBeenCalled();
- expect(workflowActionService.deleteCommentBox).not.toHaveBeenCalled();
- });
-
- it("should skip highlighted links that no longer exist in the graph", ()
=> {
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(["link-9"]);
- texeraGraphSpy.hasLinkWithID.mockReturnValue(false);
-
- component.onDelete();
-
- expect(texeraGraphSpy.hasLinkWithID).toHaveBeenCalledWith("link-9");
- expect(workflowActionService.deleteLinkWithID).not.toHaveBeenCalled();
- });
-
- it("should snapshot the highlighted IDs before deletion mutates the
highlight state", () => {
- const liveOperatorIDs = ["op1"];
- const liveLinkIDs = ["link-9"];
- const liveCommentBoxIDs = ["box-1"];
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(liveOperatorIDs);
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(liveLinkIDs);
-
jointGraphWrapperSpy.getCurrentHighlightedCommentBoxIDs.mockReturnValue(liveCommentBoxIDs);
- texeraGraphSpy.hasLinkWithID.mockReturnValue(true);
- // deleting operators unhighlights every element, as the real graph would
- workflowActionService.deleteOperatorsAndLinks.mockImplementation(() => {
- liveOperatorIDs.length = 0;
- liveLinkIDs.length = 0;
- liveCommentBoxIDs.length = 0;
- });
-
- component.onDelete();
-
-
expect(workflowActionService.deleteLinkWithID).toHaveBeenCalledWith("link-9");
-
expect(workflowActionService.deleteCommentBox).toHaveBeenCalledWith("box-1");
- });
- });
-
- describe("onClickExportHighlightedExecutionResult", () => {
- it("should open the result exportation modal with the workflow name and
context-menu source", () => {
- const modalService = TestBed.inject(NzModalService);
- const createSpy = vi.spyOn(modalService, "create").mockReturnValue({} as
any);
-
- component.onClickExportHighlightedExecutionResult();
-
- expect(createSpy).toHaveBeenCalledTimes(1);
- expect(createSpy).toHaveBeenCalledWith(
- expect.objectContaining({
- nzTitle: "Export Highlighted Operators Result",
- nzContent: ResultExportationComponent,
- nzData: {
- workflowName: "Test Workflow",
- sourceTriggered: "context-menu",
- },
- nzFooter: null,
- })
- );
- });
- });
-
- describe("highlight subscriptions", () => {
- it("should keep highlightedOperatorIds in sync with OperatorMenuService
emissions", () => {
- expect(component.highlightedOperatorIds).toEqual([]);
-
- highlightedOperatorsSubject.next(["op-a", "op-b"]);
- expect(component.highlightedOperatorIds).toEqual(["op-a", "op-b"]);
-
- highlightedOperatorsSubject.next([]);
- expect(component.highlightedOperatorIds).toEqual([]);
- });
-
- it("should keep highlightedCommentBoxIds in sync with OperatorMenuService
emissions", () => {
- expect(component.highlightedCommentBoxIds).toEqual([]);
-
- highlightedCommentBoxesSubject.next(["box-a"]);
- expect(component.highlightedCommentBoxIds).toEqual(["box-a"]);
-
- highlightedCommentBoxesSubject.next([]);
- expect(component.highlightedCommentBoxIds).toEqual([]);
- });
- });
- // ── Template menu-item (click) wiring ──
- // The class methods are covered above; these render the menu and click each
- // item so the template's *ngIf-gated (click) bindings are exercised too.
- describe("menu item click bindings", () => {
- const norm = (s: string | null) => (s ?? "").replace(/\s+/g, "
").trim().toLowerCase();
-
- /**
- * Click the rendered <li nz-menu-item> whose text matches `label`
exactly, with a real DOM
- * click so that both the nz-menu-item host listener and the template
(click) run as in the browser.
- */
- function clickItem(label: string): void {
- const items = fixture.debugElement.queryAll(By.css("li[nz-menu-item]"));
- const item = items.find(li => norm(li.nativeElement.textContent) ===
norm(label));
- if (!item) {
- throw new Error(
- `menu item "${label}" not rendered; present: [${items.map(i =>
norm(i.nativeElement.textContent)).join(" | ")}]`
- );
- }
- item.nativeElement.dispatchEvent(new MouseEvent("click", { bubbles:
true, cancelable: true }));
- }
-
- /** Whether the rendered <li nz-menu-item> with text `label` is greyed out
through nzDisabled. */
- function isItemDisabled(label: string): boolean {
- const item = fixture.debugElement
- .queryAll(By.css("li[nz-menu-item]"))
- .find(li => norm(li.nativeElement.textContent) === norm(label));
- if (!item) {
- throw new Error(`menu item "${label}" not rendered`);
- }
- return item.injector.get(NzMenuItemComponent).nzDisabled;
- }
-
- it("copy invokes onCopy", () => {
- highlightedOperatorsSubject.next(["op1"]);
- fixture.detectChanges();
- const spy = vi.spyOn(component, "onCopy").mockImplementation(() => {});
-
- clickItem("copy");
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it("cut invokes onCut", () => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
- fixture.detectChanges();
- const spy = vi.spyOn(component, "onCut").mockImplementation(() => {});
-
- clickItem("cut");
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it("paste invokes onPaste", () => {
- highlightedOperatorsSubject.next([]);
- highlightedCommentBoxesSubject.next([]);
- component.isWorkflowModifiable = true;
- fixture.detectChanges();
- const spy = vi.spyOn(component, "onPaste").mockImplementation(() => {});
-
- clickItem("paste");
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it("disable invokes operatorMenuService.disableHighlightedOperators", ()
=> {
- operatorMenuService.isDisableOperator = true;
- operatorMenuService.isDisableOperatorClickable = true;
- fixture.detectChanges();
-
- clickItem("disable");
-
-
expect(operatorMenuService.disableHighlightedOperators).toHaveBeenCalledTimes(1);
- });
-
- it("enable invokes operatorMenuService.disableHighlightedOperators", () =>
{
- operatorMenuService.isDisableOperator = false;
- operatorMenuService.isDisableOperatorClickable = true;
- fixture.detectChanges();
-
- clickItem("enable");
-
-
expect(operatorMenuService.disableHighlightedOperators).toHaveBeenCalledTimes(1);
- });
-
- it("view result invokes
operatorMenuService.viewResultHighlightedOperators", () => {
- operatorMenuService.isToViewResult = true;
- operatorMenuService.isToViewResultClickable = true;
- fixture.detectChanges();
-
- clickItem("view result");
-
-
expect(operatorMenuService.viewResultHighlightedOperators).toHaveBeenCalledTimes(1);
- });
-
- it("remove view result invokes
operatorMenuService.viewResultHighlightedOperators", () => {
- operatorMenuService.isToViewResult = false;
- operatorMenuService.isToViewResultClickable = true;
- fixture.detectChanges();
-
- clickItem("remove view result");
-
-
expect(operatorMenuService.viewResultHighlightedOperators).toHaveBeenCalledTimes(1);
- });
-
- it("reuse result renders greyed out and does nothing when clicked", () => {
- operatorMenuService.isMarkForReuse = true;
- operatorMenuService.isReuseResultClickable = true;
- fixture.detectChanges();
-
- expect(isItemDisabled("reuse result")).toBe(true);
-
- clickItem("reuse result");
-
-
expect(operatorMenuService.reuseResultHighlightedOperator).not.toHaveBeenCalled();
- });
-
- it("remove reusing result invokes
operatorMenuService.reuseResultHighlightedOperator", () => {
- operatorMenuService.isMarkForReuse = false;
- operatorMenuService.isReuseResultClickable = true;
- fixture.detectChanges();
-
- clickItem("remove reusing result");
-
-
expect(operatorMenuService.reuseResultHighlightedOperator).toHaveBeenCalledTimes(1);
- });
-
- it("delete invokes onDelete when operators are highlighted", () => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
- fixture.detectChanges();
- const spy = vi.spyOn(component, "onDelete").mockImplementation(() => {});
-
- clickItem("delete");
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it("delete invokes onDelete for a links-only selection", () => {
- highlightedOperatorsSubject.next([]);
- highlightedCommentBoxesSubject.next([]);
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(["link1"]);
- component.isWorkflowModifiable = true;
- fixture.detectChanges();
- const spy = vi.spyOn(component, "onDelete").mockImplementation(() => {});
-
- clickItem("delete");
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- // The Form View's edit mode turns modification on for the property panel
while its embedded
- // preview stays structure-locked; the lock has to reach the menu, or
right-click on the preview
- // could still re-shape the graph.
- describe("under a structure lock", () => {
- const renderedLabels = () =>
- fixture.debugElement.queryAll(By.css("li[nz-menu-item]")).map(li =>
norm(li.nativeElement.textContent));
-
- it("keeps cut, delete, disable and enable off even with modification
enabled", () => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
- component.structureLocked = true;
- operatorMenuService.isDisableOperator = true;
- operatorMenuService.isDisableOperatorClickable = true;
- operatorMenuService.isToViewResult = true;
- operatorMenuService.isToViewResultClickable = true;
- fixture.detectChanges();
-
- const labels = renderedLabels();
- expect(labels).not.toContain("cut");
- expect(labels).not.toContain("delete");
- expect(labels).not.toContain("disable");
- // Copying and the result toggle do not re-shape the graph, so they
stay.
- expect(labels).toContain("copy");
- expect(labels).toContain("view result");
-
- operatorMenuService.isDisableOperator = false;
- fixture.detectChanges();
- expect(renderedLabels()).not.toContain("enable");
- });
-
- it("keeps paste and link deletion off", () => {
- component.isWorkflowModifiable = true;
- component.structureLocked = true;
- highlightedOperatorsSubject.next([]);
- highlightedCommentBoxesSubject.next([]);
- fixture.detectChanges();
- expect(renderedLabels()).not.toContain("paste");
-
-
jointGraphWrapperSpy.getCurrentHighlightedLinkIDs.mockReturnValue(["link1"]);
- fixture.detectChanges();
- expect(renderedLabels()).not.toContain("delete");
- });
-
- it("canModify needs modification on and no structure lock", () => {
- component.isWorkflowModifiable = true;
- component.structureLocked = false;
- expect(component.canModify).toBe(true);
-
- component.structureLocked = true;
- expect(component.canModify).toBe(false);
-
- component.structureLocked = false;
- component.isWorkflowModifiable = false;
- expect(component.canModify).toBe(false);
- });
- });
-
- it("execute to this operator invokes executeUpToOperator", () => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
- validationWorkflowService.validateOperator.mockReturnValue({ isValid:
true });
- (workflowActionService.getTexeraGraph() as unknown as
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
- false
- );
- fixture.detectChanges();
- expect(component.canExecuteOperator()).toBe(true); // item is enabled
-
- clickItem("execute to this operator");
-
- expect(operatorMenuService.executeUpToOperator).toHaveBeenCalledTimes(1);
- });
-
- it("execute to this operator does nothing while the item is greyed out",
() => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
- validationWorkflowService.validateOperator.mockReturnValue({ isValid:
false, messages: {} });
- fixture.detectChanges();
- expect(component.canExecuteOperator()).toBe(false);
-
- expect(isItemDisabled("execute to this operator")).toBe(true);
-
- clickItem("execute to this operator");
-
- expect(operatorMenuService.executeUpToOperator).not.toHaveBeenCalled();
- });
-
- it("execute to this operator does nothing while the workflow is not
modifiable", () => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = false;
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
- validationWorkflowService.validateOperator.mockReturnValue({ isValid:
true });
- (workflowActionService.getTexeraGraph() as unknown as
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
- false
- );
- fixture.detectChanges();
- expect(component.canExecuteOperator()).toBe(false);
-
- expect(isItemDisabled("execute to this operator")).toBe(true);
-
- clickItem("execute to this operator");
-
- expect(operatorMenuService.executeUpToOperator).not.toHaveBeenCalled();
- });
-
- it("execute to this operator does nothing while the operator is disabled",
() => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
- validationWorkflowService.validateOperator.mockReturnValue({ isValid:
true });
- (workflowActionService.getTexeraGraph() as unknown as
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
- true
- );
- fixture.detectChanges();
- expect(component.canExecuteOperator()).toBe(false);
-
- expect(isItemDisabled("execute to this operator")).toBe(true);
-
- clickItem("execute to this operator");
-
- expect(operatorMenuService.executeUpToOperator).not.toHaveBeenCalled();
- });
-
- it("execute to this operator is not offered while more than one operator
is highlighted", () => {
- highlightedOperatorsSubject.next(["op1", "op2"]);
- component.isWorkflowModifiable = true;
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1",
"op2"]);
- fixture.detectChanges();
- expect(component.canExecuteOperator()).toBe(false);
-
- const rendered = fixture.debugElement
- .queryAll(By.css("li[nz-menu-item]"))
- .some(li => norm(li.nativeElement.textContent) === "execute to this
operator");
- expect(rendered).toBe(false);
- });
-
- it("execute to this operator checks the state at click time, not at the
last render", () => {
- highlightedOperatorsSubject.next(["op1"]);
- component.isWorkflowModifiable = true;
-
jointGraphWrapperSpy.getCurrentHighlightedOperatorIDs.mockReturnValue(["op1"]);
- validationWorkflowService.validateOperator.mockReturnValue({ isValid:
true });
- (workflowActionService.getTexeraGraph() as unknown as
Mocked<WorkflowGraph>).isOperatorDisabled.mockReturnValue(
- false
- );
- fixture.detectChanges();
- expect(isItemDisabled("execute to this operator")).toBe(false);
-
- clickItem("execute to this operator");
- expect(operatorMenuService.executeUpToOperator).toHaveBeenCalledTimes(1);
-
- // The workflow locks without a change-detection pass, so the item still
looks enabled.
- component.isWorkflowModifiable = false;
- expect(isItemDisabled("execute to this operator")).toBe(false);
-
- clickItem("execute to this operator");
-
- expect(operatorMenuService.executeUpToOperator).toHaveBeenCalledTimes(1);
- });
-
- it("Export result invokes onClickExportHighlightedExecutionResult", () => {
- (
- workflowResultExportService as unknown as {
hasResultToExportOnHighlightedOperators: boolean }
- ).hasResultToExportOnHighlightedOperators = true;
- (component as unknown as { config: { env: Record<string, unknown> }
}).config.env.exportExecutionResultEnabled =
- true;
- fixture.detectChanges();
- const spy = vi.spyOn(component,
"onClickExportHighlightedExecutionResult").mockImplementation(() => {});
-
- clickItem("export result");
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
- });
-});
-
-describe("ContextMenuComponent onDelete with real WorkflowActionService", ()
=> {
- let component: ContextMenuComponent;
- let fixture: ComponentFixture<ContextMenuComponent>;
- let workflowActionService: WorkflowActionService;
- let undoRedoService: UndoRedoService;
-
- // mockCommentBox reuses operator ID "1" (operators and comment boxes share
the
- // joint-graph cell namespace), so give the comment box a distinct ID.
- const commentBox = { ...mockCommentBox, commentBoxID: "comment-box-1" };
-
- beforeEach(async () => {
- // Only the collaborators onDelete does not touch are stubbed; deletions
run
- // through the real WorkflowActionService against a seeded graph.
- const operatorMenuServiceStub = {
- highlightedOperators$: of([] as readonly string[]),
- highlightedCommentBoxes$: of([] as readonly string[]),
- isDisableOperator: false,
- isDisableOperatorClickable: false,
- isToViewResult: false,
- isToViewResultClickable: false,
- isMarkForReuse: false,
- isReuseResultClickable: false,
- saveHighlightedElements: vi.fn(),
- performPasteOperation: vi.fn(),
- } as unknown as OperatorMenuService;
-
- await TestBed.configureTestingModule({
- providers: [
- { provide: OperatorMetadataService, useClass:
StubOperatorMetadataService },
- { provide: WorkflowResultService, useValue: { getResultService:
vi.fn(), hasAnyResult: vi.fn() } },
- { provide: WorkflowResultExportService, useValue: {
exportOperatorsResultAsFile: vi.fn() } },
- { provide: OperatorMenuService, useValue: operatorMenuServiceStub },
- { provide: ValidationWorkflowService, useValue: { validateOperator:
vi.fn() } },
- NzModalService,
- ...commonTestProviders,
- ],
- imports: [
- ContextMenuComponent,
- HttpClientTestingModule,
- ReactiveFormsModule,
- BrowserAnimationsModule,
- NzDropDownModule,
- NzModalModule,
- ],
- }).compileComponents();
-
- workflowActionService = TestBed.inject(WorkflowActionService);
- undoRedoService = TestBed.inject(UndoRedoService);
-
- fixture = TestBed.createComponent(ContextMenuComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- /**
- * Seeds scan -> sentiment connected by mockScanSentimentLink, then clears
the
- * auto-highlight state and enables multi-select so tests can highlight
exactly
- * the elements they want deleted.
- */
- function seedScanSentimentGraph(): void {
- workflowActionService.addOperatorsAndLinks(
- [
- { op: mockScanPredicate, pos: mockPoint },
- { op: mockSentimentPredicate, pos: mockPoint },
- ],
- [mockScanSentimentLink]
- );
- const wrapper = workflowActionService.getJointGraphWrapper();
-
wrapper.unhighlightOperators(...wrapper.getCurrentHighlightedOperatorIDs());
- wrapper.unhighlightLinks(...wrapper.getCurrentHighlightedLinkIDs());
- wrapper.setMultiSelectMode(true);
- }
-
- it("should delete a highlighted operator with its attached link without
double-deleting the link", () => {
- seedScanSentimentGraph();
- const wrapper = workflowActionService.getJointGraphWrapper();
- const texeraGraph = workflowActionService.getTexeraGraph();
- // highlight both the operator and its attached link: deleting the operator
- // removes the link first, so the standalone-link pass must hit the
- // hasLinkWithID guard instead of deleting (and throwing on) a missing
link.
- wrapper.highlightOperators(mockScanPredicate.operatorID);
- wrapper.highlightLinks(mockScanSentimentLink.linkID);
-
expect(wrapper.getCurrentHighlightedLinkIDs()).toEqual([mockScanSentimentLink.linkID]);
-
- component.onDelete();
-
- expect(texeraGraph.hasOperator(mockScanPredicate.operatorID)).toBe(false);
-
expect(texeraGraph.hasLinkWithID(mockScanSentimentLink.linkID)).toBe(false);
-
expect(texeraGraph.hasOperator(mockSentimentPredicate.operatorID)).toBe(true);
- });
-
- it("should delete a standalone highlighted link and keep its endpoint
operators", () => {
- seedScanSentimentGraph();
- const wrapper = workflowActionService.getJointGraphWrapper();
- const texeraGraph = workflowActionService.getTexeraGraph();
- wrapper.highlightLinks(mockScanSentimentLink.linkID);
-
- component.onDelete();
-
-
expect(texeraGraph.hasLinkWithID(mockScanSentimentLink.linkID)).toBe(false);
- expect(texeraGraph.hasOperator(mockScanPredicate.operatorID)).toBe(true);
-
expect(texeraGraph.hasOperator(mockSentimentPredicate.operatorID)).toBe(true);
- });
-
- it("should delete highlighted comment boxes", () => {
- workflowActionService.addCommentBox(commentBox);
- const wrapper = workflowActionService.getJointGraphWrapper();
- const texeraGraph = workflowActionService.getTexeraGraph();
- wrapper.highlightCommentBoxes(commentBox.commentBoxID);
-
- component.onDelete();
-
- expect(texeraGraph.hasCommentBox(commentBox.commentBoxID)).toBe(false);
- });
-
- it("should bundle the whole deletion into a single undo step", () => {
- seedScanSentimentGraph();
- workflowActionService.addCommentBox(commentBox);
- const wrapper = workflowActionService.getJointGraphWrapper();
- const texeraGraph = workflowActionService.getTexeraGraph();
- // addCommentBox turns multi-select off again, so re-enable it before
- // highlighting the whole graph.
- wrapper.setMultiSelectMode(true);
- wrapper.highlightOperators(mockScanPredicate.operatorID,
mockSentimentPredicate.operatorID);
- wrapper.highlightLinks(mockScanSentimentLink.linkID);
- wrapper.highlightCommentBoxes(commentBox.commentBoxID);
-
- // the yjs undo manager merges transactions within its capture timeout, so
- // force the deletion to start a fresh undo stack item.
- (texeraGraph as WorkflowGraph).sharedModel.undoManager.stopCapturing();
- const undoLengthBefore = undoRedoService.getUndoLength();
-
- component.onDelete();
-
- expect(texeraGraph.getAllOperators()).toEqual([]);
- expect(texeraGraph.getAllLinks()).toEqual([]);
- expect(texeraGraph.getAllCommentBoxes()).toEqual([]);
- expect(undoRedoService.getUndoLength()).toBe(undoLengthBefore + 1);
-
- // a single undo must restore every deleted element at once
- undoRedoService.undoAction();
-
- expect(texeraGraph.hasOperator(mockScanPredicate.operatorID)).toBe(true);
-
expect(texeraGraph.hasOperator(mockSentimentPredicate.operatorID)).toBe(true);
- expect(texeraGraph.hasLinkWithID(mockScanSentimentLink.linkID)).toBe(true);
- expect(texeraGraph.hasCommentBox(commentBox.commentBoxID)).toBe(true);
- });
->>>>>>> 93438d13f (fix(frontend): block clicks on disabled context menu items
(#8968))
});