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


##########
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:
   Fixed — now uses the public setter (component.entry = undefined as any) 
instead of the private _entry field.



##########
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:
   Fixed — the three download tests now spy on TestBed.inject(DownloadService) 
(providedIn root, same instance) instead of the component's private 
downloadService field.



##########
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:
   Fixed — spies on TestBed.inject(DownloadService) now.



##########
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:
   Fixed — spies on TestBed.inject(DownloadService) now.



##########
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:
   Fixed — the refresh subscription is now captured and unsubscribed after the 
assertion.



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