Skip to content

Scheduling infrastructure for absolutely everyone.

Create RTL tests for Meta component (#10478)

GitStart-Cal.com761f66fc5a44
diff --git a/packages/ui/components/meta/meta.test.tsx b/packages/ui/components/meta/meta.test.tsx
new file mode 100644
index 00000000000..6c9edaa83df
--- /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 }) => (
+ <div>
+ <h1>{title}</h1>
+ <p>{description}</p>
+ </div>
+ );
+
+ 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(<Meta title="Page Title" description="Page Description" />);
+
+ 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(<Meta title="Page Title" description="Page Description" />);
+
+ expect(getByText("Page Title")).toBeInTheDocument();
+ expect(getByText("Page Description")).toBeInTheDocument();
+
+ rerender(<Meta title="New Title" description="New Description" />);
+
+ expect(getByText("New Title")).toBeInTheDocument();
+ expect(getByText("New Description")).toBeInTheDocument();
+ });
+});