Files
calendar/packages/ui/components/all-questions/tests/allQuestions.test.tsx
T
4ebd52c9af test: Create unit tests for the questions (teste2e-multiSelectQuestion) (#11569)
* Remove unnecessary changes

* add changes

* Requested changes

* Requested changes

* FIx failing tests

* FIx failing tests

* Update regularBookings.ts

* FIx failing tests

* Refactor

* add unit tests for all questions

---------

Co-authored-by: gitstart-calcom <gitstart-calcom@users.noreply.github.com>
Co-authored-by: GitStart-Cal.com <121884634+gitstart-calcom@users.noreply.github.com>
Co-authored-by: gitstart-calcom <gitstart@users.noreply.github.com>
Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
2024-02-08 15:00:19 -03:00

77 lines
2.3 KiB
TypeScript

import { TooltipProvider } from "@radix-ui/react-tooltip";
import { render } from "@testing-library/react";
import type { ReactNode } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { vi } from "vitest";
import { FormBuilder } from "@calcom/features/form-builder/FormBuilder";
import { mockProps, questionUtils, setMockIntersectionObserver, setMockMatchMedia } from "./utils";
vi.mock("@formkit/auto-animate/react", () => ({
useAutoAnimate: () => [null],
}));
const renderComponent = () => {
const Wrapper = ({ children }: { children: ReactNode }) => {
const methods = useForm();
return (
<TooltipProvider>
<FormProvider {...methods}>{children}</FormProvider>
</TooltipProvider>
);
};
return render(<FormBuilder {...mockProps} />, { wrapper: Wrapper });
};
describe("MultiSelect Question", () => {
beforeEach(() => {
renderComponent();
});
beforeAll(() => {
setMockMatchMedia();
setMockIntersectionObserver();
});
const questionTypes = [
{ questionType: "email", label: "Email Field" },
{ questionType: "phone", label: "Phone Field" },
{ questionType: "address", label: "Address Field" },
{ questionType: "text", label: "Short Text Field" },
{ questionType: "number", label: "Number Field" },
{ questionType: "textarea", label: "LongText Field" },
{ questionType: "select", label: "Select Field" },
{ questionType: "multiselect", label: "MultiSelect Field" },
{ questionType: "multiemail", label: "Multiple Emails Field" },
{ questionType: "checkbox", label: "CheckBox Group Field" },
{ questionType: "radio", label: "Radio Group Field" },
{ questionType: "boolean", label: "Checkbox Field" },
];
for (const { questionType, label } of questionTypes) {
it(`Should handle ${label}`, async () => {
const defaultIdentifier = `${questionType}-id`;
const newIdentifier = `${defaultIdentifier}-edited`;
await questionUtils.addQuestion({
questionType,
identifier: defaultIdentifier,
label,
});
await questionUtils.editQuestion({
identifier: newIdentifier,
existingQuestionId: defaultIdentifier,
});
await questionUtils.requiredAndOptionalQuestion();
await questionUtils.hideQuestion();
await questionUtils.deleteQuestion(newIdentifier);
});
}
});