Skip to content

Commit

Permalink
[MDS-6129] streamline status actions (#3245)
Browse files Browse the repository at this point in the history
* wip

* implement disabled fields.

* update disabled fields implementation.

* update test snapshot.

* update tests.

* update logic.

* update unit tests snapshot.

* fix cypress test

* add tests

* update test.
  • Loading branch information
henryoforeh-dev authored Sep 13, 2024
1 parent 901195a commit 2ed8d13
Show file tree
Hide file tree
Showing 33 changed files with 5,856 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
INSERT INTO
project_summary_status_code (
project_summary_status_code,
description,
alias_description,
display_order,
active_ind,
create_user,
update_user
)
VALUES
(
'CHR',
'Change Requested',
'Change Requested',
210,
true,
'system-mds',
'system-mds'
);
50 changes: 50 additions & 0 deletions services/common/src/components/projectSummary/Agent.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import { render } from "@testing-library/react";
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper";
import { PROJECTS, STATIC_CONTENT, AUTHENTICATION } from "@mds/common/constants/reducerTypes";
import { FORM } from "../..";
import FormWrapper from "../forms/FormWrapper";
import * as MOCK from "@mds/common/tests/mocks/dataMocks";
import { Agent } from "./Agent";

const initialState = {
form: {
[FORM.ADD_EDIT_PROJECT_SUMMARY]: {
values: {
status_code: "DFT",
agent: {
credential_id: 1000,
party_type_code: null,
address: { address_type_code: "CAN", sub_division_code: "BC" },
},
is_agent: true,
},
},
},
[PROJECTS]: {
projectSummary: MOCK.PROJECT_SUMMARY,
},
[STATIC_CONTENT]: {
provinceOptions: MOCK.BULK_STATIC_CONTENT_RESPONSE.provinceOptions,
},
[AUTHENTICATION]: {
systemFlag: "core",
},
};

describe("Agent Component", () => {
it("should render the component with expected fields", () => {
const { container } = render(
<ReduxWrapper initialState={initialState}>
<FormWrapper
name={FORM.ADD_EDIT_PROJECT_SUMMARY}
initialValues={initialState}
onSubmit={() => {}}
>
<Agent />
</FormWrapper>
</ReduxWrapper>
);
expect(container).toMatchSnapshot();
});
});
30 changes: 27 additions & 3 deletions services/common/src/components/projectSummary/Agent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { FC, useEffect, useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import { Field, change, getFormValues } from "redux-form";
import { Col, Row, Typography, Alert } from "antd";
import { FORM } from "@mds/common/constants/forms";
import { FORM, isFieldDisabled } from "@mds/common/constants";
import RenderField from "@mds/common/components/forms/RenderField";
import RenderRadioButtons from "@mds/common/components/forms/RenderRadioButtons";
import RenderSelect from "@mds/common/components/forms/RenderSelect";
Expand All @@ -26,6 +26,7 @@ import { getOrgBookCredential } from "@mds/common/redux/selectors/orgbookSelecto
import { normalizePhone } from "@mds/common/redux/utils/helpers";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleCheck, faCircleX, faSpinner } from "@fortawesome/pro-light-svg-icons";
import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors";

export const Agent: FC = () => {
const dispatch = useDispatch();
Expand All @@ -42,6 +43,7 @@ export const Agent: FC = () => {
const [verified, setVerified] = useState(false);
const [checkingStatus, setCheckingStatus] = useState(false);
const [verifiedCredential, setVerifiedCredential] = useState(null);
const systemFlag = useSelector(getSystemFlag);

useEffect(() => {
setCheckingStatus(true);
Expand Down Expand Up @@ -178,6 +180,7 @@ export const Agent: FC = () => {
validate={[requiredRadioButton]}
label="Are you an agent applying on behalf of the applicant?"
component={RenderRadioButtons}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>

{is_agent && (
Expand All @@ -193,6 +196,7 @@ export const Agent: FC = () => {
]}
optionType="button"
onChange={handleResetParty}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
{party_type_code === "ORG" && (
<div>
Expand Down Expand Up @@ -232,6 +236,7 @@ export const Agent: FC = () => {
required
validate={[required]}
component={RenderField}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>
Expand All @@ -246,6 +251,7 @@ export const Agent: FC = () => {
component={RenderField}
required
validate={[required, maxLength(100)]}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
<Col md={12} sm={24}>
Expand All @@ -255,14 +261,20 @@ export const Agent: FC = () => {
component={RenderField}
required
validate={[required, maxLength(100)]}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>
)}

<Row gutter={16}>
<Col md={12} sm={24}>
<Field name="agent.job_title" label="Agent's Title" component={RenderField} />
<Field
name="agent.job_title"
label="Agent's Title"
component={RenderField}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>

Expand All @@ -275,6 +287,7 @@ export const Agent: FC = () => {
validate={isInternational ? [required] : [required, phoneNumber]}
component={RenderField}
normalize={normalizePhone}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
<Col md={4} sm={5}>
Expand All @@ -287,6 +300,7 @@ export const Agent: FC = () => {
required
validate={[required, email]}
component={RenderField}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>
Expand All @@ -300,10 +314,16 @@ export const Agent: FC = () => {
required
validate={[required]}
component={RenderField}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
<Col md={5} sm={24}>
<Field name="agent.address.suite_no" label="Unit #" component={RenderField} />
<Field
name="agent.address.suite_no"
label="Unit #"
component={RenderField}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>

Expand All @@ -316,6 +336,7 @@ export const Agent: FC = () => {
validate={[required]}
data={CONTACTS_COUNTRY_OPTIONS}
component={RenderSelect}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>

Expand All @@ -327,6 +348,7 @@ export const Agent: FC = () => {
data={provinceOptions.filter((p) => p.subType === address_type_code)}
validate={!isInternational ? [required] : []}
component={RenderSelect}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>
Expand All @@ -339,6 +361,7 @@ export const Agent: FC = () => {
required
validate={[required]}
component={RenderField}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
<Col md={12} sm={24}>
Expand All @@ -347,6 +370,7 @@ export const Agent: FC = () => {
label="Postal Code"
component={RenderField}
validate={[postalCodeWithCountry(address_type_code), maxLength(10)]}
disabled={isFieldDisabled(systemFlag, formValues?.status_code)}
/>
</Col>
</Row>
Expand Down
42 changes: 42 additions & 0 deletions services/common/src/components/projectSummary/Applicant.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react";
import { render } from "@testing-library/react";
import { ReduxWrapper } from "@mds/common/tests/utils/ReduxWrapper";
import { PROJECTS, STATIC_CONTENT, AUTHENTICATION } from "@mds/common/constants/reducerTypes";
import { FORM } from "../..";
import FormWrapper from "../forms/FormWrapper";
import * as MOCK from "@mds/common/tests/mocks/dataMocks";
import Applicant from "./Applicant";

const initialState = {
form: {
[FORM.ADD_EDIT_PROJECT_SUMMARY]: {
values: {},
},
},
[PROJECTS]: {
projectSummary: MOCK.PROJECT_SUMMARY,
},
[STATIC_CONTENT]: {
provinceOptions: MOCK.BULK_STATIC_CONTENT_RESPONSE.provinceOptions,
},
[AUTHENTICATION]: {
systemFlag: "ms",
},
};

describe("Applicant Component", () => {
it("should render the component with expected fields", () => {
const { container } = render(
<ReduxWrapper initialState={initialState}>
<FormWrapper
name={FORM.ADD_EDIT_PROJECT_SUMMARY}
initialValues={initialState}
onSubmit={() => {}}
>
<Applicant />
</FormWrapper>
</ReduxWrapper>
);
expect(container).toMatchSnapshot();
});
});
Loading

0 comments on commit 2ed8d13

Please sign in to comment.