import { describe, expect, it, vi } from 'vitest'; import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MitreTechniqueTag, MitreTacticTag } from '@/components/MitreTechniqueTag'; import { renderWithProviders } from './utils'; import type { MitreTacticRef } from '@/api/types'; const TECHNIQUE = { id: 'T1059', name: 'Command and Scripting Interpreter', tactics: ['execution'] }; const TACTIC: MitreTacticRef = { id: 'TA0007', name: 'Discovery' }; describe('MitreTechniqueTag', () => { it('renders id and name in title attribute (AC-22.2)', () => { renderWithProviders( , ); expect(screen.getByText('T1059')).toBeInTheDocument(); // Name is in title= only, not as visible text expect(screen.getByTitle(/Command and Scripting Interpreter/)).toBeInTheDocument(); expect(screen.queryByText(/Command and Scripting Interpreter/)).toBeNull(); }); it('shows remove button when not disabled', () => { renderWithProviders( , ); expect(screen.getByRole('button', { name: /Remove T1059/i })).toBeInTheDocument(); }); it('clicking × calls onRemove', async () => { const onRemove = vi.fn(); const user = userEvent.setup(); renderWithProviders( , ); await user.click(screen.getByRole('button', { name: /Remove T1059/i })); expect(onRemove).toHaveBeenCalledOnce(); }); it('hides remove button when disabled', () => { renderWithProviders( , ); expect(screen.queryByRole('button', { name: /Remove/i })).toBeNull(); }); }); describe('MitreTacticTag', () => { it('renders tactic id with title containing name', () => { renderWithProviders( , ); expect(screen.getByText('TA0007')).toBeInTheDocument(); expect(screen.getByTitle(/Discovery/)).toBeInTheDocument(); }); it('shows remove button when not disabled', () => { renderWithProviders( , ); expect(screen.getByRole('button', { name: /Remove TA0007/i })).toBeInTheDocument(); }); it('clicking × calls onRemove', async () => { const onRemove = vi.fn(); const user = userEvent.setup(); renderWithProviders( , ); await user.click(screen.getByRole('button', { name: /Remove TA0007/i })); expect(onRemove).toHaveBeenCalledOnce(); }); it('hides remove button when disabled', () => { renderWithProviders( , ); expect(screen.queryByRole('button', { name: /Remove/i })).toBeNull(); }); });