Skip to content

Commit

Permalink
Merge pull request #2364 from tom0827/TRACK-2363
Browse files Browse the repository at this point in the history
Uneditable work fields
  • Loading branch information
tom0827 authored Jul 24, 2024
2 parents 225ef39 + ad24ded commit 93c3536
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
180 changes: 177 additions & 3 deletions epictrack-web/src/components/work/WorkForm/__test__/WorkForm.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -198,19 +338,23 @@ describe("WorkForm", () => {
)
)
);
});

it("renders the form", () => {
cy.mount(
<Provider store={store}>
<WorkForm work={null} fetchWork={cy.stub()} saveWork={cy.stub()} />
</Provider>
);
});

it("renders the form", () => {
cy.get("form").should("be.visible");
});

it("The title is created from project name and work type", () => {
cy.mount(
<Provider store={store}>
<WorkForm work={null} fetchWork={cy.stub()} saveWork={cy.stub()} />
</Provider>
);
cy.wait("@getWorkTypes").its("response.statusCode").should("eq", 200);
const workTypeSelect = cy
.get("label")
Expand Down Expand Up @@ -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(
<Provider store={store}>
<WorkForm work={mockWork} fetchWork={cy.stub()} saveWork={cy.stub()} />
</Provider>
);
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(
<Provider store={store}>
<WorkForm work={mockWork} fetchWork={cy.stub()} saveWork={cy.stub()} />
</Provider>
);
const projectSelect = cy
.get("label")
.contains("Project")
.parent()
.find("input")
.first();
projectSelect.should("have.attr", "disabled");
});
});
7 changes: 4 additions & 3 deletions epictrack-web/src/components/work/WorkForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default function WorkForm({
React.useState<boolean>(false);

const isSpecialFieldUnlocked = isEpdFieldUnlocked || isWorkLeadFieldUnlocked;
const workHasBeenCreated = work?.id ? true : false;

useEffect(() => {
reset(work ?? defaultWork);
Expand Down Expand Up @@ -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}
></ControlledSelectV2>
</Grid>
<Grid item xs={4}>
Expand All @@ -340,9 +341,9 @@ export default function WorkForm({
</ETFormLabel>
<ControlledDatePicker
name="start_date"
disabled={!canEdit || isSpecialFieldUnlocked}
datePickerProps={{
minDate: dayjs(MIN_WORK_START_DATE),
disabled: !canEdit || isSpecialFieldUnlocked,
}}
/>
</Grid>
Expand All @@ -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}
></ControlledSelectV2>
</Grid>
<Grid item xs={6}>
Expand Down
2 changes: 0 additions & 2 deletions epictrack-web/src/components/workPlan/event/EventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -739,7 +738,6 @@ const EventForm = ({
}
datePickerProps={{
referenceDate: dayjs(acutalReferenceDate),
disabled: isFormFieldsLocked,
minDate: actualDateMin,
maxDate: actualDateMax,
onDateChange: (event: any, defaultOnChange: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93c3536

Please sign in to comment.