import React from 'react';
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { PixelAlert } from '../../feedback/PixelAlert';
describe('PixelAlert — rendering', () => {
it('renders role="alert" with label + message', () => {
render();
const alert = screen.getByRole('alert');
expect(alert.textContent).toContain('Error');
expect(alert.textContent).toContain('Something exploded.');
});
it('supports the deprecated title alias as the label', () => {
render();
expect(screen.getByRole('alert').textContent).toContain('Legacy title');
});
it('label wins over title when both are passed', () => {
render();
const alert = screen.getByRole('alert');
expect(alert.textContent).toContain('Canonical');
expect(alert.textContent).not.toContain('Old');
});
it('renders icon and action slots', () => {
render(
}
action={}
/>,
);
expect(screen.getByTestId('ico')).toBeInTheDocument();
expect(screen.getByTestId('cta')).toBeInTheDocument();
});
});
describe('PixelAlert — tone', () => {
it('defaults to tone="red" (border + soft bg)', () => {
render();
const alert = screen.getByRole('alert');
expect(alert.className).toContain('border-retro-red/40');
expect(alert.className).toContain('bg-retro-red/8');
});
it('tone="cyan" swaps tone classes', () => {
render();
const alert = screen.getByRole('alert');
expect(alert.className).toContain('border-retro-cyan/40');
expect(alert.className).not.toContain('border-retro-red/40');
});
});
describe('PixelAlert — aria-live policy', () => {
it('critical tones (red/gold) default to assertive', () => {
render();
expect(screen.getByRole('alert').getAttribute('aria-live')).toBe('assertive');
});
it('non-critical tones default to polite', () => {
render();
expect(screen.getByRole('alert').getAttribute('aria-live')).toBe('polite');
});
it('explicit live prop overrides the tone default', () => {
render();
expect(screen.getByRole('alert').getAttribute('aria-live')).toBe('off');
});
});
describe('PixelAlert — surface', () => {
it('pixel surface (default) renders the left accent stripe + pl-4', () => {
render();
const alert = screen.getByRole('alert');
expect(alert.className).toContain('pl-4');
const stripe = alert.querySelector('span[aria-hidden]') as HTMLElement;
expect(stripe).not.toBeNull();
expect(stripe.className).toContain('w-1');
expect(stripe.className).toContain('bg-retro-red');
});
it('linear surface drops the accent stripe', () => {
render();
const alert = screen.getByRole('alert');
expect(alert.className).not.toContain('pl-4');
expect(alert.querySelector('span[aria-hidden].w-1')).toBeNull();
});
});