"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("@testing-library/react");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
const Card_1 = __importDefault(require("./Card"));
const BFUIProvider_1 = require("../../BFUIProvider");
// Wrap component with BFUIProvider for Chakra UI theme context
const renderWithProvider = (ui) => {
    return (0, react_1.render)((0, jsx_runtime_1.jsx)(BFUIProvider_1.BFUIProvider, { children: ui }));
};
describe('Card Component', () => {
    test('renders with minimal props and children', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", children: (0, jsx_runtime_1.jsx)("div", { children: "Test Content" }) }));
        const cardElement = react_1.screen.getByText('Test Content');
        expect(cardElement).toBeInTheDocument();
    });
    test('renders with title', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", title: "Card Title", children: "Card Content" }));
        const title = react_1.screen.getByText('Card Title');
        expect(title).toBeInTheDocument();
        expect(title.tagName).toBe('H3');
    });
    test('renders with image', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", title: "Card Title", image: "https://example.com/image.jpg", children: "Card Content" }));
        const image = react_1.screen.getByAltText('Card Title');
        expect(image).toBeInTheDocument();
        expect(image.tagName).toBe('IMG');
        expect(image).toHaveAttribute('src', 'https://example.com/image.jpg');
    });
    test('renders with footer', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", title: "Card Title", footer: (0, jsx_runtime_1.jsx)("button", { children: "Action" }), children: "Card Content" }));
        const footer = react_1.screen.getByText('Action');
        expect(footer).toBeInTheDocument();
        expect(footer.tagName).toBe('BUTTON');
    });
    test('handles click events when clickable', async () => {
        const handleClick = jest.fn();
        const user = user_event_1.default.setup();
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", clickable: true, onClick: handleClick, children: "Clickable Card" }));
        const card = react_1.screen.getByText('Clickable Card').closest('div');
        expect(card).toHaveAttribute('cursor', 'pointer');
        await user.click(card);
        expect(handleClick).toHaveBeenCalledTimes(1);
    });
    test('renders with URL as anchor tag', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", url: "https://example.com", children: "Link Card" }));
        const card = react_1.screen.getByText('Link Card').closest('a');
        expect(card).toHaveAttribute('href', 'https://example.com');
    });
    test('applies variant styles', () => {
        const { rerender } = renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card-default", variant: "default", children: "Default Card" }));
        const defaultCard = react_1.screen.getByText('Default Card').closest('div');
        expect(defaultCard).toBeInTheDocument();
        rerender((0, jsx_runtime_1.jsx)(BFUIProvider_1.BFUIProvider, { children: (0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card-elevated", variant: "elevated", children: "Elevated Card" }) }));
        const elevatedCard = react_1.screen.getByText('Elevated Card').closest('div');
        expect(elevatedCard).toBeInTheDocument();
    });
    test('renders with different sizes', () => {
        const { rerender } = renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card-small", size: "small", children: "Small Card" }));
        const smallCard = react_1.screen.getByText('Small Card').closest('div');
        expect(smallCard).toBeInTheDocument();
        rerender((0, jsx_runtime_1.jsx)(BFUIProvider_1.BFUIProvider, { children: (0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card-large", size: "large", children: "Large Card" }) }));
        const largeCard = react_1.screen.getByText('Large Card').closest('div');
        expect(largeCard).toBeInTheDocument();
    });
    test('applies additional class names', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", className: "custom-class", children: "Custom Class Card" }));
        const card = react_1.screen.getByText('Custom Class Card').closest('div');
        expect(card).toHaveClass('custom-class');
    });
    test('renders with custom ID', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "custom-id", children: "Custom ID Card" }));
        const card = react_1.screen.getByText('Custom ID Card').closest('div');
        expect(card).toHaveAttribute('id', 'custom-id');
    });
    test('renders children as content', () => {
        renderWithProvider((0, jsx_runtime_1.jsx)(Card_1.default, { id: "test-card", children: (0, jsx_runtime_1.jsx)("div", { "data-testid": "child-element", children: (0, jsx_runtime_1.jsx)("span", { children: "Nested Content" }) }) }));
        const childElement = react_1.screen.getByTestId('child-element');
        expect(childElement).toBeInTheDocument();
        expect(react_1.screen.getByText('Nested Content')).toBeInTheDocument();
    });
});
//# sourceMappingURL=Card.test.js.map