Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #326: cautions form #353

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions public/locales/en/labelDataValidationPage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"organizations": {
"stepTitle": "Organizations"
},
"baseInformation": {
"stepTitle": "Base Information",
"fields": {
Expand Down Expand Up @@ -32,6 +29,12 @@
}
}
},
"organizations": {
"stepTitle": "Organizations"
},
"cautions": {
"stepTitle": "Cautions"
},
"verifiedQuantityMultiInput": {
"deleteRow": "Delete this row",
"defaultPlaceholder": "Enter value",
Expand Down Expand Up @@ -68,5 +71,30 @@
"row": "Row containing inputs for unit and value",
"errorIcon": "Icon indicating a validation error"
}
},
"verifiedBilingualTable": {
"english": "English",
"french": "French",
"actions": "Actions",
"placeholders": {
"english": "Enter English text",
"french": "Enter French text"
},
"addRow": "Add Row",
"delete": "Delete Row",
"verify": "Mark as Verified",
"unverify": "Mark as Unverified",
"verifyAll": "Mark All as Verified",
"unverifyAll": "Mark All as Unverified",
"accessibility": {
"englishInput": "English text input for row {{row}}",
"frenchInput": "French text input for row {{row}}",
"deleteButton": "Button to delete this row",
"addRowButton": "Button to add a new row",
"verifyButton": "Button to mark this row as Verified",
"unverifyButton": "Button to mark this row as Unverified",
"verifyAllButton": "Button to mark all rows as Verified",
"unverifyAllButton": "Button to mark all rows as Unverified"
}
}
}
34 changes: 31 additions & 3 deletions public/locales/fr/labelDataValidationPage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"organizations": {
"stepTitle": "Organisations"
},
"baseInformation": {
"stepTitle": "Informations de base sur l'engrais",
"fields": {
Expand Down Expand Up @@ -32,6 +29,12 @@
}
}
},
"organizations": {
"stepTitle": "Organisations"
},
"cautions": {
"stepTitle": "Mises en garde"
},
"verifiedQuantityMultiInput": {
"deleteRow": "Supprimer cette ligne",
"defaultPlaceholder": "Entrez une valeur",
Expand Down Expand Up @@ -68,5 +71,30 @@
"row": "Ligne contenant les champs pour l'unité et la valeur",
"errorIcon": "Icône indiquant une erreur de validation"
}
},
"verifiedBilingualTable": {
"english": "Anglais",
"french": "Français",
"actions": "Actions",
"placeholders": {
"english": "Entrez le texte en anglais",
"french": "Entrez le texte en français"
},
"addRow": "Ajouter une ligne",
"delete": "Supprimer cette ligne",
"verify": "Marquer comme vérifié",
"unverify": "Marquer comme non vérifié",
"verifyAll": "Tout marquer comme vérifié",
"unverifyAll": "Tout marquer comme non vérifié",
"accessibility": {
"englishInput": "Zone de texte en anglais pour la ligne {{row}}",
"frenchInput": "Zone de texte en français pour la ligne {{row}}",
"deleteButton": "Bouton pour supprimer cette ligne",
"addRowButton": "Bouton pour ajouter une nouvelle ligne",
"verifyButton": "Bouton pour marquer cette ligne comme vérifiée",
"unverifyButton": "Bouton pour marquer cette ligne comme non vérifiée",
"verifyAllButton": "Bouton pour tout marquer comme vérifié",
"unverifyAllButton": "Bouton pour tout marquer comme non vérifié"
}
}
}
49 changes: 43 additions & 6 deletions src/app/label-data-validation/__tests__/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ describe("LabelDataValidationPage Functionality", () => {

fireEvent.click(nextButton);
fireEvent.click(nextButton);
expect(screen.getByTestId("organizations-form")).toBeInTheDocument();
fireEvent.click(nextButton);
expect(screen.getByTestId("cautions-form")).toBeInTheDocument();
});

it("renders the mocked Image Viewer", () => {
Expand All @@ -66,11 +67,13 @@ describe("LabelDataValidationPage Functionality", () => {
});
});

