From 718d83d6d1f2512b8ea91b35f3b2ba1f2d498f54 Mon Sep 17 00:00:00 2001 From: Andrey Epifancev Date: Thu, 22 Oct 2026 16:30:01 +0400 Subject: [PATCH] =?UTF-8?q?test(web):=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D1=82=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D1=81=D1=83=D0=BC=D0=BC=20=D1=88=D0=B0=D1=85=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20(=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20#158,=20AURORA?= =?UTF-8?q?-1538)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Сдвиг единиц, точное округление без float, большие суммы, «-0,00», пустые значения. Co-Authored-By: Claude Opus 5.5 --- .../utils/chessTableCellFormatValue.test.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 web/src/utils/chessTableCellFormatValue.test.ts diff --git a/web/src/utils/chessTableCellFormatValue.test.ts b/web/src/utils/chessTableCellFormatValue.test.ts new file mode 100644 index 0000000..5696c8d --- /dev/null +++ b/web/src/utils/chessTableCellFormatValue.test.ts @@ -0,0 +1,50 @@ +import { describe, expect, it } from 'vitest'; +import { chessTableCellFormatValue as fmt } from './chessTableCellFormatValue'; + +const NBSP = ' '; + +describe('chessTableCellFormatValue', () => { + it('руб.: разряды, запятая, заданное число знаков', () => { + expect(fmt('4454151.93', 'rub', 2)).toBe(`4${NBSP}454${NBSP}151,93`); + expect(fmt('100', 'rub', 2)).toBe('100,00'); + expect(fmt('123.456', 'rub', 0)).toBe('123'); + expect(fmt('123.4', 'rub', 3)).toBe('123,400'); + }); + + it('тыс./млн/млрд — сдвиг запятой в строке', () => { + expect(fmt('2346459.05', 'thousand', 2)).toBe(`2${NBSP}346,46`); + expect(fmt('2346459.05', 'million', 1)).toBe('2,3'); + expect(fmt('2346459.05', 'billion', 3)).toBe('0,002'); + expect(fmt('12', 'thousand', 3)).toBe('0,012'); + }); + + it('округление точное, без двоичной погрешности float', () => { + // 1005 руб. = 1,005 тыс.: через Number(...).toFixed(2) вышло бы «1,00» + expect(fmt('1005', 'thousand', 2)).toBe('1,01'); + expect(fmt('0.005', 'rub', 2)).toBe('0,01'); + }); + + it('большие суммы не теряют копейки', () => { + expect(fmt('12345678901234567.89', 'rub', 2)).toBe(`12${NBSP}345${NBSP}678${NBSP}901${NBSP}234${NBSP}567,89`); + }); + + it('отрицательные', () => { + expect(fmt('-1234567.1', 'rub', 2)).toBe(`-1${NBSP}234${NBSP}567,10`); + expect(fmt('-2346459.05', 'thousand', 2)).toBe(`-2${NBSP}346,46`); + }); + + it('отрицательная сумма, округлённая до нуля, — без минуса', () => { + expect(fmt('-4.00', 'thousand', 2)).toBe('0,00'); + expect(fmt('-0.001', 'rub', 0)).toBe('0'); + }); + + it('пустое значение — пустая строка', () => { + expect(fmt(null, 'rub', 2)).toBe(''); + expect(fmt(undefined, 'thousand', 2)).toBe(''); + expect(fmt('', 'million', 2)).toBe(''); + }); + + it('нечисловое значение в руб. — как пришло', () => { + expect(fmt('abc', 'rub', 2)).toBe('abc'); + }); +});