Ma77Ball commented on code in PR #6466:
URL: https://github.com/apache/texera/pull/6466#discussion_r3627119997


##########
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:
   Added a jsdom unit test for `createSnapShotCanvas()` covering the 
`document.body` fallback and the crop-ratio math, and removed the stale comment 
referencing a non-existent e2e/browser suite. I will also bump the PR 
description to 7 tests.
   



##########
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:
   Added an upload error test that flushes a 500 and asserts the error 
propagates to the subscriber, mirroring the retrieve error case.
   



-- 
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]

Reply via email to