describe("LabelDataValidationPage and OrganizationsForm Integration", () => {
describe("LabelDataValidationPage and Forms Integration", () => {
it("marks the Organizations step as Completed or Incomplete when fields are Verified", () => {
render(<LabelDataValidationPage />);

const spans = screen.getAllByText("organizations.stepTitle", { exact: true });
const spans = screen.getAllByText("organizations.stepTitle", {
exact: true,
});
const targetSpan = spans.find((span) =>
span.classList.contains("MuiStepLabel-label"),
);
Expand All @@ -88,13 +91,13 @@ describe("LabelDataValidationPage and OrganizationsForm Integration", () => {

expect(targetSpan).not.toHaveClass("Mui-completed");
});
});

describe("LabelDataValidationPage and BaseInformationForm Integration", () => {
it("marks the Base Information step as Completed or Incomplete when fields are Verified", async () => {
render(<LabelDataValidationPage />);

const spans = screen.getAllByText("baseInformation.stepTitle", { exact: true });
const spans = screen.getAllByText("baseInformation.stepTitle", {
exact: true,
});
const targetSpan = spans.find((span) =>
span.classList.contains("MuiStepLabel-label"),
);
Expand Down Expand Up @@ -124,4 +127,38 @@ describe("LabelDataValidationPage and BaseInformationForm Integration", () => {

expect(targetSpan).not.toHaveClass("Mui-completed");
});

it("marks the Cautions step as Completed or Incomplete when fields are Verified", async () => {
render(<LabelDataValidationPage />);

const spans = screen.getAllByText("cautions.stepTitle", {
exact: true,
});
const targetSpan = spans.find((span) =>
span.classList.contains("MuiStepLabel-label"),
);
expect(targetSpan).not.toHaveClass("Mui-completed");

const button = targetSpan!.closest("button");
await act(async () => {
fireEvent.click(button!);
});

const verifyButtons = screen.getAllByTestId(/verify-row-btn-cautions-\d+/);
expect(verifyButtons.length).toBeGreaterThanOrEqual(1);

for (const button of verifyButtons) {
await act(async () => {
fireEvent.click(button);
});
}

expect(targetSpan).toHaveClass("Mui-completed");

await act(async () => {
fireEvent.click(verifyButtons[0]);
});

expect(targetSpan).not.toHaveClass("Mui-completed");
});
});
17 changes: 17 additions & 0 deletions src/app/label-data-validation/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";
import BaseInformationForm from "@/components/BaseInformationForm";
import CautionsForm from "@/components/CautionsForm";
import ImageViewer from "@/components/ImageViewer";
import OrganizationsForm from "@/components/OrganizationsForm";
import {
Expand Down Expand Up @@ -32,6 +33,9 @@ function LabelDataValidationPage() {
useState<StepStatus>(StepStatus.Incomplete);
const [baseInformationStepStatus, setBaseInformationStepStatus] =
useState<StepStatus>(StepStatus.Incomplete);
const [cautionsStepStatus, setCautionsStepStatus] = useState<StepStatus>(
StepStatus.Incomplete,
);
const { showAlert } = useAlertStore();

const createStep = (
Expand Down Expand Up @@ -63,6 +67,12 @@ function LabelDataValidationPage() {
organizationsStepStatus,
setOrganizationsStepStatus,
),
createStep(
t("cautions.stepTitle"),
CautionsForm,
cautionsStepStatus,
setCautionsStepStatus,
),
];

const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -89,6 +99,13 @@ function LabelDataValidationPage() {
);
}, [labelData.baseInformation, setBaseInformationStepStatus]);

useEffect(() => {
const verified = labelData.cautions.every((caution) => caution.verified);
setCautionsStepStatus(
verified ? StepStatus.Completed : StepStatus.Incomplete,
);
}, [labelData.cautions, setCautionsStepStatus]);

return (
<Container
className="flex flex-col max-w-[1920px] bg-gray-100 "
Expand Down
37 changes: 37 additions & 0 deletions src/components/CautionsForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FormComponentProps, LabelData } from "@/types/types";
import { Box } from "@mui/material";
import { useEffect } from "react";
import { FormProvider, useForm, useWatch } from "react-hook-form";
import VerifiedBilingualTable from "./VerifiedBilingualTable";

function CautionsForm({ labelData, setLabelData }: FormComponentProps) {
const methods = useForm<LabelData>({
defaultValues: labelData,
});

const { control } = methods;

const watchedCautions = useWatch({
control,
name: "cautions",
});

useEffect(() => {
if (watchedCautions) {
setLabelData((prevLabelData) => ({
...prevLabelData,
cautions: watchedCautions,
}));
}
}, [watchedCautions, setLabelData]);

return (
<FormProvider {...methods}>
<Box className="p-4" data-testid="cautions-form">
<VerifiedBilingualTable path={"cautions"} />
</Box>
</FormProvider>
);
}

export default CautionsForm;
Loading
Loading