From b0079158628d2789e600c56e8d84192321224cc6 Mon Sep 17 00:00:00 2001 From: Gurjeet Matharu Date: Thu, 7 Apr 2022 12:14:40 -0700 Subject: [PATCH] feat: showing edit project state in task list --- app/components/TaskList.tsx | 21 +++++++++++----- .../[projectRevision]/form/contacts.test.tsx | 7 ++++-- .../[projectRevision]/form/managers.test.tsx | 7 ++++-- .../[projectRevision]/form/overview.test.tsx | 5 +++- .../[projectRevision]/index.test.tsx | 25 ++++++++++++++++++- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/components/TaskList.tsx b/app/components/TaskList.tsx index 64e7e4ea5b..5f1c896461 100644 --- a/app/components/TaskList.tsx +++ b/app/components/TaskList.tsx @@ -15,16 +15,21 @@ interface Props { } const TaskList: React.FC = ({ projectRevision }) => { - const { id } = useFragment( + const { id, projectByProjectId } = useFragment( graphql` fragment TaskList_projectRevision on ProjectRevision { id + projectByProjectId { + proposalReference + } } `, projectRevision ); const router = useRouter(); + let mode = projectByProjectId ? "update" : "create"; + const currentStep = useMemo(() => { if (!router || !router.pathname) return null; if (`${router.pathname}/` === getProjectRevisionPageRoute(id).pathname) @@ -35,7 +40,11 @@ const TaskList: React.FC = ({ projectRevision }) => { return (
-

Add a Project

+

+ {projectByProjectId + ? "Editing: " + projectByProjectId.proposalReference + : "Add a Project"} +

  1. 1. Project Overview

    @@ -51,14 +60,14 @@ const TaskList: React.FC = ({ projectRevision }) => {
  2. -

    2. Project Details (optional)

    +

    2. Project Details {mode === "update" ? "" : "(optional)"}

  3. -

    3. Submit Project

    +

    3. Submit changes

    • { expect( within( screen.getByRole("navigation", { name: "side navigation" }) - ).getByText(/add a project/i) + ).getByText(/Editing: 001/i) ).toBeInTheDocument(); expect( - screen.getByText(/add project contacts/i).closest("li") + screen.getByText(/Edit project contacts/i).closest("li") ).toHaveAttribute("aria-current", "step"); }); diff --git a/app/tests/unit/pages/project-revision/[projectRevision]/form/managers.test.tsx b/app/tests/unit/pages/project-revision/[projectRevision]/form/managers.test.tsx index 8f30ff2e7c..3fd83378da 100644 --- a/app/tests/unit/pages/project-revision/[projectRevision]/form/managers.test.tsx +++ b/app/tests/unit/pages/project-revision/[projectRevision]/form/managers.test.tsx @@ -33,6 +33,9 @@ const defaultMockResolver = { ProjectRevision() { return { id: "mock-proj-rev-id", + projectByProjectId: { + proposalReference: "001", + }, projectFormChange: { id: "mock-project-form-id", newFormData: { @@ -84,10 +87,10 @@ describe("The Project Managers form page", () => { expect( within( screen.getByRole("navigation", { name: "side navigation" }) - ).getByText(/add a project/i) + ).getByText(/Editing: /i) ).toBeInTheDocument(); expect( - screen.getByText(/add project managers/i).closest("li") + screen.getByText(/Edit project managers/i).closest("li") ).toHaveAttribute("aria-current", "step"); }); diff --git a/app/tests/unit/pages/project-revision/[projectRevision]/form/overview.test.tsx b/app/tests/unit/pages/project-revision/[projectRevision]/form/overview.test.tsx index 4a4c67f1e1..3a25b60391 100644 --- a/app/tests/unit/pages/project-revision/[projectRevision]/form/overview.test.tsx +++ b/app/tests/unit/pages/project-revision/[projectRevision]/form/overview.test.tsx @@ -33,6 +33,9 @@ const defaultMockResolver = { ProjectRevision() { return { id: "mock-proj-rev-id", + projectByProjectId: { + proposalReference: "001", + }, projectFormChange: { id: "mock-project-form-id", newFormData: { @@ -84,7 +87,7 @@ describe("The Project Overview page", () => { expect( within( screen.getByRole("navigation", { name: "side navigation" }) - ).getByText(/add a project/i) + ).getByText(/Editing: 001/i) ).toBeInTheDocument(); expect( screen.getByText(/add project overview/i).closest("li") diff --git a/app/tests/unit/pages/project-revision/[projectRevision]/index.test.tsx b/app/tests/unit/pages/project-revision/[projectRevision]/index.test.tsx index 30af5cd14d..26647a7b4a 100644 --- a/app/tests/unit/pages/project-revision/[projectRevision]/index.test.tsx +++ b/app/tests/unit/pages/project-revision/[projectRevision]/index.test.tsx @@ -34,6 +34,9 @@ const defaultMockResolver = { ProjectRevision() { return { id: "mock-proj-rev-id", + projectByProjectId: { + proposalReference: "001", + }, projectFormChange: { id: "mock-project-form-id", newFormData: { @@ -101,7 +104,7 @@ describe("The Create Project page", () => { expect( within( screen.getByRole("navigation", { name: "side navigation" }) - ).getByText(/add a project/i) + ).getByText(/Editing: 001/i) ).toBeInTheDocument(); expect( @@ -109,6 +112,26 @@ describe("The Create Project page", () => { ).toHaveAttribute("aria-current", "step"); }); + // it("renders task list with optional", () => { + // const router = mocked(useRouter); + // const mockPathname = "/cif/project-revision/[projectRevision]"; + // router.mockReturnValue({ + // pathname: mockPathname, + // } as any); + + // loadProjectRevisionQuery(); + // renderProjectRevisionPage(); + // expect( + // within( + // screen.getByRole("navigation", { name: "side navigation" }) + // ).getByText(/( optional )/i) + // ).toBeInTheDocument(); + + // expect( + // screen.getByText(/review and submit information/i).closest("li") + // ).toHaveAttribute("aria-current", "step"); + // }); + it("Renders an enabled submit and discard changes button", async () => { jest .spyOn(require("mutations/useDebouncedMutation"), "default")