Skip to content

Commit

Permalink
issue #326: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-allagbe committed Nov 26, 2024
1 parent e570602 commit e38f095
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 18 deletions.
38 changes: 35 additions & 3 deletions src/app/label-data-validation/__tests__/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ 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 />);

Expand All @@ -91,9 +91,7 @@ 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 />);

Expand Down Expand Up @@ -129,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");
});
});
11 changes: 2 additions & 9 deletions src/components/__tests__/BaseInformationForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_BASE_INFORMATION, LabelData } from "@/types/types";
import { DEFAULT_LABEL_DATA, LabelData } from "@/types/types";
import { render, screen } from "@testing-library/react";
import { useEffect, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
Expand Down Expand Up @@ -31,14 +31,7 @@ const Wrapper = ({

describe("BaseInformationForm Rendering", () => {
it("should render all fields with correct components", () => {
render(
<Wrapper
initialData={{
organizations: [],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
/>,
);
render(<Wrapper initialData={DEFAULT_LABEL_DATA} />);

const verifiedFields = ["name", "registrationNumber", "lotNumber", "npk"];
const quantityFields = ["weight", "density", "volume"];
Expand Down
39 changes: 39 additions & 0 deletions src/components/__tests__/CautionsForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { DEFAULT_LABEL_DATA } from "@/types/types";
import { render, screen } from "@testing-library/react";
import { useEffect, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import CautionsForm from "../CautionsForm";

const Wrapper = ({
initialData,
onStateChange,
}: {
initialData: any;
onStateChange?: (data: any) => void;
}) => {
const [labelData, setLabelData] = useState(initialData);
const methods = useForm({
defaultValues: labelData,
});

useEffect(() => {
if (onStateChange) {
onStateChange(labelData);
}
}, [labelData, onStateChange]);

return (
<FormProvider {...methods}>
<CautionsForm labelData={labelData} setLabelData={setLabelData} />
</FormProvider>
);
};

describe("CautionsForm Rendering", () => {
it("should render the VerifiedBilingualTable for cautions", () => {
render(<Wrapper initialData={DEFAULT_LABEL_DATA} />);

expect(screen.getByTestId("cautions-form")).toBeInTheDocument();
expect(screen.getByTestId("table-container-cautions")).toBeInTheDocument();
});
});
13 changes: 7 additions & 6 deletions src/components/__tests__/OrganizationsForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("OrganizationsForm Rendering", () => {
initialData={{
organizations: [DEFAULT_ORGANIZATION, DEFAULT_ORGANIZATION],
baseInformation: DEFAULT_BASE_INFORMATION,
cautions: [],
}}
/>,
);
Expand All @@ -67,8 +68,8 @@ describe("OrganizationsForm Rendering", () => {
render(
<Wrapper
initialData={{
...DEFAULT_LABEL_DATA,
organizations: [],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
/>,
);
Expand All @@ -84,8 +85,8 @@ describe("OrganizationsForm Functionality", () => {
render(
<Wrapper
initialData={{
...DEFAULT_LABEL_DATA,
organizations: [],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
/>,
);
Expand Down Expand Up @@ -226,8 +227,8 @@ describe("OrganizationsForm Functionality", () => {
render(
<Wrapper
initialData={{
...DEFAULT_LABEL_DATA,
organizations: [verifiedOrg],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
/>,
);
Expand Down Expand Up @@ -261,8 +262,8 @@ describe("OrganizationsForm Functionality", () => {
render(
<Wrapper
initialData={{
...DEFAULT_LABEL_DATA,
organizations: [partiallyVerifiedOrg],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
onStateChange={mockStateChange}
/>,
Expand Down Expand Up @@ -319,8 +320,8 @@ describe("OrganizationsForm Functionality", () => {
render(
<Wrapper
initialData={{
...DEFAULT_LABEL_DATA,
organizations: [allUnverifiedOrg],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
/>,
);
Expand All @@ -335,8 +336,8 @@ describe("OrganizationsForm Edge Cases", () => {
render(
<Wrapper
initialData={{
...DEFAULT_LABEL_DATA,
organizations: [],
baseInformation: DEFAULT_BASE_INFORMATION,
}}
/>,
);
Expand Down
Loading

0 comments on commit e38f095

Please sign in to comment.