Copilot commented on code in PR #6539:
URL: https://github.com/apache/texera/pull/6539#discussion_r3609556224
##########
frontend/src/app/workspace/component/result-panel/console-frame/console-frame.component.spec.ts:
##########
@@ -27,35 +27,266 @@ import { NzDropDownModule } from "ng-zorro-antd/dropdown";
import { ComputingUnitStatusService } from
"../../../../common/service/computing-unit/computing-unit-status/computing-unit-status.service";
import { MockComputingUnitStatusService } from
"../../../../common/service/computing-unit/computing-unit-status/mock-computing-unit-status.service";
import { commonTestProviders } from "../../../../common/testing/test-utils";
+import { ExecuteWorkflowService } from
"../../../service/execute-workflow/execute-workflow.service";
+import { WorkflowConsoleService } from
"../../../service/workflow-console/workflow-console.service";
+import { WorkflowWebsocketService } from
"../../../service/workflow-websocket/workflow-websocket.service";
+import { NotificationService } from
"../../../../common/service/notification/notification.service";
+import { UdfDebugService } from
"../../../service/operator-debug/udf-debug.service";
+import { ExecutionState } from "../../../types/execute-workflow.interface";
+import { ConsoleMessage } from "../../../types/workflow-common.interface";
+
+function consoleMessage(name: string): ConsoleMessage {
+ return {
+ workerId: "w",
+ timestamp: { nanos: 0, seconds: 0 },
+ msgType: { name },
+ source: "src",
+ title: "title",
+ message: "message",
+ };
+}
+
+type StateEvent = { previous: { state: ExecutionState }; current: { state:
ExecutionState } };
describe("ConsoleFrameComponent", () => {
let component: ConsoleFrameComponent;
let fixture: ComponentFixture<ConsoleFrameComponent>;
+ let getWorkerIds: ReturnType<typeof vi.fn>;
+ let getConsoleMessages: ReturnType<typeof vi.fn>;
+ let skipTuples: ReturnType<typeof vi.fn>;
+ let retryExecution: ReturnType<typeof vi.fn>;
+ let send: ReturnType<typeof vi.fn>;
+ let notifyError: ReturnType<typeof vi.fn>;
+ let doStep: ReturnType<typeof vi.fn>;
+ let doContinue: ReturnType<typeof vi.fn>;
+ let executionStateStream: Subject<StateEvent>;
+ let consoleUpdateStream: Subject<void>;
+
beforeEach(async () => {
+ getWorkerIds = vi.fn().mockReturnValue([]);
+ getConsoleMessages = vi.fn().mockReturnValue([]);
+ skipTuples = vi.fn();
+ retryExecution = vi.fn();
+ send = vi.fn();
+ notifyError = vi.fn();
+ doStep = vi.fn();
+ doContinue = vi.fn();
+ executionStateStream = new Subject<StateEvent>();
+ consoleUpdateStream = new Subject<void>();
+
await TestBed.configureTestingModule({
imports: [ConsoleFrameComponent, HttpClientTestingModule,
NzDropDownModule],
providers: [
+ { provide: OperatorMetadataService, useClass:
StubOperatorMetadataService },
+ { provide: ComputingUnitStatusService, useClass:
MockComputingUnitStatusService },
{
- provide: OperatorMetadataService,
- useClass: StubOperatorMetadataService,
+ provide: ExecuteWorkflowService,
+ useValue: {
+ getExecutionStateStream: () => executionStateStream.asObservable(),
+ getWorkerIds,
+ skipTuples,
+ retryExecution,
+ },
},
{
- provide: ComputingUnitStatusService,
- useClass: MockComputingUnitStatusService,
+ provide: WorkflowConsoleService,
+ useValue: { getConsoleMessageUpdateStream: () =>
consoleUpdateStream.asObservable(), getConsoleMessages },
},
+ { provide: WorkflowWebsocketService, useValue: { send } },
+ { provide: NotificationService, useValue: { error: notifyError } },
+ { provide: UdfDebugService, useValue: { doStep, doContinue } },
...commonTestProviders,
],
}).compileComponents();
- });
- beforeEach(() => {
fixture = TestBed.createComponent(ConsoleFrameComponent);
component = fixture.componentInstance;
- fixture.detectChanges();
+ fixture.detectChanges(); // runs ngOnInit -> registerAutoConsoleRerender
});
it("should create", () => {
expect(component).toBeTruthy();
});
+
+ describe("pure helpers", () => {
+ it("getWorkerIndex parses the trailing numeric token", () => {
+ expect(component.getWorkerIndex("worker-op-3")).toBe(3);
+ expect(component.getWorkerIndex("W-0-12")).toBe(12);
+ expect(component.getWorkerIndex("")).toBe(0);
+ });
+
+ it("workerIdToAbbr prefixes the worker index with 'W'", () => {
+ expect(component.workerIdToAbbr("worker-op-3")).toBe("W3");
+ });
+
+ it("getWorkerColor returns a deterministic hex color", () => {
+ const color = component.getWorkerColor(0);
+ expect(color).toMatch(/^#[0-9a-fA-F]{6}$/);
+ expect(component.getWorkerColor(0)).toBe(color); // deterministic
+ expect(component.getWorkerColor(5)).toMatch(/^#[0-9a-fA-F]{6}$/);
+ });
+
+ it("getMessageLabel maps the message type to its tag color", () => {
+
expect(component.getMessageLabel(consoleMessage("PRINT"))).toBe("default");
+
expect(component.getMessageLabel(consoleMessage("COMMAND"))).toBe("processing");
+
expect(component.getMessageLabel(consoleMessage("DEBUGGER"))).toBe("warning");
+ expect(component.getMessageLabel(consoleMessage("ERROR"))).toBe("error");
+ expect(component.getMessageLabel(consoleMessage("UNKNOWN"))).toBe("");
+ });
+ });
+
+ describe("console rendering", () => {
+ it("clearConsole empties the message list", () => {
+ component.consoleMessages = [consoleMessage("PRINT")];
+ component.clearConsole();
+ expect(component.consoleMessages).toEqual([]);
+ });
+
+ it("displayConsoleMessages loads the operator's messages from the
service", () => {
+ const messages = [consoleMessage("PRINT"), consoleMessage("ERROR")];
+ getConsoleMessages.mockReturnValue(messages);
+
+ component.displayConsoleMessages("op1");
+
+ expect(getConsoleMessages).toHaveBeenCalledWith("op1");
+ expect(component.consoleMessages).toEqual(messages);
+ });
+
+ it("renderConsole loads the worker ids and messages when an operator is
set", () => {
+ component.operatorId = "op1";
+ getWorkerIds.mockReturnValue(["w-1", "w-2"]);
+ getConsoleMessages.mockReturnValue([consoleMessage("PRINT")]);
+
+ component.renderConsole();
+
+ expect(component.workerIds).toEqual(["w-1", "w-2"]);
+ expect(getConsoleMessages).toHaveBeenCalledWith("op1");
+ });
+
+ it("renderConsole is a no-op without an operator id", () => {
+ component.operatorId = "";
+ getWorkerIds.mockClear();
+ component.renderConsole();
+ expect(getWorkerIds).not.toHaveBeenCalled();
+ });
+ });
+
+ describe("debug controls", () => {
+ it("onClickContinue steps every worker via the debug service", () => {
Review Comment:
Test name is inaccurate: onClickContinue calls UdfDebugService.doContinue
(not a step). Renaming avoids confusion when reading failures and aligns with
the actual behavior under test.
--
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]