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

feat(test)Unit test for RHF #1050

Merged
merged 8 commits into from
Jan 23, 2025
Merged
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
201 changes: 201 additions & 0 deletions mocks/data/forms/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { FormSchema } from "shared-types";
import { slots } from "./slots";

export const textForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.textForm],
},
],
},
{
title: "dependency",
sectionId: "dependencySection",
dependency: {
conditions: [{ name: "acceptTerms", type: "valueExists" }],
effect: { type: "show" },
},
form: [
{
description: "Set your preferences.",
slots: [
{
name: "notifications",
label: "Enable Notifications",
rhf: "Switch",
},
],
},
],
},
{
title: "dependency2",
sectionId: "dependencySection",
dependency: {
conditions: [{ name: "acceptTerms", type: "valueNotExist" }],
effect: { type: "hide" },
},
form: [
{
description: "Set your preferences.",
slots: [
{
name: "notifications",
label: "Enable Notifications",
rhf: "Switch",
},
],
},
],
},
],
};
export const textFromExpected: FormSchema = {
header: "Test header2",
formId: "testID2",
sections: [
{
title: "dependency",
sectionId: "dependencySection",
dependency: {
conditions: [
{
name: "firstName",
type: "expectedValue",
expectedValue: "yes",
},
],
effect: { type: "show" },
},
form: [
{
description: "Set your preferences.",
slots: [slots.textForm],
},
],
},
],
};
export const uploadForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.upload],
},
],
},
],
};
export const checkboxForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.checkbox],
},
],
},
],
};
export const radioForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.radio],
},
],
},
],
};
export const selectForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.selectField],
},
],
},
],
};
export const switchForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.switchField],
},
],
},
],
};
export const inputForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.inputBox],
},
],
},
],
};
export const fieldArrayForm: FormSchema = {
header: "Test header",
formId: "testID",
sections: [
{
title: "testForm",
sectionId: "testSection",
form: [
{
slots: [slots.fieldArrayParent],
},
],
},
],
};

export const mockForms = {
checkboxForm,
fieldArrayForm,
inputForm,
radioForm,
selectForm,
switchForm,
textForm,
textFromExpected,
uploadForm,
};
128 changes: 128 additions & 0 deletions mocks/data/forms/slots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { RHFSlotProps } from "shared-types";

const upload: RHFSlotProps = {
rhf: "Upload",
name: "test-upload",
label: "State plan amendment attachment",
labelClassName: "font-bold",
description: "Only required if not using the payment methodology in the approved state plan",
descriptionAbove: true,
props: { maxFiles: 3 },
};
const checkbox: RHFSlotProps = {
rhf: "Checkbox",
name: "test_checkbox",
rules: { required: "* Required" },
props: {
options: [
{
label: "test_label",
value: "test-value",
},
{
label: "test_label2",
value: "test-value2",
},
],
},
};
const radio: RHFSlotProps = {
rhf: "Radio",
name: "test_radio",
rules: {
required: "* Required",
},
props: {
options: [
{
label: "Households with income at or below the standard",
value: "1",
},
{
label: "Households with income above the standard",
value: "2",
},
],
},
};
const textForm: RHFSlotProps = {
name: "firstName",
label: "First Name",
rhf: "Textarea",
rules: { required: "First Name is required" },
};
const inputBox: RHFSlotProps = {
rhf: "Input",
name: "testNameInput",
label: "Test input value",

props: { placeholder: "enter name" },
};
const selectField: RHFSlotProps = {
rhf: "Select",
name: "test_select",
label: "test select",
labelClassName: "font-bold",
rules: { required: "* Required" },
props: {
className: "w-[150px]",
options: [
{ label: "Yes", value: "yes" },
{
label: "No",
value: "no",
},
],
},
};
const switchField: RHFSlotProps = {
name: "notifications",
label: "Enable Notifications",
rhf: "Switch",
};
const fieldArray: RHFSlotProps = {
rhf: "FieldArray",
name: "field-array",
label: `field_label`,
labelClassName: "font-bold",
props: {
appendText: "Add benefit or service",
removeText: "Remove",
},
fields: [
{
rhf: "WrappedGroup",
name: "wrapped_fields",

fields: [textForm, inputBox],
},
],
};
const fieldArrayParent: RHFSlotProps = {
rhf: "FieldArray",
name: "field-array-parent",
label: `field_label`,
labelClassName: "font-bold",
props: {
appendText: "Add benefit or service",
removeText: "Remove",
},
fields: [
{
rhf: "FieldArray",
name: "wrapped_fields",
fields: [fieldArray],
},
],
};
export const slots = {
checkbox,
fieldArray,
fieldArrayParent,
inputBox,
radio,
selectField,
switchField,
textForm,
upload,
};
Loading
Loading