import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import test from 'node:test'; import { bindDateInputMask, dateInputValueToIso, formatDateInputValue, isoDateToInputValue } from '../admin/js/date-input.js'; test('маска расставляет точки при последовательном вводе восьми цифр', () => { assert.equal(formatDateInputValue('0'), '0'); assert.equal(formatDateInputValue('01'), '01'); assert.equal(formatDateInputValue('010'), '01.0'); assert.equal(formatDateInputValue('0109'), '01.09'); assert.equal(formatDateInputValue('01092'), '01.09.2'); assert.equal(formatDateInputValue('01092026'), '01.09.2026'); }); test('маска удаляет посторонние символы и ограничивает год четырьмя цифрами', () => { assert.equal(formatDateInputValue('01-09/2026'), '01.09.2026'); assert.equal(formatDateInputValue('010920261234'), '01.09.2026'); }); test('привязанная маска расставляет точки прямо во время ввода', () => { const input = new DateInputStub(); bindDateInputMask(input); typeText(input, '01092026'); assert.equal(input.value, '01.09.2026'); assert.equal(input.selectionStart, 10); typeText(input, '12'); assert.equal(input.value, '01.09.2026'); assert.equal(input.selectionStart, 10); }); test('дата преобразуется между форматом поля и ISO без потери значения', () => { assert.equal(dateInputValueToIso('01.09.2026'), '2026-09-01'); assert.equal(isoDateToInputValue('2026-09-01'), '01.09.2026'); }); test('неполный, шестизначный год и несуществующие даты отклоняются', () => { assert.throws(() => dateInputValueToIso('01.09.202'), /год — 4 цифры/); assert.throws(() => dateInputValueToIso('01.09.202612'), /год — 4 цифры/); assert.throws(() => dateInputValueToIso('31.02.2026'), /существующую дату/); assert.equal(dateInputValueToIso('29.02.2024'), '2024-02-29'); assert.throws(() => dateInputValueToIso('29.02.2025'), /существующую дату/); }); test('все поля дат календарного графика подключены к числовой маске', async () => { const template = await readFile(new URL('../react/admin/tabs/AcademicCalendarTab.jsx', import.meta.url), 'utf8'); // Маска объявлена один раз в компоненте поля даты и подключена ко всем шести полям assert.match(template, /data-date-input/); assert.match(template, /maxLength="10"/); assert.equal(template.match(/