import { render, screen } from '@testing-library/react';
import type { ReactNode } from 'react';
import { describe, expect, test, vi } from 'vitest';
import { TagCard } from './tag-card';
vi.mock('next/link', () => ({
default: ({
href,
children,
...props
}: {
href: string;
children: ReactNode;
}) => (
{children}
),
}));
describe('TagCard', () => {
test('renders a tag link with computed tag url', () => {
render();
const link = screen.getByRole('link', { name: /react/i });
expect(link).toHaveAttribute('href', '/tags/react');
});
test('renders count only when displayCount is true and count exists', () => {
const { rerender } = render();
expect(screen.getByText('(12)')).toBeInTheDocument();
rerender();
expect(screen.queryByText('(12)')).not.toBeInTheDocument();
});
});