xtablo-source/apps/main/src/components/CustomModal.test.tsx

111 lines
3.2 KiB
TypeScript
Raw Normal View History

2025-10-27 08:13:25 +00:00
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { CustomModal } from "./CustomModal";
describe("CustomModal", () => {
const mockOnClose = vi.fn();
beforeEach(() => {
vi.clearAllMocks();
});
it("renders without crashing when open", () => {
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
it("does not render when closed", () => {
render(
<CustomModal isOpen={false} onClose={mockOnClose} title="Test Modal">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.queryByText("Test Modal")).not.toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
it("displays the title", () => {
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal Title">
<div>Test Content</div>
</CustomModal>
);
expect(screen.getByText("Test Modal Title")).toBeInTheDocument();
});
it("renders children content", () => {
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal">
<div>Custom Modal Content</div>
</CustomModal>
);
expect(screen.getByText("Custom Modal Content")).toBeInTheDocument();
});
2025-10-28 21:23:50 +00:00
it("applies sm width prop", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal" width="sm">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
2025-10-28 21:23:50 +00:00
it("renders with md width by default", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
2025-10-28 21:23:50 +00:00
it("applies lg width prop", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal" width="lg">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
2025-10-28 21:23:50 +00:00
it("applies xl width prop", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal" width="xl">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
2025-10-28 21:23:50 +00:00
it("applies 2xl width prop", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal" width="2xl">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
2025-10-28 21:23:50 +00:00
it("applies full width prop", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal" width="full">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
2025-10-28 21:23:50 +00:00
it("applies auto width prop", () => {
2025-10-27 08:13:25 +00:00
render(
<CustomModal isOpen={true} onClose={mockOnClose} title="Test Modal" width="auto">
<div>Test Content</div>
</CustomModal>
);
2025-10-28 21:23:50 +00:00
expect(screen.getByText("Test Modal")).toBeInTheDocument();
2025-10-27 08:13:25 +00:00
});
});