import React from "react";
import { Text } from "./index";

import { render, screen } from "@testing-library/react";

// Mock dependencies
jest.mock("@shared/components/text", () => ({
  Text: ({ children }: { children: React.ReactNode }) => (
    <span data-testid="text-component">{children}</span>
  ),
}));

describe("Text (Contentful Block)", () => {
  describe("Rendering", () => {
    it("renders the Text Block placeholder text", () => {
      render(<Text fields={{}} />);
      expect(screen.getByText("Text Block")).toBeInTheDocument();
    });

    it("renders inside a div wrapper", () => {
      const { container } = render(<Text fields={{}} />);
      expect(container.firstChild?.nodeName).toBe("DIV");
    });

    it("uses the shared TextComponent", () => {
      render(<Text fields={{}} />);
      expect(screen.getByTestId("text-component")).toBeInTheDocument();
    });

    it("renders consistently with empty fields object", () => {
      const { container: first } = render(<Text fields={{}} />);
      const { container: second } = render(<Text fields={{}} />);
      expect(first.innerHTML).toBe(second.innerHTML);
    });
  });
});
