1 import React from "react"
2 import { beforeEach, describe, expect, test, vi } from "vitest"
3 import { cleanup, render } from "@testing-library/react"
4
5 // mock components
6 vi.mock("@/components/Section/Divider", () => ({
7 default: () => <div data-testid="section-divider">Section Divider</div>,
8 }))
9 vi.mock("docs-ui", () => ({
10 WideSection: ({ children }: { children: React.ReactNode }) => (
11 <div data-testid="wide-section">{children}</div>
12 ),
13 }))
14
15 import SectionContainer from ".."
16
17 beforeEach(() => {
18 vi.clearAllMocks()
19 cleanup()
20 })
21
22 describe("rendering", () => {
23 test("renders section container with children", () => {
24 const { getByTestId } = render(<SectionContainer>Test</SectionContainer>)
25 const wideSectionElement = getByTestId("wide-section")
26 expect(wideSectionElement).toBeInTheDocument()
27 expect(wideSectionElement).toHaveTextContent("Test")
28 })
29 test("renders section container with no top padding", () => {
30 const { getByTestId } = render(<SectionContainer noTopPadding>Test</SectionContainer>)
31 const sectionContainerElement = getByTestId("section-container")
32 expect(sectionContainerElement).not.toHaveClass("pt-7")
33 })
34 test("renders section container with top padding", () => {
35 const { getByTestId } = render(<SectionContainer noTopPadding={false}>Test</SectionContainer>)
36 const sectionContainerElement = getByTestId("section-container")
37 expect(sectionContainerElement).toHaveClass("pt-7")
38 })
39 test("renders section container with divider", () => {
40 const { getByTestId } = render(<SectionContainer>Test</SectionContainer>)
41 const sectionDividerElement = getByTestId("section-divider")
42 expect(sectionDividerElement).toBeInTheDocument()
43 })
44 test("renders section container with no divider", () => {
45 const { container } = render(<SectionContainer noDivider>Test</SectionContainer>)
46 const sectionDividerElement = container.querySelectorAll("[data-testid='section-divider']")
47 expect(sectionDividerElement).toHaveLength(0)
48 })
49 test("renders section container with className", () => {
50 const { getByTestId } = render(<SectionContainer className="test-class">Test</SectionContainer>)
51 const sectionContainerElement = getByTestId("section-container")
52 expect(sectionContainerElement).toHaveClass("test-class")
53 })
54 test("renders section container with ref", () => {
55 const ref = vi.fn()
56 render(<SectionContainer ref={ref}>Test</SectionContainer>)
57 expect(ref).toHaveBeenCalled()
58 })
59 })