/** * Тесты для TimelineProvider */ import { render, screen } from "@testing-library/react" import { describe, expect, it } from "vitest" import { TimelineProvider } from "../../services/timeline-provider" // Тестовый компонент для проверки провайдера const TestComponent = () => { return
Timeline Test Component
} describe("TimelineProvider", () => { describe("Provider Initialization", () => { it("should be defined and exportable", () => { expect(TimelineProvider).toBeDefined() expect(typeof TimelineProvider).toBe("function") }) it("should render without errors", () => { expect(() => { render( , ) }).not.toThrow() }) it("should render children components", () => { render( , ) expect(screen.getByTestId("timeline-test-component")).toBeInTheDocument() expect(screen.getByTestId("timeline-test-component")).toHaveTextContent("Timeline Test Component") }) }) describe("Provider Functionality", () => { it("should accept children prop", () => { const { getByTestId } = render(
Child Component
, ) expect(getByTestId("child-component")).toBeInTheDocument() }) it("should render multiple children", () => { render(
Child 1
Child 2
Child 3
, ) expect(screen.getByTestId("child-1")).toBeInTheDocument() expect(screen.getByTestId("child-2")).toBeInTheDocument() expect(screen.getByTestId("child-3")).toBeInTheDocument() }) }) describe("Provider Context", () => { it("should provide timeline context to children", () => { // Поскольку у нас есть глобальные моки, провайдер должен работать const { container } = render( , ) expect(container.firstChild).toBeInTheDocument() }) it("should handle nested providers", () => { expect(() => { render( , ) }).not.toThrow() }) }) describe("Error Handling", () => { it("should handle empty children", () => { expect(() => { render({null}) }).not.toThrow() }) it("should handle undefined children", () => { expect(() => { render({undefined}) }).not.toThrow() }) it("should handle false children", () => { expect(() => { render({false}) }).not.toThrow() }) }) describe("Provider Performance", () => { it("should render efficiently with many children", () => { const children = Array.from({ length: 100 }, (_, i) => (
Child {i}
)) expect(() => { render({children}) }).not.toThrow() // Проверяем, что первый и последний элементы отрендерились expect(screen.getByTestId("child-0")).toBeInTheDocument() expect(screen.getByTestId("child-99")).toBeInTheDocument() }) }) })