From ad24ded4e2e480eb8e1e64337382d1bd1957bfec Mon Sep 17 00:00:00 2001 From: Tom Chapman Date: Tue, 23 Jul 2024 12:54:39 -0700 Subject: [PATCH] make project and worktype selects disabled after work creation --- .../ControlledDatePicker.tsx | 1 - .../work/WorkForm/__test__/WorkForm.cy.tsx | 180 +++++++++++++++++- .../src/components/work/WorkForm/index.tsx | 7 +- .../components/workPlan/event/EventForm.tsx | 2 - .../event/components/ExtensionInput.tsx | 1 - 5 files changed, 181 insertions(+), 10 deletions(-) diff --git a/epictrack-web/src/components/shared/controlledInputComponents/ControlledDatePicker.tsx b/epictrack-web/src/components/shared/controlledInputComponents/ControlledDatePicker.tsx index afae793f2..6ecdd5b4f 100644 --- a/epictrack-web/src/components/shared/controlledInputComponents/ControlledDatePicker.tsx +++ b/epictrack-web/src/components/shared/controlledInputComponents/ControlledDatePicker.tsx @@ -13,7 +13,6 @@ type ControlledDatePickerProps = { referenceDate?: dayjs.Dayjs; minDate?: dayjs.Dayjs | undefined; maxDate?: dayjs.Dayjs | undefined; - disabled?: boolean; onDateChange?: ( value: dayjs.Dayjs | null, defaultOnChangeFunc: (value: dayjs.Dayjs | null) => void diff --git a/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx b/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx index 5195c9d70..ffbc63069 100644 --- a/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx +++ b/epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx @@ -7,6 +7,7 @@ import { store } from "store"; import { UserDetail } from "services/userService/type"; import { AppConfig } from "config"; import { setupIntercepts } from "../../../../../cypress/support/utils"; +import { WORK_STATE } from "components/shared/constants"; const generateFakePosition = () => { return { @@ -179,6 +180,145 @@ const endpoints = [ }, ]; +const mockWork = { + id: faker.number.int(), + title: faker.lorem.words(3), + simple_title: faker.lorem.word(), + report_description: faker.lorem.sentence(), + epic_description: faker.lorem.sentence(), + is_cac_recommended: false, + is_active: true, + is_complete: false, + is_high_priority: false, + is_deleted: false, + start_date: faker.date.past().toISOString(), + anticipated_decision_date: faker.date.future().toISOString(), + decision_date: faker.date.future().toISOString(), + work_decision_date: faker.date.future().toISOString(), + first_nation_notes: faker.lorem.paragraph(), + status_notes: faker.lorem.paragraph(), + work_state: WORK_STATE.IN_PROGRESS.value, + project_id: faker.number.int(), + ministry_id: faker.number.int(), + ea_act_id: faker.number.int(), + eao_team_id: faker.number.int(), + federal_involvement_id: faker.number.int(), + responsible_epd_id: faker.number.int(), + work_lead_id: faker.number.int(), + work_type_id: faker.number.int(), + current_work_phase_id: faker.number.int(), + substitution_act_id: faker.number.int(), + eac_decision_by_id: faker.number.int(), + decision_by_id: faker.number.int(), + decision_maker_position_id: faker.number.int(), + start_date_locked: faker.datatype.boolean(), + created_at: faker.date.past().toISOString(), + project: { + id: faker.number.int(), + name: faker.lorem.words(2), + created_at: faker.date.past().toISOString(), + description: faker.lorem.sentence(), + address: faker.lorem.word(), + abbreviation: faker.lorem.word(), + type: { id: faker.number.int(), name: faker.lorem.word() }, + sub_type: { id: faker.number.int(), name: faker.lorem.word() }, + proponent: { id: faker.number.int(), name: faker.lorem.word() }, + region_env: { id: faker.number.int(), name: faker.lorem.word() }, + region_flnro: { id: faker.number.int(), name: faker.lorem.word() }, + }, + ministry: { + id: faker.number.int(), + name: faker.lorem.word(), + abbreviation: faker.lorem.word(), + combined: faker.lorem.word(), + minister: { + id: faker.number.int(), + phone: faker.lorem.word(), + email: faker.internet.email(), + is_active: true, + position_id: faker.number.int(), + first_name: faker.lorem.word(), + last_name: faker.lorem.word(), + full_name: faker.lorem.word(), + position: { + id: faker.number.int(), + name: faker.lorem.word(), + sort_order: faker.number.int(), + }, + }, + sort_order: 1, + }, + ea_act: { id: faker.number.int(), name: faker.lorem.word() }, + eao_team: { id: faker.number.int(), name: faker.lorem.word() }, + federal_involvement: { + id: faker.number.int(), + name: faker.lorem.word(), + }, + responsible_epd: { + id: faker.number.int(), + phone: faker.lorem.word(), + email: faker.internet.email(), + is_active: true, + position_id: faker.number.int(), + first_name: faker.lorem.word(), + last_name: faker.lorem.word(), + full_name: faker.lorem.word(), + position: { + id: faker.number.int(), + name: faker.lorem.word(), + sort_order: faker.number.int(), + }, + }, + work_lead: { + id: faker.number.int(), + phone: faker.lorem.word(), + email: faker.internet.email(), + is_active: true, + position_id: faker.number.int(), + first_name: faker.lorem.word(), + last_name: faker.lorem.word(), + full_name: faker.lorem.word(), + position: { + id: faker.number.int(), + name: faker.lorem.word(), + sort_order: faker.number.int(), + }, + }, + work_type: { id: faker.number.int(), name: faker.lorem.word() }, + current_work_phase: { id: faker.number.int(), name: faker.lorem.word() }, + substitution_act: { id: faker.number.int(), name: faker.lorem.word() }, + eac_decision_by: { + id: faker.number.int(), + phone: faker.lorem.word(), + email: faker.internet.email(), + is_active: true, + position_id: faker.number.int(), + first_name: faker.lorem.word(), + last_name: faker.lorem.word(), + full_name: faker.lorem.word(), + position: { + id: faker.number.int(), + name: faker.lorem.word(), + sort_order: faker.number.int(), + }, + }, + decision_by: { + id: faker.number.int(), + phone: faker.lorem.word(), + email: faker.internet.email(), + is_active: true, + position_id: faker.number.int(), + first_name: faker.lorem.word(), + last_name: faker.lorem.word(), + full_name: faker.lorem.word(), + position: { + id: faker.number.int(), + name: faker.lorem.word(), + sort_order: faker.number.int(), + }, + }, +}; + describe("WorkForm", () => { beforeEach(() => { setupIntercepts(endpoints); @@ -198,19 +338,23 @@ describe("WorkForm", () => { ) ) ); + }); + it("renders the form", () => { cy.mount( ); - }); - - it("renders the form", () => { cy.get("form").should("be.visible"); }); it("The title is created from project name and work type", () => { + cy.mount( + + + + ); cy.wait("@getWorkTypes").its("response.statusCode").should("eq", 200); const workTypeSelect = cy .get("label") @@ -244,4 +388,34 @@ describe("WorkForm", () => { .contains(`${mockProject.name} - ${mockWorkType.name} -`) .should("be.visible"); }); + + it("WorkType select should be disabled when a work exists", () => { + cy.mount( + + + + ); + const workTypeSelect = cy + .get("label") + .contains("Worktype") + .parent() + .find("input") + .first(); + workTypeSelect.should("have.attr", "disabled"); + }); + + it("Project select should be disabled when a work exists", () => { + cy.mount( + + + + ); + const projectSelect = cy + .get("label") + .contains("Project") + .parent() + .find("input") + .first(); + projectSelect.should("have.attr", "disabled"); + }); }); diff --git a/epictrack-web/src/components/work/WorkForm/index.tsx b/epictrack-web/src/components/work/WorkForm/index.tsx index 64085ce46..d60055a4e 100644 --- a/epictrack-web/src/components/work/WorkForm/index.tsx +++ b/epictrack-web/src/components/work/WorkForm/index.tsx @@ -137,6 +137,7 @@ export default function WorkForm({ React.useState(false); const isSpecialFieldUnlocked = isEpdFieldUnlocked || isWorkLeadFieldUnlocked; + const workHasBeenCreated = work?.id ? true : false; useEffect(() => { reset(work ?? defaultWork); @@ -331,7 +332,7 @@ export default function WorkForm({ getOptionValue={(o: ListType) => o?.id.toString()} getOptionLabel={(o: ListType) => o.name} {...register("work_type_id")} - disabled={!canEdit || isSpecialFieldUnlocked} + disabled={!canEdit || workHasBeenCreated} > @@ -340,9 +341,9 @@ export default function WorkForm({ @@ -358,7 +359,7 @@ export default function WorkForm({ getOptionValue={(o: ListType) => o?.id?.toString()} getOptionLabel={(o: ListType) => o?.name} {...register("project_id")} - disabled={!canEdit || isSpecialFieldUnlocked} + disabled={!canEdit || workHasBeenCreated} > diff --git a/epictrack-web/src/components/workPlan/event/EventForm.tsx b/epictrack-web/src/components/workPlan/event/EventForm.tsx index 4f7be713c..d0a03e37e 100644 --- a/epictrack-web/src/components/workPlan/event/EventForm.tsx +++ b/epictrack-web/src/components/workPlan/event/EventForm.tsx @@ -714,7 +714,6 @@ const EventForm = ({ referenceDate: dayjs( selectedWorkPhase?.work_phase.start_date ), - disabled: isFormFieldsLocked, minDate: anticipatedMinDate, onDateChange: (event: any, defaultOnChange: any) => { const d = event ? event["$d"] : null; @@ -739,7 +738,6 @@ const EventForm = ({ } datePickerProps={{ referenceDate: dayjs(acutalReferenceDate), - disabled: isFormFieldsLocked, minDate: actualDateMin, maxDate: actualDateMax, onDateChange: (event: any, defaultOnChange: any) => { diff --git a/epictrack-web/src/components/workPlan/event/components/ExtensionInput.tsx b/epictrack-web/src/components/workPlan/event/components/ExtensionInput.tsx index 23d0d6236..4c4f42977 100644 --- a/epictrack-web/src/components/workPlan/event/components/ExtensionInput.tsx +++ b/epictrack-web/src/components/workPlan/event/components/ExtensionInput.tsx @@ -111,7 +111,6 @@ const ExtensionInput = (props: ExtensionInputProps) => { name="phase_end_date" disabled={props.isFormFieldsLocked} datePickerProps={{ - disabled: props.isFormFieldsLocked, onDateChange: (event: any, defaultOnChange: any) => { const d = event ? event["$d"] : null; defaultOnChange(d);