import { renderWithProviders, screen } from '../../../test/render';
import { describe, it, expect } from 'vitest';
import { ActivityCard, type ActivityItem } from './ActivityCard';
import React from 'react';
const items: ActivityItem[] = [
{
id: '1',
user: { name: 'Ana Silva', initials: 'AS' },
action: 'atualizou',
target: 'Documento X',
time: '2h atrás',
type: 'update',
},
{
id: '2',
user: { name: 'Bruno Costa', initials: 'BC', avatar: 'https://example.com/avatar.png' },
action: 'criou',
target: 'Projeto Y',
time: '1d atrás',
type: 'create',
},
{
id: '3',
user: { name: 'Carla Dias', initials: 'CD' },
action: 'comentou em',
target: 'Tarefa Z',
time: '3h atrás',
},
];
describe('ActivityCard', () => {
it('renders the default title and every activity item', () => {
renderWithProviders();
expect(screen.getByText('Atividade Recente')).toBeInTheDocument();
expect(screen.getByText('Ana Silva')).toBeInTheDocument();
expect(screen.getByText('Bruno Costa')).toBeInTheDocument();
expect(screen.getByText('Carla Dias')).toBeInTheDocument();
expect(screen.getByText('Documento X')).toBeInTheDocument();
expect(screen.getByText('2h atrás')).toBeInTheDocument();
});
it('renders a translated badge label per activity type and omits it when type is absent', () => {
renderWithProviders();
expect(screen.getByText('Atualizado')).toBeInTheDocument();
expect(screen.getByText('Criado')).toBeInTheDocument();
// item 3 has no `type`, so no badge should render for it — total badges = 2
expect(screen.queryByText('Comentou')).not.toBeInTheDocument();
});
it('renders a custom title when provided instead of the i18n default', () => {
renderWithProviders();
expect(screen.getByText('Minhas Atividades')).toBeInTheDocument();
expect(screen.queryByText('Atividade Recente')).not.toBeInTheDocument();
});
it('limits the rendered items to maxItems', () => {
renderWithProviders();
expect(screen.getByText('Ana Silva')).toBeInTheDocument();
expect(screen.queryByText('Bruno Costa')).not.toBeInTheDocument();
expect(screen.queryByText('Carla Dias')).not.toBeInTheDocument();
});
it('renders the action node when provided', () => {
renderWithProviders(Ver tudo} />);
expect(screen.getByRole('button', { name: 'Ver tudo' })).toBeInTheDocument();
});
it('renders an avatar for the user with an avatar URL (falls back to initials in jsdom)', () => {
renderWithProviders();
// Radix Avatar never fires a load event in jsdom, so the fallback initials
// remain visible even when an avatar URL is provided.
expect(screen.getByText('BC')).toBeInTheDocument();
});
});