fix(client): compute "today" from the local calendar, not UTC

This commit is contained in:
jubnl
2026-08-25 00:44:42 +02:00
parent 67b71a52d1
commit efcdbd94fb
20 changed files with 171 additions and 115 deletions
@@ -25,10 +25,13 @@ vi.mock('../../../../src/components/Plugins/TripCardBadges', () => ({
useTripCardBadges: () => (tripId: number) => mocks.badges[tripId] ?? [],
}));
// Local-calendar date string — NOT toISOString(), which is the UTC date and
// disagrees with the badge logic's wall-clock classification between local
// midnight and the UTC rollover (these tests flaked in exactly that window).
const iso = (offsetDays: number): string => {
const d = new Date();
d.setDate(d.getDate() + offsetDays);
return d.toISOString().split('T')[0];
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
};
function buildTrip(over: Partial<DashboardTrip> = {}): DashboardTrip {
@@ -1,6 +1,7 @@
import { StrictMode } from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { http, HttpResponse } from 'msw';
import { localIsoDate } from '../../../../src/utils/localDate';
import userEvent from '@testing-library/user-event';
import { mapsApi, weatherApi } from '../../../../src/api/client';
import { useAddonStore } from '../../../../src/store/addonStore';
@@ -326,8 +327,8 @@ describe('MJourneyEntrySheet full editor', () => {
expect(screen.getByText('Mood')).toBeInTheDocument();
expect(screen.getByText('Weather')).toBeInTheDocument();
expect(screen.getByText('Tags')).toBeInTheDocument();
// An empty entry_date falls back to today, an empty gallery locks the picker.
expect(dateField().value).toBe(new Date().toISOString().split('T')[0]);
// An empty entry_date falls back to today (the LOCAL date), an empty gallery locks the picker.
expect(dateField().value).toBe(localIsoDate());
expect(timeField()).toHaveValue('');
expect(screen.getByRole('button', { name: 'From Gallery' })).toBeDisabled();
expect(screen.getByRole('button', { name: 'Upload photos' })).toBeEnabled();