Skip to content

Commit

Permalink
Update depedencyWrapper.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
jdinh8124 committed Jul 30, 2024
1 parent 3c1d565 commit 23a4389
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions react-app/src/components/RHF/tests/depedencyWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render } from "@testing-library/react";
import { useForm, FormProvider } from "react-hook-form";
import { DependencyWrapper } from "../dependencyWrapper";
import { PropsWithChildren } from "react";
import { DependencyRule } from "shared-types"; // Adjust the import path as needed
import { DependencyRule } from "shared-types";

const TestComp = ({
name,
Expand Down Expand Up @@ -89,18 +89,43 @@ describe("DependencyWrapper Tests", () => {
],
effect: { type: "setValue", fieldName: "field2", newValue: "newValue" },
};
const { getByRole } = render(
<TestComp

let methods: any;

const TestCompWithMethods = (
props: PropsWithChildren<{
name: string;
dependency: DependencyRule;
parentValue: string[];
changeMethod: (values: string[]) => void;
}>,
) => {
methods = useForm({
defaultValues: {
[props.name]: props.parentValue,
field1: "test",
field2: "",
},
});

return (
<FormProvider {...methods}>
<DependencyWrapper {...props}>{props.children}</DependencyWrapper>
</FormProvider>
);
};

render(
<TestCompWithMethods
name="testField"
dependency={dependency}
parentValue={["testField"]}
changeMethod={() => {}}

Check failure on line 123 in react-app/src/components/RHF/tests/depedencyWrapper.test.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected empty arrow function
>
<div>Child Component</div>
</TestComp>,
</TestCompWithMethods>,
);

const input = getByRole("textbox", { name: /field2/i }) as HTMLInputElement;
expect(input.value).toBe("newValue");
expect(methods.getValues("field2")).toBe("newValue");
});
});

0 comments on commit 23a4389

Please sign in to comment.