Copilot commented on code in PR #6780:
URL: https://github.com/apache/texera/pull/6780#discussion_r3627943053


##########
frontend/src/app/dashboard/component/user/list-item/card-item/card-item.component.spec.ts:
##########
@@ -635,4 +645,252 @@ describe("CardItemComponent", () => {
 
     expect(postLikeSpy).not.toHaveBeenCalled();
   });
+
+  describe("extended coverage", () => {
+    it("entry getter throws when no entry has been provided", () => {
+      (component as any)._entry = undefined;
+      expect(() => component.entry).toThrow("entry property must be 
provided.");

Review Comment:
   This test reaches into the component’s private `_entry` field, which couples 
the spec to an implementation detail. Prefer using the public setter with an 
`any` cast so the test only depends on the public `entry` API.



##########
frontend/src/app/dashboard/component/user/list-item/card-item/card-item.component.spec.ts:
##########
@@ -635,4 +645,252 @@ describe("CardItemComponent", () => {
 
     expect(postLikeSpy).not.toHaveBeenCalled();
   });
+
+  describe("extended coverage", () => {
+    it("entry getter throws when no entry has been provided", () => {
+      (component as any)._entry = undefined;
+      expect(() => component.entry).toThrow("entry property must be 
provided.");
+    });
+
+    it("initializeEntry routes an owning dataset user to the user dataset 
view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: true },
+        accessibleUserIds: [42],
+        coverImageUrl: undefined, // skips the cover fetch
+        size: 55,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([USER_DATASET, "5"]);
+      expect(component.iconType).toBe("database");
+      expect(component.disableDelete).toBe(false); // owner
+      expect(component.size).toBe(55);
+    });
+
+    it("initializeEntry routes a non-owning dataset user to the hub dataset 
detail view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: false },
+        accessibleUserIds: [99],
+        coverImageUrl: undefined,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([HUB_DATASET_RESULT_DETAIL, "5"]);
+      expect(component.disableDelete).toBe(true); // !isOwner
+    });
+
+    it("onClickDownload downloads a workflow via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadWorkflowSpy = vi.spyOn(downloadService, 
"downloadWorkflow").mockReturnValue(of({} as any));

Review Comment:
   This test spies on a constructor-injected private field via `(component as 
any).downloadService`, which makes the spec brittle to refactors. Prefer 
injecting the service from the TestBed and spying on that instance.



##########
frontend/src/app/dashboard/component/user/list-item/card-item/card-item.component.spec.ts:
##########
@@ -635,4 +645,252 @@ describe("CardItemComponent", () => {
 
     expect(postLikeSpy).not.toHaveBeenCalled();
   });
+
+  describe("extended coverage", () => {
+    it("entry getter throws when no entry has been provided", () => {
+      (component as any)._entry = undefined;
+      expect(() => component.entry).toThrow("entry property must be 
provided.");
+    });
+
+    it("initializeEntry routes an owning dataset user to the user dataset 
view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: true },
+        accessibleUserIds: [42],
+        coverImageUrl: undefined, // skips the cover fetch
+        size: 55,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([USER_DATASET, "5"]);
+      expect(component.iconType).toBe("database");
+      expect(component.disableDelete).toBe(false); // owner
+      expect(component.size).toBe(55);
+    });
+
+    it("initializeEntry routes a non-owning dataset user to the hub dataset 
detail view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: false },
+        accessibleUserIds: [99],
+        coverImageUrl: undefined,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([HUB_DATASET_RESULT_DETAIL, "5"]);
+      expect(component.disableDelete).toBe(true); // !isOwner
+    });
+
+    it("onClickDownload downloads a workflow via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadWorkflowSpy = vi.spyOn(downloadService, 
"downloadWorkflow").mockReturnValue(of({} as any));
+      component.entry = makeWorkflowEntry({ id: 7, workflow: { isOwner: true, 
workflow: { name: "myflow" } } } as any);
+
+      component.onClickDownload();
+
+      expect(downloadWorkflowSpy).toHaveBeenCalledWith(7, "myflow");
+    });
+
+    it("onClickDownload downloads a dataset via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadDatasetSpy = vi.spyOn(downloadService, 
"downloadDataset").mockReturnValue(of(new Blob()));

Review Comment:
   Same as above: avoid accessing the component’s private `downloadService` 
field; inject `DownloadService` from the TestBed to spy on its methods.



##########
frontend/src/app/dashboard/component/user/list-item/card-item/card-item.component.spec.ts:
##########
@@ -635,4 +645,252 @@ describe("CardItemComponent", () => {
 
     expect(postLikeSpy).not.toHaveBeenCalled();
   });
+
+  describe("extended coverage", () => {
+    it("entry getter throws when no entry has been provided", () => {
+      (component as any)._entry = undefined;
+      expect(() => component.entry).toThrow("entry property must be 
provided.");
+    });
+
+    it("initializeEntry routes an owning dataset user to the user dataset 
view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: true },
+        accessibleUserIds: [42],
+        coverImageUrl: undefined, // skips the cover fetch
+        size: 55,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([USER_DATASET, "5"]);
+      expect(component.iconType).toBe("database");
+      expect(component.disableDelete).toBe(false); // owner
+      expect(component.size).toBe(55);
+    });
+
+    it("initializeEntry routes a non-owning dataset user to the hub dataset 
detail view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: false },
+        accessibleUserIds: [99],
+        coverImageUrl: undefined,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([HUB_DATASET_RESULT_DETAIL, "5"]);
+      expect(component.disableDelete).toBe(true); // !isOwner
+    });
+
+    it("onClickDownload downloads a workflow via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadWorkflowSpy = vi.spyOn(downloadService, 
"downloadWorkflow").mockReturnValue(of({} as any));
+      component.entry = makeWorkflowEntry({ id: 7, workflow: { isOwner: true, 
workflow: { name: "myflow" } } } as any);
+
+      component.onClickDownload();
+
+      expect(downloadWorkflowSpy).toHaveBeenCalledWith(7, "myflow");
+    });
+
+    it("onClickDownload downloads a dataset via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadDatasetSpy = vi.spyOn(downloadService, 
"downloadDataset").mockReturnValue(of(new Blob()));
+      component.entry = makeDatasetEntry({ id: 5, name: "mydataset", 
coverImageUrl: undefined });
+
+      component.onClickDownload();
+
+      expect(downloadDatasetSpy).toHaveBeenCalledWith(5, "mydataset");
+    });
+
+    it("onClickDownload is a no-op when the entry has no id", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadWorkflowSpy = vi.spyOn(downloadService, 
"downloadWorkflow");
+      const downloadDatasetSpy = vi.spyOn(downloadService, "downloadDataset");
+      component.entry = makeWorkflowEntry({ id: undefined });
+
+      component.onClickDownload();
+
+      expect(downloadWorkflowSpy).not.toHaveBeenCalled();
+      expect(downloadDatasetSpy).not.toHaveBeenCalled();
+    });
+
+    it("onClickOpenShareAccess opens the workflow share modal and forwards 
refresh events", async () => {
+      const modalService = TestBed.inject(NzModalService);
+      const refresh$ = new Subject<void>();
+      const createSpy = vi
+        .spyOn(modalService, "create")
+        .mockReturnValue({ componentInstance: { refresh: refresh$ } } as any);
+      (workflowPersistService as any).retrieveOwners = 
vi.fn().mockReturnValue(of(["alice", "bob"]));
+      component.entry = makeWorkflowEntry({ id: 7, workflow: { isOwner: true, 
accessLevel: "WRITE" } } as any);
+
+      await component.onClickOpenShareAccess();
+
+      expect(createSpy).toHaveBeenCalledTimes(1);
+      const cfg = createSpy.mock.calls[0][0];
+      expect(cfg.nzData).toEqual({
+        writeAccess: true,
+        type: "workflow",
+        id: 7,
+        allOwners: ["alice", "bob"],
+        inWorkspace: false,
+      });
+      expect(cfg.nzTitle).toBe("Share this workflow with others");
+
+      const refreshSpy = vi.fn();
+      component.refresh.subscribe(refreshSpy);
+      refresh$.next();
+      expect(refreshSpy).toHaveBeenCalledTimes(1);

Review Comment:
   The test subscribes to `component.refresh` but never unsubscribes; over a 
growing suite this can contribute to retained references and harder-to-debug 
leaks. Capture the subscription and unsubscribe after the assertion.



##########
frontend/src/app/dashboard/component/user/list-item/card-item/card-item.component.spec.ts:
##########
@@ -635,4 +645,252 @@ describe("CardItemComponent", () => {
 
     expect(postLikeSpy).not.toHaveBeenCalled();
   });
+
+  describe("extended coverage", () => {
+    it("entry getter throws when no entry has been provided", () => {
+      (component as any)._entry = undefined;
+      expect(() => component.entry).toThrow("entry property must be 
provided.");
+    });
+
+    it("initializeEntry routes an owning dataset user to the user dataset 
view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: true },
+        accessibleUserIds: [42],
+        coverImageUrl: undefined, // skips the cover fetch
+        size: 55,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([USER_DATASET, "5"]);
+      expect(component.iconType).toBe("database");
+      expect(component.disableDelete).toBe(false); // owner
+      expect(component.size).toBe(55);
+    });
+
+    it("initializeEntry routes a non-owning dataset user to the hub dataset 
detail view", () => {
+      component.currentUid = 42;
+      component.entry = makeDatasetEntry({
+        id: 5,
+        dataset: { isOwner: false },
+        accessibleUserIds: [99],
+        coverImageUrl: undefined,
+      } as any);
+
+      component.initializeEntry();
+
+      expect(component.entryLink).toEqual([HUB_DATASET_RESULT_DETAIL, "5"]);
+      expect(component.disableDelete).toBe(true); // !isOwner
+    });
+
+    it("onClickDownload downloads a workflow via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadWorkflowSpy = vi.spyOn(downloadService, 
"downloadWorkflow").mockReturnValue(of({} as any));
+      component.entry = makeWorkflowEntry({ id: 7, workflow: { isOwner: true, 
workflow: { name: "myflow" } } } as any);
+
+      component.onClickDownload();
+
+      expect(downloadWorkflowSpy).toHaveBeenCalledWith(7, "myflow");
+    });
+
+    it("onClickDownload downloads a dataset via the download service", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadDatasetSpy = vi.spyOn(downloadService, 
"downloadDataset").mockReturnValue(of(new Blob()));
+      component.entry = makeDatasetEntry({ id: 5, name: "mydataset", 
coverImageUrl: undefined });
+
+      component.onClickDownload();
+
+      expect(downloadDatasetSpy).toHaveBeenCalledWith(5, "mydataset");
+    });
+
+    it("onClickDownload is a no-op when the entry has no id", () => {
+      const downloadService = (component as any).downloadService as 
DownloadService;
+      const downloadWorkflowSpy = vi.spyOn(downloadService, 
"downloadWorkflow");

Review Comment:
   Same as above: spy on `DownloadService` via `TestBed.inject(...)` rather 
than reaching into a private field on the component.



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