Skip to content

Commit

Permalink
Merge branch '3.2.0' into CRDCDH-2008
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 authored Dec 12, 2024
2 parents cff287b + ab499c7 commit 7e18810
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 171 deletions.
4 changes: 2 additions & 2 deletions src/components/Contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, createContext, useContext, useEffect, useMemo, useState } from "react";
import { useLazyQuery } from "@apollo/client";
import { query as GET_USER, Response as GetUserResp } from "../../graphql/getMyUser";
import { authenticationLogin, authenticationLogout } from "../../utils";
import { authenticationLogin, authenticationLogout, safeParse } from "../../utils";

export type ContextState = {
status: Status;
Expand Down Expand Up @@ -66,7 +66,7 @@ type ProviderProps = {
* @returns {JSX.Element} - Auth context provider
*/
export const AuthProvider: FC<ProviderProps> = ({ children }: ProviderProps) => {
const cachedUser = JSON.parse(localStorage.getItem("userDetails"));
const cachedUser = safeParse<User | null>(localStorage.getItem("userDetails"), null);
const cachedState = cachedUser
? {
isLoggedIn: true,
Expand Down
241 changes: 116 additions & 125 deletions src/components/DataSubmissions/CreateDataSubmissionDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,32 @@ import {
import {
CREATE_SUBMISSION,
CreateSubmissionResp,
LIST_APPROVED_STUDIES_OF_MY_ORG,
GetMyUserResp,
LIST_ORGS,
ListApprovedStudiesOfMyOrgResp,
ListOrgsResp,
} from "../../graphql";

const listApprovedStudiesOfMyOrgMocks: MockedResponse<ListApprovedStudiesOfMyOrgResp>[] = [
const baseStudies: GetMyUserResp["getMyUser"]["studies"] = [
{
request: {
query: LIST_APPROVED_STUDIES_OF_MY_ORG,
},
result: {
data: {
listApprovedStudiesOfMyOrganization: [
{
_id: "study1",
studyName: "study-name",
studyAbbreviation: "SN",
dbGaPID: "phsTEST",
controlledAccess: null,
},
{
_id: "study2",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: "phsTEST",
controlledAccess: true,
},
{
_id: "no-dbGaP-ID",
studyName: "controlled-study",
studyAbbreviation: "DB",
dbGaPID: null,
controlledAccess: true,
},
],
},
},
_id: "study1",
studyName: "study-name",
studyAbbreviation: "SN",
dbGaPID: "phsTEST",
controlledAccess: null,
},
{
_id: "study2",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: "phsTEST",
controlledAccess: true,
},
{
_id: "no-dbGaP-ID",
studyName: "controlled-study",
studyAbbreviation: "DB",
dbGaPID: null,
controlledAccess: true,
},
];

Expand Down Expand Up @@ -112,7 +100,7 @@ const listOrgsMocks: MockedResponse<ListOrgsResp>[] = [
},
];

const baseMocks = [...listApprovedStudiesOfMyOrgMocks, ...createSubmissionMocks, ...listOrgsMocks];
const baseMocks = [...createSubmissionMocks, ...listOrgsMocks];

const baseUser: Omit<User, "role"> = {
_id: "",
Expand Down Expand Up @@ -189,7 +177,12 @@ describe("Basic Functionality", () => {

it("submits the form successfully", async () => {
const { getByTestId, getByRole, getByText } = render(
<TestParent authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}>
<TestParent
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
>
<CreateDataSubmissionDialog onCreate={handleCreate} />
</TestParent>
);
Expand Down Expand Up @@ -247,7 +240,12 @@ describe("Basic Functionality", () => {

it("should only show the dbGaP ID if study is controlled access", async () => {
const { getByText, getByRole, getByTestId } = render(
<TestParent authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}>
<TestParent
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
>
<CreateDataSubmissionDialog onCreate={handleCreate} />
</TestParent>
);
Expand Down Expand Up @@ -298,7 +296,12 @@ describe("Basic Functionality", () => {

it("sets dbGaPID to an empty string and isDbGapRequired to false when studyID is not found", async () => {
const { getByText, getByRole, getByTestId } = render(
<TestParent authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}>
<TestParent
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
>
<CreateDataSubmissionDialog onCreate={handleCreate} />
</TestParent>
);
Expand Down Expand Up @@ -341,7 +344,6 @@ describe("Basic Functionality", () => {

it("should show an error message when submission could not be created (network)", async () => {
const mocks: MockedResponse[] = [
...listApprovedStudiesOfMyOrgMocks,
...listOrgsMocks,
{
request: {
Expand All @@ -361,7 +363,10 @@ describe("Basic Functionality", () => {
const { getByText, getByRole, getByTestId } = render(
<TestParent
mocks={mocks}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
>
<CreateDataSubmissionDialog onCreate={handleCreate} />
</TestParent>
Expand Down Expand Up @@ -420,7 +425,6 @@ describe("Basic Functionality", () => {

it("should show an error message when submission could not be created (GraphQL)", async () => {
const mocks: MockedResponse[] = [
...listApprovedStudiesOfMyOrgMocks,
...listOrgsMocks,
{
request: {
Expand All @@ -442,7 +446,10 @@ describe("Basic Functionality", () => {
const { getByText, getByRole, getByTestId } = render(
<TestParent
mocks={mocks}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
>
<CreateDataSubmissionDialog onCreate={handleCreate} />
</TestParent>
Expand Down Expand Up @@ -501,7 +508,12 @@ describe("Basic Functionality", () => {

it("should show message field is required but input is empty", async () => {
const { getByText, getByRole, getByTestId } = render(
<TestParent authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}>
<TestParent
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
>
<CreateDataSubmissionDialog onCreate={handleCreate} />
</TestParent>
);
Expand Down Expand Up @@ -694,7 +706,10 @@ describe("Basic Functionality", () => {
wrapper: (p) => (
<TestParent
mocks={baseMocks}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: baseStudies },
}}
{...p}
/>
),
Expand Down Expand Up @@ -746,32 +761,26 @@ describe("Basic Functionality", () => {

describe("Implementation Requirements", () => {
it("should disable the Create button if dbGaP ID is required and not added to the study", async () => {
const ApprovedStudyNoDbGaPID: MockedResponse<ListApprovedStudiesOfMyOrgResp> = {
request: {
query: LIST_APPROVED_STUDIES_OF_MY_ORG,
},
result: {
data: {
listApprovedStudiesOfMyOrganization: [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: null,
controlledAccess: true,
},
],
},
const ApprovedStudyNoDbGaPID: GetMyUserResp["getMyUser"]["studies"] = [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: null,
controlledAccess: true,
},
};
];

const { getByRole, getByTestId, getByText } = render(
<CreateDataSubmissionDialog onCreate={jest.fn()} />,
{
wrapper: (p) => (
<TestParent
mocks={[ApprovedStudyNoDbGaPID, ...listOrgsMocks]}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
mocks={[...listOrgsMocks]}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: ApprovedStudyNoDbGaPID },
}}
{...p}
/>
),
Expand Down Expand Up @@ -807,32 +816,26 @@ describe("Implementation Requirements", () => {
});

it("should show an alert icon next to dbGaPID if it is required and not added to the study", async () => {
const ApprovedStudyNoDbGaPID: MockedResponse<ListApprovedStudiesOfMyOrgResp> = {
request: {
query: LIST_APPROVED_STUDIES_OF_MY_ORG,
},
result: {
data: {
listApprovedStudiesOfMyOrganization: [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: null,
controlledAccess: true,
},
],
},
const ApprovedStudyNoDbGaPID: GetMyUserResp["getMyUser"]["studies"] = [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: null,
controlledAccess: true,
},
};
];

const { getByRole, getByTestId, getByText } = render(
<CreateDataSubmissionDialog onCreate={jest.fn()} />,
{
wrapper: (p) => (
<TestParent
mocks={[ApprovedStudyNoDbGaPID, ...listOrgsMocks]}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
mocks={[...listOrgsMocks]}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: ApprovedStudyNoDbGaPID },
}}
{...p}
/>
),
Expand Down Expand Up @@ -879,39 +882,33 @@ describe("Implementation Requirements", () => {
});

it("should hide the dbGaPID field if controlledAccess is false", async () => {
const ApprovedStudyNoDbGaPID: MockedResponse<ListApprovedStudiesOfMyOrgResp> = {
request: {
query: LIST_APPROVED_STUDIES_OF_MY_ORG,
const ApprovedStudyNoDbGaPID: GetMyUserResp["getMyUser"]["studies"] = [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: "phsTEST",
controlledAccess: true,
},
result: {
data: {
listApprovedStudiesOfMyOrganization: [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: "phsTEST",
controlledAccess: true,
},
{
_id: "non-controlled",
studyName: "non-controlled-study",
studyAbbreviation: "NCS",
dbGaPID: null,
controlledAccess: false,
},
],
},
{
_id: "non-controlled",
studyName: "non-controlled-study",
studyAbbreviation: "NCS",
dbGaPID: null,
controlledAccess: false,
},
};
];

const { getByRole, getByTestId, getByText } = render(
<CreateDataSubmissionDialog onCreate={jest.fn()} />,
{
wrapper: (p) => (
<TestParent
mocks={[ApprovedStudyNoDbGaPID, ...listOrgsMocks]}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
mocks={[...listOrgsMocks]}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: ApprovedStudyNoDbGaPID },
}}
{...p}
/>
),
Expand Down Expand Up @@ -960,32 +957,26 @@ describe("Implementation Requirements", () => {
});

it("should have a tooltip for the dbGaPID field explaining why it is required", async () => {
const ApprovedStudyNoDbGaPID: MockedResponse<ListApprovedStudiesOfMyOrgResp> = {
request: {
query: LIST_APPROVED_STUDIES_OF_MY_ORG,
},
result: {
data: {
listApprovedStudiesOfMyOrganization: [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: null,
controlledAccess: true,
},
],
},
const ApprovedStudyNoDbGaPID: GetMyUserResp["getMyUser"]["studies"] = [
{
_id: "controlled",
studyName: "controlled-study",
studyAbbreviation: "CS",
dbGaPID: null,
controlledAccess: true,
},
};
];

const { getByRole, getByTestId, getByText } = render(
<CreateDataSubmissionDialog onCreate={jest.fn()} />,
{
wrapper: (p) => (
<TestParent
mocks={[ApprovedStudyNoDbGaPID, ...listOrgsMocks]}
authCtxState={{ ...baseAuthCtx, user: { ...baseUser, role: "Submitter" } }}
mocks={[...listOrgsMocks]}
authCtxState={{
...baseAuthCtx,
user: { ...baseUser, role: "Submitter", studies: ApprovedStudyNoDbGaPID },
}}
{...p}
/>
),
Expand Down
Loading

0 comments on commit 7e18810

Please sign in to comment.