Skip to content

Commit

Permalink
Merge pull request #453 from ai-cfia/429-inspection-comment
Browse files Browse the repository at this point in the history
issue #429: implement inspection notes
  • Loading branch information
k-allagbe authored Feb 7, 2025
2 parents f4b784a + 5a0c6af commit d114e58
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 664 deletions.
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions public/locales/en/confirmationPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"sectionTitle": "Ingredients",
"nutrients": "Nutrients"
},
"notes": {
"sectionTitle": "Notes",
"placeholder": "Add a note"
},
"bilingualTable": {
"tableHeaders": {
"english": "English",
Expand All @@ -56,9 +60,8 @@
"confirmingButton": "Confirming",
"editButton": "Edit Details"
},
"expandRetractButton":{
"expandRetractButton": {
"expandButton": "Hide image and show only label information.",
"retractButton": "Show image and label information."
}

}
4 changes: 4 additions & 0 deletions public/locales/fr/confirmationPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"sectionTitle": "Ingrédients",
"nutrients": "Nutriments"
},
"notes": {
"sectionTitle": "Notes",
"placeholder": "Ajouter une note"
},
"bilingualTable": {
"tableHeaders": {
"english": "Anglais",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import { fireEvent, render, screen } from "@testing-library/react";
import axios from "axios";
import LabelDataConfirmationPage from "../page";
import { QuantityChips } from "@/components/QuantityChip";
import { Quantity } from "@/types/types";

const mockedRouterPush = jest.fn();
jest.mock("next/navigation", () => ({
Expand Down Expand Up @@ -205,3 +207,59 @@ describe("LabelDataConfirmationPage", () => {
expect(bilingualTableContainers.length).toBe(4);
});
});

describe("QuantityChips", () => {
it("renders valid quantities, filters out invalid values", () => {
const quantities: Quantity[] = [
{ value: "5", unit: "kg" },
{ value: "", unit: "g" },
{ value: "0", unit: "kg" },
];

render(<QuantityChips quantities={quantities} />);

expect(screen.getByText("5 kg")).toBeInTheDocument();
expect(screen.getByText("0 kg")).toBeInTheDocument();
expect(screen.queryByText("g")).not.toBeInTheDocument();
});
});

describe("Notes Section Tests", () => {
it("should render the notes section with a textbox", () => {
render(<LabelDataConfirmationPage />);
const notesSection = screen.getByTestId("notes-section");
const notesTextbox = screen.getByTestId("notes-textbox");
expect(notesSection).toBeInTheDocument();
expect(notesTextbox).toBeInTheDocument();
});

it("should update the comment value when text is entered", () => {
useLabelDataStore.getState().setLabelData(VERIFIED_LABEL_DATA);
expect(useLabelDataStore.getState().labelData?.comment).toBe("Compliant with regulations.");
render(<LabelDataConfirmationPage />);
const notesTextbox = screen
.getByTestId("notes-textbox")
.querySelector("textarea");
expect(notesTextbox).toBeInTheDocument();
fireEvent.change(notesTextbox!, { target: { value: "New note" } });
expect(useLabelDataStore.getState().labelData?.comment).toBe("New note");
expect(notesTextbox).toHaveValue("New note");
});

it("should toggle the notes textbox disabled state when the checkbox is clicked", () => {
render(<LabelDataConfirmationPage />);
const notesTextbox = screen
.getByTestId("notes-textbox")
.querySelector("textarea");
const checkboxInput = screen
.getByTestId("confirmation-checkbox")
.querySelector("input");
expect(notesTextbox).toBeInTheDocument();
expect(checkboxInput).toBeInTheDocument();
expect(notesTextbox).not.toBeDisabled();
fireEvent.click(checkboxInput!);
expect(notesTextbox).toBeDisabled();
fireEvent.click(checkboxInput!);
expect(notesTextbox).not.toBeDisabled();
});
});
Loading

0 comments on commit d114e58

Please sign in to comment.