From 0824c592879255c2e90223216483716d346f6afb Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Thu, 11 Jul 2024 18:09:58 -0700 Subject: [PATCH] test: adding tests for the changes --- .../Form/ProjectAttachmentsFormSummary.tsx | 2 +- .../ProjectAttachmentsFormSummary.test.tsx | 45 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/components/Form/ProjectAttachmentsFormSummary.tsx b/app/components/Form/ProjectAttachmentsFormSummary.tsx index 02885f7fa6..9956695261 100644 --- a/app/components/Form/ProjectAttachmentsFormSummary.tsx +++ b/app/components/Form/ProjectAttachmentsFormSummary.tsx @@ -116,7 +116,7 @@ const ProjectAttachmentsFormSummary: React.FC = ({ { ); }; +const getPropsFromTestQuery = (data) => ({ + query: data.query, + projectRevision: data.query.projectRevision, +}); + const componentTestingHelper = new ComponentTestingHelper({ component: TestWrapper, testQuery: testQuery, compiledQuery: compiledFormIndexPageQuery, - getPropsFromTestQuery: (data) => ({ - query: data.query, - projectRevision: data.query.projectRevision, - }), + getPropsFromTestQuery: getPropsFromTestQuery, defaultQueryResolver: defaultQueryResolver, defaultQueryVariables: { projectRevision: "mock-id" }, }); @@ -132,20 +134,47 @@ describe("The project's attachment page", () => { ).not.toBeInTheDocument(); }); - it("Displays all attachments that were created in this revision", () => { + it("Displays all attachments that were created in this revision if the isOnAmendmentsAndOtherRevisionsPage flag is false, and displays their create operation", () => { componentTestingHelper.loadQuery(); - componentTestingHelper.renderComponent(); + componentTestingHelper.renderComponent(getPropsFromTestQuery, { + isOnAmendmentsAndOtherRevisionsPage: false, + }); expect(screen.getAllByText(/Create/i)).toHaveLength(2); expect(screen.getByText(/test-attachment-1.jpg/i)).toBeInTheDocument(); expect(screen.getByText(/test-attachment-2.jpg/i)).toBeInTheDocument(); }); - it("Displays all attachments that were archived in this revision", () => { + it("Displays all attachments that were archived in this revision if the isOnAmendmentsAndOtherRevisionsPage flag is false", () => { componentTestingHelper.loadQuery(); - componentTestingHelper.renderComponent(); + componentTestingHelper.renderComponent(getPropsFromTestQuery, { + isOnAmendmentsAndOtherRevisionsPage: false, + }); expect(screen.getAllByText(/Archive/i)).toHaveLength(1); expect(screen.getByText(/test-attachment-3.jpg/i)).toBeInTheDocument(); }); + + it("Displays all attachments that were created in this revision if the isOnAmendmentsAndOtherRevisionsPage flag is false, without their create operation", () => { + componentTestingHelper.loadQuery(); + componentTestingHelper.renderComponent(getPropsFromTestQuery, { + isOnAmendmentsAndOtherRevisionsPage: true, + }); + + expect(screen.queryByText(/Create/i)).not.toBeInTheDocument(); + expect(screen.getByText(/test-attachment-1.jpg/i)).toBeInTheDocument(); + expect(screen.getByText(/test-attachment-2.jpg/i)).toBeInTheDocument(); + }); + + it("Doesn't display archived items if the isOnAmendmentsAndOtherRevisionsPage flag is false", () => { + componentTestingHelper.loadQuery(); + componentTestingHelper.renderComponent(getPropsFromTestQuery, { + isOnAmendmentsAndOtherRevisionsPage: true, + }); + + expect(screen.queryByText(/Archive/i)).not.toBeInTheDocument(); + expect( + screen.queryByText(/test-attachment-3.jpg/i) + ).not.toBeInTheDocument(); + }); });