import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import ToolCard from '../ToolCard';
import AccessTimeIcon from '@mui/icons-material/AccessTime';
describe('ToolCard Component', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('Rendering', () => {
it('should render with title and description', () => {
render(
}
onClick={() => {}}
/>
);
expect(screen.getByText('Test Tool')).toBeInTheDocument();
expect(screen.getByText('This is a test tool')).toBeInTheDocument();
});
it('should render with only title when no description', () => {
render(
}
onClick={() => {}}
/>
);
expect(screen.getByText('Title Only')).toBeInTheDocument();
});
it('should render icon', () => {
render(
}
onClick={() => {}}
/>
);
expect(screen.getByTestId('test-icon')).toBeInTheDocument();
});
it('should render snapshot content when provided', () => {
render(
}
onClick={() => {}}
snapshot={
Snapshot Content
}
/>
);
expect(screen.getByTestId('snapshot')).toBeInTheDocument();
});
it('should not render snapshot section when not provided', () => {
const { container } = render(
}
onClick={() => {}}
/>
);
expect(container.querySelector('[data-testid="snapshot"]')).not.toBeInTheDocument();
});
});
describe('AI Badge', () => {
it('should render AI badge when hasAI is true', () => {
render(
}
onClick={() => {}}
/>
);
const autoAwesomeIcon = screen.getByTestId('AutoAwesomeIcon');
expect(autoAwesomeIcon).toBeInTheDocument();
});
it('should not render AI badge when hasAI is false', () => {
render(
}
onClick={() => {}}
/>
);
const autoAwesomeIcon = screen.queryByTestId('AutoAwesomeIcon');
expect(autoAwesomeIcon).not.toBeInTheDocument();
});
});
describe('Interaction', () => {
it('should call onClick when clicked', () => {
const handleClick = vi.fn();
render(
}
onClick={handleClick}
/>
);
const card = screen.getByText('Clickable').closest('.MuiBox-root');
if (card) {
fireEvent.click(card);
}
expect(handleClick).toHaveBeenCalledTimes(1);
});
});
describe('Styling', () => {
it('should apply custom color code', () => {
const customColor = '#ff5722';
const { container } = render(
}
onClick={() => {}}
/>
);
const iconContainer = container.querySelector('.MuiBox-root > div');
expect(iconContainer).toBeInTheDocument();
});
});
});