import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { Avatar } from '../../src/components/ui/Avatar';
import { IconButton } from '../../src/components/ui/IconButton';
import { Ring } from '../../src/components/ui/Ring';
import { SparkBars } from '../../src/components/ui/SparkBars';
import { SupplyBar } from '../../src/components/ui/SupplyBar';
import { Card, CardHeader, CardBody } from '../../src/components/ui/Card';
describe('Avatar', () => {
it('renders initial from name', () => {
render();
expect(screen.getByLabelText('Alice')).toBeInTheDocument();
expect(screen.getByText('A')).toBeInTheDocument();
});
it('uses custom size', () => {
render();
const el = screen.getByLabelText('Bob');
expect(el).toHaveStyle({ width: '48px', height: '48px' });
});
});
describe('IconButton', () => {
it('renders with label and icon', () => {
render();
expect(screen.getByLabelText('Settings')).toBeInTheDocument();
});
it('renders notification dot when dot=true', () => {
render();
// dot is a span inside the button
const btn = screen.getByLabelText('Notifications');
expect(btn.querySelectorAll('span').length).toBeGreaterThanOrEqual(1);
});
});
describe('Ring', () => {
it('renders value and total', () => {
render();
expect(screen.getByLabelText('5 of 10 doses taken')).toBeInTheDocument();
expect(screen.getByText('5')).toBeInTheDocument();
});
it('handles zero total', () => {
render();
expect(screen.getByText('0')).toBeInTheDocument();
});
});
describe('SparkBars', () => {
it('renders bars with labels', () => {
const data = [
{ label: 'Jan', amount: 100 },
{ label: 'Feb', amount: 200 },
];
render();
expect(screen.getByText('Jan')).toBeInTheDocument();
expect(screen.getByText('Feb')).toBeInTheDocument();
});
it('renders formatted amounts', () => {
const data = [{ label: 'Mar', amount: 5000 }];
render();
expect(screen.getByText('5k')).toBeInTheDocument();
});
});
describe('SupplyBar', () => {
it('renders days value', () => {
render();
expect(screen.getByText('30')).toBeInTheDocument();
expect(screen.getByText('d')).toBeInTheDocument();
});
it('renders for critical days', () => {
render();
expect(screen.getByText('5')).toBeInTheDocument();
});
it('renders for medium days', () => {
render();
expect(screen.getByText('10')).toBeInTheDocument();
});
});
describe('Card', () => {
it('renders children and applies custom styles', () => {
render(
Card Content
);
expect(screen.getByText('Card Content')).toBeInTheDocument();
});
it('renders header with title, subtitle and action', () => {
render(
Click Me}
/>
);
expect(screen.getByText('My Card')).toBeInTheDocument();
expect(screen.getByText('My Subtitle')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Click Me' })).toBeInTheDocument();
});
it('renders body with children', () => {
render(
Body Content
);
expect(screen.getByText('Body Content')).toBeInTheDocument();
});
});