import { describe, expect, it } from 'vitest'; import { formatAppliesFromMessage } from '../../resources/js/composables/appliesFromMessage'; describe('formatAppliesFromMessage', () => { it('returns "Сохранено." when applies_from is null', () => { expect(formatAppliesFromMessage(null)).toBe('Сохранено.'); }); it('returns "Сохранено." when applies_from is undefined', () => { expect(formatAppliesFromMessage(undefined)).toBe('Сохранено.'); }); it('returns message with date and 21:00 МСК when applies_from is given (ISO8601 +03:00)', () => { const msg = formatAppliesFromMessage('2026-05-29T21:00:00+03:00'); expect(msg).toContain('21:00 МСК'); expect(msg).toContain('29.05.2026'); expect(msg).toMatch(/^Сохранено\./); }); it('renders Moscow-local date even when applies_from offset differs (e.g. UTC)', () => { // 2026-05-29 18:00 UTC = 2026-05-29 21:00 МСК — same calendar date в Москве const msg = formatAppliesFromMessage('2026-05-29T18:00:00Z'); expect(msg).toContain('29.05.2026'); expect(msg).toContain('21:00 МСК'); }); it('rolls calendar date forward when applies_from straddles midnight UTC (Moscow ahead by 3h)', () => { // 2026-05-29 22:00 UTC = 2026-05-30 01:00 МСК (но 21:00 МСК — это фиксированный слепок-час) // Бизнес-инвариант: applies_from = N.21:00 МСК, поэтому в Москве это всегда 21:00. // Этот кейс проверяет, что мы берём календарную дату по Москве, не локали клиента. const msg = formatAppliesFromMessage('2026-05-30T21:00:00+03:00'); expect(msg).toContain('30.05.2026'); }); });