From 17fcc2c21341fa95ef235c49cb41cbb30d0721db Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Wed, 19 Feb 2025 13:50:26 +0530 Subject: [PATCH] fix: Test preview - Routing forms crash for regular teams(that are not sub-teams) (#19353) --- .../insights/insights-virtual-queues-view.tsx | 6 +- .../__tests__/TestFormDialog.test.tsx | 77 ++++++++++++++++--- .../routing-forms/components/SingleForm.tsx | 10 ++- ...rsMatchingAttributeLogicOfRoute.handler.ts | 3 +- 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/apps/web/modules/insights/insights-virtual-queues-view.tsx b/apps/web/modules/insights/insights-virtual-queues-view.tsx index a07b198406..14e3bdab55 100644 --- a/apps/web/modules/insights/insights-virtual-queues-view.tsx +++ b/apps/web/modules/insights/insights-virtual-queues-view.tsx @@ -38,7 +38,11 @@ export default function InsightsVirtualQueuesPage() { value={selectedForm ? { label: selectedForm.name, value: selectedForm.id } : undefined} />
- {selectedForm ? : <>} + {selectedForm ? ( + + ) : ( + <> + )}
); diff --git a/packages/app-store/routing-forms/__tests__/TestFormDialog.test.tsx b/packages/app-store/routing-forms/__tests__/TestFormDialog.test.tsx index 30a2ff3738..3ef1e1975e 100644 --- a/packages/app-store/routing-forms/__tests__/TestFormDialog.test.tsx +++ b/packages/app-store/routing-forms/__tests__/TestFormDialog.test.tsx @@ -112,7 +112,7 @@ vi.mock("@calcom/trpc/react", () => ({ }, })); -const mockTeamForm = { +const mockSubTeamForm = { id: "routing-form-id", teamId: "test-team-id", name: "Test Form", @@ -152,6 +152,16 @@ const mockTeamForm = { }, }, ], + team: { + parentId: "org-1", + }, +} as any; + +const mockRegularTeamForm = { + ...mockSubTeamForm, + team: { + parentId: null, + }, } as any; describe("TestFormDialog", () => { @@ -163,7 +173,7 @@ describe("TestFormDialog", () => { it("renders the dialog when open", () => { render( { return; @@ -178,7 +188,7 @@ describe("TestFormDialog", () => { it("doesn't render the dialog when closed", () => { render( { return; @@ -192,7 +202,7 @@ describe("TestFormDialog", () => { it("renders form fields", () => { render( { return; @@ -203,12 +213,13 @@ describe("TestFormDialog", () => { expect(screen.getByTestId("form-field-name")).toBeInTheDocument(); }); - describe("Team Form", () => { + describe("Sub-Team Form", () => { + const form = mockSubTeamForm; it("submits the form and shows test results for Custom Page", async () => { mockCustomPageMessageMatchingRoute(); render( { return; @@ -227,7 +238,7 @@ describe("TestFormDialog", () => { mockEventTypeRedirectUrlMatchingRoute(); render( { return; @@ -257,7 +268,7 @@ describe("TestFormDialog", () => { }); render( { return; @@ -287,7 +298,7 @@ describe("TestFormDialog", () => { }); render( { return; @@ -313,7 +324,7 @@ describe("TestFormDialog", () => { }); render( { return; @@ -339,7 +350,7 @@ describe("TestFormDialog", () => { }); render( { return; @@ -356,11 +367,53 @@ describe("TestFormDialog", () => { }); }); + describe("Regular Team Form", () => { + const form = mockRegularTeamForm; + it("submits the form and shows test results for Custom Page", async () => { + mockCustomPageMessageMatchingRoute(); + render( + { + return; + }} + /> + ); + fireEvent.change(screen.getByTestId("form-field-name"), { target: { value: "John Doe" } }); + fireEvent.click(screen.getByText("test_routing")); + + expect(screen.getByText("route_to:")).toBeInTheDocument(); + expect(screen.getByTestId("test-routing-result-type")).toHaveTextContent("Custom Page"); + expect(screen.getByTestId("test-routing-result")).toHaveTextContent("Thank you for submitting!"); + }); + + it("submits the form and shows test results for Event Type", async () => { + mockEventTypeRedirectUrlMatchingRoute(); + render( + { + return; + }} + /> + ); + fireEvent.change(screen.getByTestId("form-field-name"), { target: { value: "John Doe" } }); + fireEvent.click(screen.getByText("test_routing")); + expect(screen.getByText("route_to:")).toBeInTheDocument(); + expect(screen.getByTestId("test-routing-result-type")).toHaveTextContent("Event Redirect"); + expect(screen.getByTestId("test-routing-result")).toHaveTextContent("john/30min"); + // When we support showing matching route we can add this back + // expect(screen.getByTestId("chosen-route")).toHaveTextContent("Route 2"); + }); + }); + it("closes the dialog when close button is clicked", () => { const setIsTestPreviewOpen = vi.fn(); render( diff --git a/packages/app-store/routing-forms/components/SingleForm.tsx b/packages/app-store/routing-forms/components/SingleForm.tsx index ecace2653f..5042091bfe 100644 --- a/packages/app-store/routing-forms/components/SingleForm.tsx +++ b/packages/app-store/routing-forms/components/SingleForm.tsx @@ -443,10 +443,12 @@ type UptoDateForm = Brand< export const TestForm = ({ form, + supportsTeamMembersMatchingLogic, showAllData = true, renderFooter, }: { form: UptoDateForm | RoutingForm; + supportsTeamMembersMatchingLogic: boolean; showAllData?: boolean; renderFooter?: (onClose: () => void) => React.ReactNode; }) => { @@ -455,7 +457,6 @@ export const TestForm = ({ const [chosenRoute, setChosenRoute] = useState(null); const [eventTypeUrlWithoutParams, setEventTypeUrlWithoutParams] = useState(""); const searchParams = useCompatSearchParams(); - const isTeamForm = !!form.teamId; const [membersMatchResult, setMembersMatchResult] = useState(null); const resetMembersMatchResult = () => { @@ -504,7 +505,7 @@ export const TestForm = ({ if (!route) return; - if (isTeamForm) { + if (supportsTeamMembersMatchingLogic) { findTeamMembersMatchingAttributeLogicMutation.mutate({ formId: form.id, response, @@ -528,7 +529,7 @@ export const TestForm = ({ }; const renderTeamMembersMatchResult = (showAllData: boolean, isPending: boolean) => { - if (!isTeamForm) return null; + if (!supportsTeamMembersMatchingLogic) return null; if (isPending) return
Loading...
; return ( @@ -649,7 +650,7 @@ export const TestFormDialog = ({ setIsTestPreviewOpen: (value: boolean) => void; }) => { const { t } = useLocale(); - + const isSubTeamForm = !!form.team?.parentId; return ( @@ -657,6 +658,7 @@ export const TestFormDialog = ({
(