From 761f66fc5a44bd7a9e164a918f75dd67e013db04 Mon Sep 17 00:00:00 2001 From: "GitStart-Cal.com" <121884634+gitstart-calcom@users.noreply.github.com> Date: Fri, 18 Aug 2023 07:58:30 -0300 Subject: [PATCH] Create RTL tests for Meta component (#10478) Co-authored-by: gitstart-calcom Co-authored-by: Shivam Kalra Co-authored-by: Keith Williams --- packages/ui/components/meta/meta.test.tsx | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 packages/ui/components/meta/meta.test.tsx diff --git a/packages/ui/components/meta/meta.test.tsx b/packages/ui/components/meta/meta.test.tsx new file mode 100644 index 0000000000..6c9edaa83d --- /dev/null +++ b/packages/ui/components/meta/meta.test.tsx @@ -0,0 +1,54 @@ +import { render } from "@testing-library/react"; +import { vi } from "vitest"; + +import Meta, { useMeta } from "./Meta"; + +vi.mock("./Meta", async () => { + const actualMeta = (await vi.importActual("./Meta")) as object; + const MockMeta = ({ title, description }: { title: string; description: string }) => ( +
+

{title}

+

{description}

+
+ ); + + type MetaProviderProps = { + children: React.ReactNode; + }; + + return { + ...actualMeta, + default: MockMeta, + useMeta: vi.fn(), + MetaProvider: ({ children }: MetaProviderProps) => children, + }; +}); + +describe("Meta Component", () => { + test("Should render with default metadata", () => { + (useMeta as jest.Mock).mockReturnValue({ + meta: { title: "", description: "", backButton: false, CTA: null }, + }); + + const { getByText } = render(); + + expect(getByText("Page Title")).toBeInTheDocument(); + expect(getByText("Page Description")).toBeInTheDocument(); + }); + + test("Should update metadata when props change", () => { + (useMeta as jest.Mock).mockReturnValue({ + meta: { title: "", description: "", backButton: false, CTA: null }, + }); + + const { rerender, getByText } = render(); + + expect(getByText("Page Title")).toBeInTheDocument(); + expect(getByText("Page Description")).toBeInTheDocument(); + + rerender(); + + expect(getByText("New Title")).toBeInTheDocument(); + expect(getByText("New Description")).toBeInTheDocument(); + }); +});