Copilot commented on code in PR #6466: URL: https://github.com/apache/texera/pull/6466#discussion_r3600970497
########## frontend/src/app/dashboard/service/user/workflow-snapshot/workflow-snapshot.service.spec.ts: ########## @@ -0,0 +1,99 @@ +/** + * 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, HttpTestingController } from "@angular/common/http/testing"; +import { TestBed } from "@angular/core/testing"; +import { + WorkflowSnapshotService, + WORKFLOW_SNAPSHOT_API_BASE_URL, + WORKFLOW_SNAPSHOT_UPLOAD_URL, +} from "./workflow-snapshot.service"; + +// createSnapShotCanvas() delegates to html2canvas, whose module-level mock is not +// reliable here (other specs import it unmocked and the builder shares one module +// registry), so it is exercised in the e2e/browser suite rather than pinned here. Review Comment: This spec explicitly opts out of unit-testing `createSnapShotCanvas()` (and there are only 5 `it(...)` cases total), but the PR description and linked issue both state that canvas capture (ratio math + `document.body` fallback) is verified in unit tests and expect 6 passing tests. Either add unit tests for `createSnapShotCanvas()` (including success/error paths) or update the PR description/issue scope to match what’s actually covered here; also consider removing the unverified reference to an "e2e/browser suite" in this repo to avoid misleading future readers. ########## frontend/src/app/dashboard/service/user/workflow-snapshot/workflow-snapshot.service.spec.ts: ########## @@ -0,0 +1,99 @@ +/** + * 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, HttpTestingController } from "@angular/common/http/testing"; +import { TestBed } from "@angular/core/testing"; +import { + WorkflowSnapshotService, + WORKFLOW_SNAPSHOT_API_BASE_URL, + WORKFLOW_SNAPSHOT_UPLOAD_URL, +} from "./workflow-snapshot.service"; + +// createSnapShotCanvas() delegates to html2canvas, whose module-level mock is not +// reliable here (other specs import it unmocked and the builder shares one module +// registry), so it is exercised in the e2e/browser suite rather than pinned here. +describe("WorkflowSnapshotService", () => { + let service: WorkflowSnapshotService; + let httpMock: HttpTestingController; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [WorkflowSnapshotService], + }); + service = TestBed.inject(WorkflowSnapshotService); + httpMock = TestBed.inject(HttpTestingController); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it("should be created", () => { + expect(service).toBeTruthy(); + }); + + describe("uploadWorkflowSnapshot", () => { + it("PUTs a multipart form with the blob and stringified wid", () => { + const blob = new Blob(["img"], { type: "image/png" }); + service.uploadWorkflowSnapshot(blob, 12).subscribe(); + + const req = httpMock.expectOne(WORKFLOW_SNAPSHOT_UPLOAD_URL); + expect(req.request.method).toEqual("PUT"); + const body = req.request.body as FormData; + expect(body.get("wid")).toEqual("12"); + expect(body.get("SnapshotBlob")).toBeInstanceOf(Blob); + req.flush({}); + }); + + it("sends an empty wid string when wid is undefined", () => { + service.uploadWorkflowSnapshot(new Blob([]), undefined).subscribe(); + + const req = httpMock.expectOne(WORKFLOW_SNAPSHOT_UPLOAD_URL); + expect((req.request.body as FormData).get("wid")).toEqual(""); + req.flush({}); + }); + }); Review Comment: The linked issue asks for both success and error paths; `uploadWorkflowSnapshot` is only covered for success. Add a test that asserts server errors are propagated to the caller (similar to the retrieve error 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]
