import { describe, expect, it } from 'vitest'; import type { FailedCheckOut } from '../../types/api'; import { failureKey, failureText, hasColumn } from './checkText'; const base: FailedCheckOut = { column_index: 0, relation: '1600 = 1700', expected: '10.00', actual: '9.00', codes: [], line_ids: [] }; describe('hasColumn', () => { it('0 и больше — колонка есть; -1 и null — нарушение без колонки', () => { expect(hasColumn(0)).toBe(true); expect(hasColumn(3)).toBe(true); expect(hasColumn(-1)).toBe(false); expect(hasColumn(null)).toBe(false); expect(hasColumn(undefined)).toBe(false); }); }); describe('failureText', () => { it('обычное нарушение с номером колонки', () => { expect(failureText(base)).toBe('Колонка 1: 1600 = 1700 — ожидалось 10,00, получено 9,00'); }); it('expected = null: «цель не заполнена»', () => { const text = failureText({ ...base, expected: null }); expect(text).toBe('Колонка 1: 1600 = 1700 — цель не заполнена, получено 9,00'); expect(text).not.toContain('NaN'); }); it('expected и actual оба null', () => { expect(failureText({ ...base, expected: null, actual: null })).toContain('цель не заполнена, получено —'); }); it('actual = null показывается прочерком', () => { expect(failureText({ ...base, actual: null })).toContain('получено —'); }); it('индекс -1 и null: без номера колонки', () => { expect(failureText({ ...base, column_index: -1 })).toMatch(/^Без колонки: /); expect(failureText({ ...base, column_index: null })).toMatch(/^Без колонки: /); }); }); describe('failureKey', () => { it('для нарушений без колонки ключ не содержит -1/null', () => { expect(failureKey({ ...base, column_index: null })).toBe('none-1600 = 1700'); expect(failureKey({ ...base, column_index: -1 })).toBe('none-1600 = 1700'); expect(failureKey(base)).toBe('0-1600 = 1700'); }); });