Files
portal/app/tests/Frontend/appliesFromMessage.spec.ts
T
Дмитрий 6e2ad108de feat(slepok): Task 2.11 UI — applies_from toast «вступит в силу N.21:00 МСК»
После правки slepok-чувствительных полей проекта (regions / delivery_days_mask /
daily_limit_target / источник) backend возвращает ProjectResource.applies_from
= N.21:00 МСК (Task 2.11 backend slice, commit dd5954d8). Клиент Лидерры
теперь видит расширенный тост: «Сохранено. Изменения вступят в силу
DD.MM.YYYY в 21:00 МСК.» Когда правка не затронула slepok — обычное
«Сохранено.».

Изменения:
- composables/appliesFromMessage.ts — чистый форматтер (Moscow tz, не локаль клиента).
- ProjectDetailsDrawer / NewProjectDialog / EditProjectDialog — emit('saved', appliesFrom).
- ProjectsView — v-snackbar + onSaved/onDrawerSaved обработчики.
- tests/Frontend/appliesFromMessage.spec.ts — 5 invariant-кейсов.

Plan §Task 2.11 Step 5-6. Spec §4.2.5 UX block. R-15 + R-06..R-08 UX closure.
Vitest worktree-only 944/3sk GREEN, vue-tsc 3 pre-existing errors (вне диффа),
ESLint clean на затронутых файлах.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 09:52:42 +03:00

35 lines
1.8 KiB
TypeScript

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');
});
});