arm-web/src/utils/dates.test.ts
2026-10-18 13:31:51 +04:00

26 lines
1005 B
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 { formatMoscowDate, isIsoDate } from './dates';
describe('formatMoscowDate', () => {
it('момент времени из API (UTC) — дата по Москве', () => {
expect(formatMoscowDate('2026-10-07T23:11:42.981145Z')).toBe('08.10.2026');
expect(formatMoscowDate('2024-03-12T10:00:00Z')).toBe('12.03.2024');
});
it('пусто и мусор', () => {
expect(formatMoscowDate(null)).toBeNull();
expect(formatMoscowDate('не дата')).toBeNull();
});
});
describe('isIsoDate', () => {
it('строго ГГГГ-ММ-ДД и существующая дата', () => {
expect(isIsoDate('2024-12-31')).toBe(true);
expect(isIsoDate('2024-02-29')).toBe(true);
});
it('иной формат и несуществующая дата — нет', () => {
for (const text of ['2024-2-1', '2024-02-30', '2023-02-29', '31.12.2024', '', ' 2024-12-31', '2024-13-01']) {
expect(isIsoDate(text), text).toBe(false);
}
});
});