From 29f2e66407922a47189213bc80041d20f174a747 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Thu, 28 Nov 2024 14:16:47 +0100 Subject: [PATCH] refactor: remove isPI method and its associated tests from DatasetDetailComponent --- .../dataset-detail.component.spec.ts | 110 ------------------ .../dataset-detail.component.ts | 25 ---- 2 files changed, 135 deletions(-) diff --git a/src/app/datasets/dataset-detail/dataset-detail.component.spec.ts b/src/app/datasets/dataset-detail/dataset-detail.component.spec.ts index 96c778a5e..e31898a84 100644 --- a/src/app/datasets/dataset-detail/dataset-detail.component.spec.ts +++ b/src/app/datasets/dataset-detail/dataset-detail.component.spec.ts @@ -358,114 +358,4 @@ describe("DatasetDetailComponent", () => { ); }); }); - - describe("#isPI()", () => { - it("should return true if user username is admin", () => { - component.user = new User({ - username: "admin", - email: "test@email.com", - }); - - const isPI = component.isPI(); - - expect(isPI).toEqual(true); - }); - - it("should return true if user email equals principalInvestigator of a raw dataset", () => { - component.user = new User({ email: "test@email.com" }); - component.dataset = { - owner: "test", - contactEmail: "test", - sourceFolder: "test", - creationTime: new Date(), - type: "raw", - ownerGroup: "test", - principalInvestigator: "test@email.com", - creationLocation: "test", - } as unknown as Dataset; - - const isPI = component.isPI(); - - expect(isPI).toEqual(true); - }); - - it("should return false if user email does not equal principalInvestigator of a raw dataset", () => { - component.user = new User({ email: "failTest@email.com" }); - component.dataset = { - owner: "test", - contactEmail: "test", - sourceFolder: "test", - creationTime: new Date(), - type: "raw", - ownerGroup: "test", - principalInvestigator: "test@email.com", - creationLocation: "test", - } as unknown as Dataset; - const isPI = component.isPI(); - - expect(isPI).toEqual(false); - }); - - it("should return true if user email equals investigator of a derived dataset", () => { - component.user = new User({ email: "test@email.com" }); - component.dataset = { - owner: "test", - contactEmail: "test", - sourceFolder: "test", - creationTime: new Date(), - type: "derived", - ownerGroup: "test", - investigator: "test@email.com", - inputDatasets: ["test"], - usedSoftware: ["test"], - } as unknown as Dataset; - - const isPI = component.isPI(); - - expect(isPI).toEqual(true); - }); - - it("should return false if user email does not equal investigator of a derived dataset", () => { - component.user = new User({ email: "failTest@email.com" }); - component.dataset = { - owner: "test", - contactEmail: "test", - sourceFolder: "test", - creationTime: new Date(), - type: "derived", - ownerGroup: "test", - investigator: "test@email.com", - inputDatasets: ["test"], - usedSoftware: ["test"], - } as unknown as Dataset; - const isPI = component.isPI(); - - expect(isPI).toEqual(false); - }); - - it("should return false if dataset type is neither 'raw' or 'derived'", () => { - component.user = new User({ email: "failTest@email.com" }); - component.dataset = { - owner: "test", - contactEmail: "test", - sourceFolder: "test", - creationTime: new Date(), - type: "failTest", - ownerGroup: "test", - principalInvestigator: "test@email.com", - creationLocation: "test", - } as unknown as Dataset; - const isPI = component.isPI(); - - expect(isPI).toEqual(false); - }); - - it("should return false if no user is provided", () => { - component.user = undefined; - - const isPI = component.isPI(); - - expect(isPI).toEqual(false); - }); - }); }); diff --git a/src/app/datasets/dataset-detail/dataset-detail.component.ts b/src/app/datasets/dataset-detail/dataset-detail.component.ts index c48fb223c..668582c22 100644 --- a/src/app/datasets/dataset-detail/dataset-detail.component.ts +++ b/src/app/datasets/dataset-detail/dataset-detail.component.ts @@ -165,31 +165,6 @@ export class DatasetDetailComponent return this._hasUnsavedChanges; } - isPI(): boolean { - if (this.user && this.dataset) { - if (this.user.username === "admin") { - return true; - } - if (this.dataset.type === "raw") { - return ( - this.user.email.toLowerCase() === - (this.dataset as unknown as RawDataset)[ - "principalInvestigator" - ].toLowerCase() - ); - } - if (this.dataset.type === "derived") { - return ( - this.user.email.toLowerCase() === - (this.dataset as unknown as DerivedDataset)[ - "investigator" - ].toLowerCase() - ); - } - } - return false; - } - onClickKeyword(keyword: string) { this.store.dispatch(clearFacetsAction()); this.store.dispatch(addKeywordFilterAction({ keyword }));