import type { components } from '@pipu/api-client'; import { createI18n } from '@pipu/i18n'; import { cleanup, render, screen } from '@testing-library/react'; import { I18nextProvider } from 'react-i18next'; import { afterEach, expect, it } from 'vitest'; import { ScanLine } from './ScanStatus'; afterEach(cleanup); const scan: components['schemas']['ScanProgress'] = { running: true, full: false, started_at: '2026-10-22T12:00:00Z', finished_at: null, found: 12, to_process: 0, processed: 0, added: 0, updated: 0, moved: 0, missing: 0, errors: 0, error: null, phase: 'walking', walked_dirs: 4, current_dir: 'Artist/Album', }; async function fixture(overrides: Partial = {}) { const i18n = await createI18n('ru'); render(); } it('shows changing folder and file counts during the walk without a misleading percentage', async () => { await fixture(); expect(screen.getByText(/Проверено папок: 4 · найдено аудиофайлов: 12/)).toBeVisible(); expect(screen.getByText('Текущая папка: Artist/Album')).toBeVisible(); expect(screen.getByRole('progressbar')).not.toHaveAttribute('aria-valuenow'); }); it('shows a percentage only once file processing has a known total', async () => { await fixture({ phase: 'processing', to_process: 12, processed: 3 }); expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '25'); expect(screen.queryByText(/Текущая папка/)).not.toBeInTheDocument(); }); it.each([['preparing', 'Сопоставление файлов с библиотекой…'], ['finalizing', 'Завершение сканирования…']] as const)('labels the %s stage', async (phase, label) => { await fixture({ phase }); expect(screen.getByText(label)).toBeVisible(); expect(screen.getByRole('progressbar')).not.toHaveAttribute('aria-valuenow'); }); it('supports servers without the new progress fields', async () => { await fixture({ phase: undefined, walked_dirs: undefined, current_dir: undefined, found: 0 }); expect(screen.getByText('Обход папок…')).toBeVisible(); });