arm-core/web/src/widgets/FilesDrawer/documentRows.test.ts
Andrey Epifancev 5958b07410 fix(web): синхронизация встроенного фронта с arm-web@test (a3c0010) (#139)
Перенесён диапазон arm-web 8345f5e..a3c0010 (3 коммитов, 22 файлов набора
синхронизации) скриптом docs/scripts/sync-web.sh. После переноса web/ и
arm-web@test идентичны по набору. Коммиты arm-web:
- ff1e45c file id as option value for react rendering
- 0242486 fix(#49): зелёный make check и исправления после ревью (AURORA-144)
- 0fdbd80 feat: add comments frontend, checklist modal, files delete, select options in document review

Co-Authored-By: sync-web.sh <noreply@aepif.ru>
2026-10-19 14:54:36 +04:00

195 lines
7.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest';
import type { DocumentBrief, FileOut } from '../../types/api';
import { buildDocumentRows, rowBadge } from './documentRows';
const doc = (over: Partial<DocumentBrief> = {}): DocumentBrief => ({
id: 'd1',
document_type: 'BALANCE',
osv_account_code: null,
period_year: 2024,
period_quarter: 'Q1',
is_cumulative: false,
status: 'CONFIRMED',
period_check: 'UNKNOWN',
counterparty_check: null,
locator: null,
comments_count: 0,
issue_counts: { error: 0, info: 0 },
...over,
});
const file = (over: Partial<FileOut> = {}): FileOut => ({
id: 'f1',
legal_entity_id: 'le',
original_name: 'Баланс_2024_К1.pdf',
file_type: 'PDF',
status: 'PROCESSED',
version_no: 1,
size_bytes: 10,
uploaded_at: '2024-03-12T10:00:00Z',
consolidation_id: null,
job: null,
documents: [],
...over,
});
describe('buildDocumentRows', () => {
it('документ ББ из PDF', () => {
const rows = buildDocumentRows([file({ documents: [doc()] })]);
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({
key: 'd1',
documentId: 'd1',
name: 'Баланс_2024_К1.pdf',
subtitle: 'Бух. баланс · PDF · 12.03.2024',
period: '2024 К1',
periodCheck: 'UNKNOWN',
counterpartyCheck: null,
status: 'success',
statusLabel: 'Загружен',
linkable: true,
fileType: 'PDF',
});
});
it('два документа одного файла — две строки', () => {
const rows = buildDocumentRows([
file({
file_type: 'XLSX',
documents: [
doc({ id: 'a', document_type: 'OSV', osv_account_code: '60' }),
doc({ id: 'b', document_type: 'OSV', osv_account_code: '62', status: 'NEEDS_CHECK' }),
],
}),
]);
expect(rows.map((r) => r.key)).toEqual(['a', 'b']);
expect(rows[0].subtitle).toBe('ОСВ 60 · XLSX · 12.03.2024');
expect(rows[1].status).toBe('warning');
expect(rows[1].statusLabel).toBe('Требуется проверка');
});
it('файл PROCESSING без документов', () => {
const rows = buildDocumentRows([file({ status: 'PROCESSING' })]);
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({
key: 'f1',
documentId: null,
period: '—',
subtitle: 'PDF · 12.03.2024',
status: 'processing',
statusLabel: 'Обработка',
linkable: false,
});
});
it('файл ERROR с причиной', () => {
const rows = buildDocumentRows([
file({
status: 'ERROR',
job: {
id: 'j',
status: 'FAILED',
error_code: 'E1',
error_message: 'сообщение',
mapping_error: null,
warnings: [],
mapping_warnings: [],
finished_at: null,
} as FileOut['job'],
}),
]);
expect(rows[0]).toMatchObject({ status: 'error', statusLabel: 'Ошибка', errorReason: 'сообщение', linkable: false });
});
it('расшифровка — «Прочий документ», не кликается', () => {
const rows = buildDocumentRows([file({ documents: [doc({ id: 'x', document_type: 'DISCLOSURE' })] })]);
expect(rows[0].subtitle).toBe('Прочий документ · PDF · 12.03.2024');
expect(rows[0].linkable).toBe(false);
});
it('подпись консолидации добавляется в subtitle последней, null — не добавляется', () => {
const rows = buildDocumentRows(
[file({ id: 'f1', documents: [doc()] }), file({ id: 'f2', documents: [], consolidation_id: 'c9' })],
(f) => (f.id === 'f2' ? 'вне консолидации' : null),
);
expect(rows[0].subtitle.endsWith('вне консолидации')).toBe(false);
expect(rows[1].subtitle.endsWith(' · вне консолидации')).toBe(true);
});
});
const jsonFailed = { code: 'JSON_FAILED', severity: 'error' as const, message: 'm', locator: 'file:x_ofr.json' };
const job = (over: Partial<NonNullable<FileOut['job']>> = {}): FileOut['job'] => ({
id: 'j',
status: 'DONE',
error_code: null,
error_message: null,
mapping_error: null,
warnings: [],
mapping_warnings: [],
finished_at: null,
...over,
});
describe('buildDocumentRows: предупреждения', () => {
it('предупреждения файла попадают в обе строки файла', () => {
const rows = buildDocumentRows([
file({ job: job({ warnings: [jsonFailed], mapping_warnings: ['w'] }), documents: [doc({ id: 'a' }), doc({ id: 'b' })] }),
]);
expect(rows.map((r) => r.fileWarnings.length)).toEqual([1, 1]);
expect(rows[0].mappingWarnings).toEqual(['w']);
});
it('файл ERROR без документов', () => {
const rows = buildDocumentRows([file({ status: 'ERROR', job: job({ warnings: [jsonFailed] }) })]);
expect(rows[0].fileWarnings).toEqual([jsonFailed]);
expect(rows[0].issueCounts).toEqual({ error: 0, info: 0 });
});
it('fileId — id файла и у строки документа, и у строки файла без документов (удаление идёт по файлу)', () => {
const withDoc = buildDocumentRows([file({ id: 'f7', documents: [doc({ id: 'd7' })] })]);
expect(withDoc[0]).toMatchObject({ key: 'd7', documentId: 'd7', fileId: 'f7' });
const failed = buildDocumentRows([file({ id: 'f8', status: 'ERROR' })]);
expect(failed[0]).toMatchObject({ key: 'f8', documentId: null, fileId: 'f8' });
});
it('job null — пустые списки; старый формат строк не ломает', () => {
expect(buildDocumentRows([file({ documents: [doc()] })])[0]).toMatchObject({ fileWarnings: [], mappingWarnings: [] });
const legacy = buildDocumentRows([file({ job: job({ warnings: ['старое'] as never }), documents: [doc()] })]);
expect(legacy[0].fileWarnings[0]).toMatchObject({ code: 'LEGACY_WARNING', message: 'старое' });
});
it('ядро без issue_counts (до v5.19) — нули, не падает', () => {
const old = doc() as Partial<DocumentBrief>;
old.issue_counts = undefined;
const rows = buildDocumentRows([file({ documents: [old as DocumentBrief] })]);
expect(rows[0].issueCounts).toEqual({ error: 0, info: 0 });
});
it('issue_counts документа переносятся в issueCounts', () => {
const rows = buildDocumentRows([file({ documents: [doc({ issue_counts: { error: 1, info: 3 } })] })]);
expect(rows[0].issueCounts).toEqual({ error: 1, info: 3 });
});
});
describe('rowBadge', () => {
const row = (fileWarnings: unknown[], counts: { error: number; info: number }) =>
buildDocumentRows([file({ job: job({ warnings: fileWarnings as never }), documents: [doc({ issue_counts: counts })] })])[0];
it('только счётчики info', () => {
expect(rowBadge(row([], { error: 0, info: 2 }))).toEqual({ count: 2, level: 'info' });
});
it('ошибка файла + info документа', () => {
expect(rowBadge(row([jsonFailed], { error: 0, info: 1 }))).toEqual({ count: 2, level: 'error' });
});
it('error документа без файла', () => {
expect(rowBadge(row([], { error: 1, info: 0 }))).toMatchObject({ level: 'error' });
});
it('файл без документов: считаются предупреждения файла', () => {
const r = buildDocumentRows([file({ status: 'ERROR', job: job({ warnings: [jsonFailed] }) })])[0];
expect(rowBadge(r)).toEqual({ count: 1, level: 'error' });
});
it('нули — null', () => {
expect(rowBadge(row([], { error: 0, info: 0 }))).toBeNull();
});
});