/** @vitest-environment jsdom */
import { act, cleanup, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { en } from '../i18n/en';
import { it as itTranslations } from '../i18n/it';
import { barProgress, STATUS_SCHEDULE_SECONDS } from '../processingProgress';
import { ProcessingView } from './ProcessingView';
afterEach(() => {
cleanup();
vi.useRealTimers();
});
describe.each([
['en', en, 'Finishing your result', '26.0s'],
['it', itTranslations, 'Finalizzazione del risultato', '26,0s'],
] as const)('ProcessingView (%s)', (_locale, t, finalStatus, elapsed) => {
it('reaches and holds a neutral last step with live announcements and continuing progress', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));
const { container, unmount } = render(
,
);
const avatar = container.querySelector('img');
expect(avatar?.getAttribute('alt')).toBe('');
expect(avatar?.className).toContain('ph-no-capture');
expect(avatar?.getAttribute('aria-hidden')).toBe('true');
let previousSeconds = 0;
for (const seconds of STATUS_SCHEDULE_SECONDS.slice(0, -1)) {
act(() => vi.advanceTimersByTime((seconds - previousSeconds) * 1000));
expect(container.textContent).not.toMatch(/Ti sta benissimo|You look good|Looking great on you/);
expect(container.querySelector('.aisthetix-status')?.getAttribute('aria-live')).toBe('polite');
previousSeconds = seconds;
}
act(() => vi.advanceTimersByTime(25_900 - previousSeconds * 1000));
expect(screen.queryByText(finalStatus)).toBeNull();
act(() => vi.advanceTimersByTime(100));
expect(screen.getByText(finalStatus).getAttribute('aria-live')).toBe('polite');
expect(screen.getByText(elapsed)).toBeDefined();
const fill = container.querySelector('.aisthetix-progress-fill')!;
expect(parseFloat(fill.style.width)).toBeCloseTo(barProgress(26_000) * 100);
const finalStepWidth = parseFloat(fill.style.width);
act(() => vi.advanceTimersByTime(94_000));
expect(screen.getByText(finalStatus)).toBeDefined();
expect(container.textContent).not.toMatch(/Ti sta benissimo|You look good|Looking great on you/);
expect(parseFloat(fill.style.width)).toBeGreaterThan(finalStepWidth);
expect(parseFloat(fill.style.width)).toBeLessThan(100);
unmount();
expect(vi.getTimerCount()).toBe(0);
});
});