Copilot commented on code in PR #6471: URL: https://github.com/apache/texera/pull/6471#discussion_r3598837011
########## frontend/src/app/workspace/service/report-generation/report-generation.service.spec.ts: ########## @@ -0,0 +1,174 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { TestBed } from "@angular/core/testing"; +import { of, throwError } from "rxjs"; +import { ReportGenerationService } from "./report-generation.service"; +import { WorkflowActionService } from "../workflow-graph/model/workflow-action.service"; +import { WorkflowResultService } from "../workflow-result/workflow-result.service"; +import { NotificationService } from "src/app/common/service/notification/notification.service"; +import { AiAnalystService } from "../ai-analyst/ai-analyst.service"; + +describe("ReportGenerationService", () => { + let service: ReportGenerationService; + let workflowActionService: { getWorkflowContent: ReturnType<typeof vi.fn> }; + let workflowResultService: { + getResultService: ReturnType<typeof vi.fn>; + getPaginatedResultService: ReturnType<typeof vi.fn>; + }; + let notificationService: { error: ReturnType<typeof vi.fn> }; + let aiAnalystService: { + isOpenAIEnabled: ReturnType<typeof vi.fn>; + sendPromptToOpenAI: ReturnType<typeof vi.fn>; + }; + + beforeEach(() => { + vi.clearAllMocks(); + workflowActionService = { + getWorkflowContent: vi.fn().mockReturnValue({ operators: [{ operatorID: "op1", operatorType: "CSVFileScan" }] }), + }; + workflowResultService = { + getResultService: vi.fn().mockReturnValue(undefined), + getPaginatedResultService: vi.fn().mockReturnValue(undefined), + }; + notificationService = { error: vi.fn() }; + aiAnalystService = { + isOpenAIEnabled: vi.fn().mockReturnValue(of(true)), + sendPromptToOpenAI: vi.fn().mockReturnValue(of("AI comment")), + }; + + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + ReportGenerationService, + { provide: WorkflowActionService, useValue: workflowActionService }, + { provide: WorkflowResultService, useValue: workflowResultService }, + { provide: NotificationService, useValue: notificationService }, + { provide: AiAnalystService, useValue: aiAnalystService }, + ], + }); + service = TestBed.inject(ReportGenerationService); + }); + + afterEach(() => { + const editor = document.querySelector("#workflow-editor"); + editor?.remove(); + }); + + it("should be created", () => { + expect(service).toBeTruthy(); + }); + + describe("generateComment / generateSummaryComment", () => { + it("generateComment embeds the operator info and delegates to the AI service", () => { + let result: string | undefined; + service.generateComment({ foo: "bar" }).subscribe(r => (result = r)); + + expect(aiAnalystService.sendPromptToOpenAI).toHaveBeenCalledTimes(1); + const prompt = aiAnalystService.sendPromptToOpenAI.mock.calls[0][0] as string; + expect(prompt).toContain('"foo": "bar"'); + expect(prompt).toContain("at least 80 words"); + expect(result).toEqual("AI comment"); + }); + + it("generateSummaryComment uses the longer (150-word) summary prompt", () => { + service.generateSummaryComment({ a: 1 }).subscribe(); + + const prompt = aiAnalystService.sendPromptToOpenAI.mock.calls[0][0] as string; + expect(prompt).toContain("at least 150 words"); + expect(prompt).toContain('"a": 1'); + }); + }); + + describe("generateWorkflowSnapshot", () => { + // The rendering path delegates to html2canvas (unmockable reliably under the + // shared module registry), so only the pre-render guard is pinned here. + it("errors when the #workflow-editor element is absent", () => { + let error: unknown; + service.generateWorkflowSnapshot("wf").subscribe({ error: (e: unknown) => (error = e) }); + expect(error).toEqual("Workflow editor element not found"); + }); Review Comment: The spec currently only pins the “element absent” guard for generateWorkflowSnapshot. The PR description (and issue #6459) state the workflow snapshot path is covered for both found and not-found, but there’s no test exercising the success path (i.e., when #workflow-editor exists and html2canvas resolves). Consider adding a deterministic success-case test by mocking the html2canvas module (e.g., via a top-level vi.mock before importing the service, or via vi.resetModules()+vi.doMock+dynamic import) so the Observable emits a stable data URL. -- 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]
