diff --git a/services/common/src/components/forms/RenderOrgBookSearch.tsx b/services/common/src/components/forms/RenderOrgBookSearch.tsx index ed4d261e8f..a825109a87 100644 --- a/services/common/src/components/forms/RenderOrgBookSearch.tsx +++ b/services/common/src/components/forms/RenderOrgBookSearch.tsx @@ -16,7 +16,6 @@ import { BaseInputProps, getFormItemLabel } from "./BaseInput"; interface OrgBookSearchProps extends BaseInputProps { data?: any; - isDisabled?: boolean; setCredential: (credential: IOrgbookCredential) => void; } @@ -29,7 +28,7 @@ const RenderOrgBookSearch: FC = ({ input, meta, required, - isDisabled = false, + disabled = false, setCredential, }) => { const dispatch = useDispatch(); @@ -133,7 +132,7 @@ const RenderOrgBookSearch: FC = ({ onChange={handleChange} onSelect={handleSelect} style={{ width: "100%" }} - disabled={isDisabled} + disabled={disabled} value={options.length === 1 ? { key: options[0].text } : null} > {options.map((option) => ( diff --git a/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx b/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx index fb838b7dac..8a3aac5d42 100644 --- a/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx +++ b/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx @@ -608,6 +608,7 @@ export const AuthorizationsInvolved: FC = ({ f component={RenderHiddenField} required validate={[requiredList]} + disabled={fieldsDisabled} label={Regulatory Approval Type} > diff --git a/services/common/src/components/projectSummary/ProjectSummaryFormComponents.spec.tsx b/services/common/src/components/projectSummary/ProjectSummaryFormComponents.spec.tsx new file mode 100644 index 0000000000..7cb8e6af18 --- /dev/null +++ b/services/common/src/components/projectSummary/ProjectSummaryFormComponents.spec.tsx @@ -0,0 +1,140 @@ +import React from "react"; +import { render } from "@testing-library/react"; +import FormWrapper from "../forms/FormWrapper"; +import { FORM, SystemFlagEnum } from "@mds/common/constants"; +import { ProjectManagement } from "./ProjectManagement"; +import { LegalLandOwnerInformation } from "./LegalLandOwnerInformation"; +import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper"; +import * as MOCK from "@mds/common/tests/mocks/dataMocks"; +import { AUTHENTICATION, PROJECTS, STATIC_CONTENT } from "@mds/common/constants/reducerTypes"; +import { formatProjectSummary } from "@mds/common/redux/selectors/projectSelectors"; +import BasicInformation from "./BasicInformation"; +import ProjectLinks from "./ProjectLinks"; +import ProjectContacts from "./ProjectContacts"; +import ProjectDates from "./ProjectDates"; +import Applicant from "./Applicant"; +import { Agent } from "./Agent"; +import { ApplicationSummary } from "./ApplicationSummary"; +import AuthorizationsInvolved from "./AuthorizationsInvolved"; +import Declaration from "./Declaration"; +import DocumentUpload from "./DocumentUpload"; +import { FacilityOperator } from "./FacilityOperator"; +import { BrowserRouter } from "react-router-dom"; + +const amsAuthTypes = ['AIR_EMISSIONS_DISCHARGE_PERMIT', 'EFFLUENT_DISCHARGE_PERMIT', 'REFUSE_DISCHARGE_PERMIT']; +const project = { project_lead_party_guid: "project_lead_party_guid" }; +const formattedProjectSummary = formatProjectSummary(MOCK.PROJECT_SUMMARY, project, amsAuthTypes); + +const initialState = { + form: { + [FORM.ADD_EDIT_PROJECT_SUMMARY]: { + values: formattedProjectSummary, + }, + }, + [PROJECTS]: { + projectSummary: MOCK.PROJECT_SUMMARY, + projects: MOCK.PROJECTS.records, + project: MOCK.PROJECT, + }, + [STATIC_CONTENT]: { + projectSummaryAuthorizationTypes: + MOCK.BULK_STATIC_CONTENT_RESPONSE.projectSummaryAuthorizationTypes, + }, + [AUTHENTICATION]: { + systemFlag: SystemFlagEnum.core, + userAccessData: MOCK.USER_ACCESS_DATA, + userInfo: { preferred_username: "USERNAME" } + }, +}; + +const mockFields = jest.fn(); +const mockDocFields = jest.fn(); +const mockAuthFields = jest.fn(); +const mockEnvFields = jest.fn(); + +jest.mock("@mds/common/components/projects/projectUtils", () => ({ + areFieldsDisabled: () => mockFields(), + areDocumentFieldsDisabled: () => mockDocFields(), + areAuthFieldsDisabled: () => mockAuthFields(), + areAuthEnvFieldsDisabled: () => mockEnvFields(), + getProjectStatusDescription: () => jest.fn().mockReturnValue("Status Description") +})); + +const allowedEnabledWhenDisabled = [ + "status_code", // core user can edit status + "project_lead_party_guid", // and the project lead + "ADD_EDIT_PROJECT_SUMMARY_ams_terms_agreed", // still debating these 2, but harmless to leave open + "ADD_EDIT_PROJECT_SUMMARY_confirmation_of_submission", +]; + +const filterOutAllowedEnabledIds = (idArray: string[]) => { + return idArray.filter((id) => !allowedEnabledWhenDisabled.includes(id)); +}; +describe("ProjectSummaryForm components disable accurately accoring to functions", () => { + const renderedComponents = ({ fieldsDisabled, authFieldsDisabled, docFieldsDisabled, envFieldsDisabled }) => ( + + + + + + + + + + + + + + + + + + ); + + test("shows all disabled", () => { + const params = { + fieldsDisabled: true, + authFieldsDisabled: true, + docFieldsDisabled: true, + envFieldsDisabled: true + }; + mockFields.mockReturnValue(params.fieldsDisabled); + mockDocFields.mockReturnValue(params.docFieldsDisabled); + mockAuthFields.mockReturnValue(params.authFieldsDisabled); + mockEnvFields.mockReturnValue(params.envFieldsDisabled); + + const { container } = render( + + {renderedComponents(params)} + + ); + + const enabledInputs = container.querySelectorAll(`input:not(:disabled)`); + const enabledInputIds = Array.from(enabledInputs).map((input) => input.id); + const filteredIds = filterOutAllowedEnabledIds(enabledInputIds); + expect(filteredIds).toEqual([]); + }); + + test("shows all enabled", () => { + const params = { + fieldsDisabled: false, + authFieldsDisabled: false, + docFieldsDisabled: false, + envFieldsDisabled: false + }; + mockFields.mockReturnValue(params.fieldsDisabled); + mockDocFields.mockReturnValue(params.docFieldsDisabled); + mockAuthFields.mockReturnValue(params.authFieldsDisabled); + mockEnvFields.mockReturnValue(params.envFieldsDisabled); + + const { container } = render( + + {renderedComponents(params)} + + ); + + const disabledInputs = container.querySelectorAll(`input:disabled`); + const disabledInputIds = Array.from(disabledInputs).map((input) => input.id); + expect(disabledInputIds).toEqual([]); + }); +}); \ No newline at end of file diff --git a/services/common/src/redux/selectors/projectSelectors.ts b/services/common/src/redux/selectors/projectSelectors.ts index 3c7aa4c219..37198c90b0 100644 --- a/services/common/src/redux/selectors/projectSelectors.ts +++ b/services/common/src/redux/selectors/projectSelectors.ts @@ -138,27 +138,31 @@ export const getFormattedProjectApplication = createSelector( } ); +export const formatProjectSummary = (summary, project, amsAuthTypes) => { + const documents = formatProjectSummaryDocuments(summary.documents); + const contacts = formatProjectContact(project.contacts); + const agent = formatProjectSummaryParty(summary.agent); + const facility_operator = formatProjectSummaryParty(summary.facility_operator); + const confirmation_of_submission = Boolean(summary.submission_date); + + const formattedSummary = { + ...summary, + contacts, + agent, + facility_operator, + confirmation_of_submission, + ...formatAuthorizations(amsAuthTypes, confirmation_of_submission, summary.authorizations), + ...documents, + }; + + formattedSummary.project_lead_party_guid = project.project_lead_party_guid; + return formattedSummary; +} + export const getFormattedProjectSummary = createSelector( [getProjectSummary, getProject, getAmsAuthorizationTypes], (summary, project, amsAuthTypes) => { - const documents = formatProjectSummaryDocuments(summary.documents); - const contacts = formatProjectContact(project.contacts); - const agent = formatProjectSummaryParty(summary.agent); - const facility_operator = formatProjectSummaryParty(summary.facility_operator); - const confirmation_of_submission = Boolean(summary.submission_date); - - const formattedSummary = { - ...summary, - contacts, - agent, - facility_operator, - confirmation_of_submission, - ...formatAuthorizations(amsAuthTypes, confirmation_of_submission, summary.authorizations), - ...documents, - }; - - formattedSummary.project_lead_party_guid = project.project_lead_party_guid; - - return formattedSummary; + console.log(amsAuthTypes); + return formatProjectSummary(summary, project, amsAuthTypes); } );