-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FormBuilderField and BookingFields tests
- Loading branch information
1 parent
455fdd2
commit 7901b2e
Showing
12 changed files
with
163 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/features/bookings/Booker/components/BookEventForm/BookingFields.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { TooltipProvider } from "@radix-ui/react-tooltip"; | ||
import { render, screen } from "@testing-library/react"; | ||
import * as React from "react"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
|
||
import { getBookingFieldsWithSystemFields } from "../../../lib/getBookingFields"; | ||
import { BookingFields } from "./BookingFields"; | ||
|
||
const renderComponent = ({ | ||
props: props, | ||
formDefaultValues, | ||
}: { | ||
props: Parameters<typeof BookingFields>[0]; | ||
formDefaultValues?: any; | ||
}) => { | ||
const Wrapper = ({ children }: { children: React.ReactNode }) => { | ||
const form = useForm({ | ||
defaultValues: formDefaultValues, | ||
}); | ||
return ( | ||
<TooltipProvider> | ||
<FormProvider {...form}>{children}</FormProvider> | ||
</TooltipProvider> | ||
); | ||
}; | ||
return render(<BookingFields {...props} />, { wrapper: Wrapper }); | ||
}; | ||
|
||
describe("FormBuilderField", () => { | ||
it("basic test", () => { | ||
renderComponent({ | ||
props: { | ||
fields: getBookingFieldsWithSystemFields({ | ||
disableGuests: false, | ||
bookingFields: [], | ||
metadata: null, | ||
workflows: [], | ||
customInputs: [], | ||
}), | ||
locations: [ | ||
{ | ||
type: "phone", | ||
}, | ||
{ | ||
link: "https://google.com", | ||
type: "link", | ||
displayLocationPublicly: true, | ||
}, | ||
], | ||
isDynamicGroupBooking: false, | ||
bookingData: null, | ||
}, | ||
formDefaultValues: {}, | ||
}); | ||
screen.getByText("email_address"); | ||
screen.logTestingPlaygroundURL(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { render } from "@testing-library/react"; | ||
import * as React from "react"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
import { vi } from "vitest"; | ||
|
||
import { FormBuilderField } from "./FormBuilderField"; | ||
import { getLocationBookingField } from "./testUtils"; | ||
|
||
vi.mock("@formkit/auto-animate/react", () => ({ | ||
useAutoAnimate: () => [null], | ||
})); | ||
|
||
const renderComponent = ({ | ||
props: props, | ||
formDefaultValues, | ||
}: { | ||
props: Parameters<typeof FormBuilderField>[0]; | ||
formDefaultValues?: any; | ||
}) => { | ||
const Wrapper = ({ children }: { children: React.ReactNode }) => { | ||
const form = useForm({ | ||
defaultValues: formDefaultValues, | ||
}); | ||
return <FormProvider {...form}>{children}</FormProvider>; | ||
}; | ||
return render(<FormBuilderField {...props} />, { wrapper: Wrapper }); | ||
}; | ||
|
||
describe("FormBuilderField", () => { | ||
it("basic test", () => { | ||
renderComponent({ | ||
props: { | ||
field: getLocationBookingField(), | ||
readOnly: false, | ||
className: "", | ||
}, | ||
formDefaultValues: {}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters