mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
Migrate date precision handling tests
Update park and ride submission forms to support and persist all new date precision options (exact, month, year, decade, century, approximate), ensure default and validation align with backend, and verify submissions save without errors. Includes front-end tests scaffolding and adjustments to submission helpers to store updated precision fields.
This commit is contained in:
@@ -405,7 +405,7 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
|||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
<FlexibleDateInput
|
<FlexibleDateInput
|
||||||
value={watch('opening_date') ? parseDateOnly(watch('opening_date')!) : undefined}
|
value={watch('opening_date') ? parseDateOnly(watch('opening_date')!) : undefined}
|
||||||
precision={(watch('opening_date_precision') as DatePrecision) || 'day'}
|
precision={(watch('opening_date_precision') as DatePrecision) || 'exact'}
|
||||||
onChange={(date, precision) => {
|
onChange={(date, precision) => {
|
||||||
setValue('opening_date', date ? toDateWithPrecision(date, precision) : undefined);
|
setValue('opening_date', date ? toDateWithPrecision(date, precision) : undefined);
|
||||||
setValue('opening_date_precision', precision);
|
setValue('opening_date_precision', precision);
|
||||||
@@ -418,7 +418,7 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
|||||||
|
|
||||||
<FlexibleDateInput
|
<FlexibleDateInput
|
||||||
value={watch('closing_date') ? parseDateOnly(watch('closing_date')!) : undefined}
|
value={watch('closing_date') ? parseDateOnly(watch('closing_date')!) : undefined}
|
||||||
precision={(watch('closing_date_precision') as DatePrecision) || 'day'}
|
precision={(watch('closing_date_precision') as DatePrecision) || 'exact'}
|
||||||
onChange={(date, precision) => {
|
onChange={(date, precision) => {
|
||||||
setValue('closing_date', date ? toDateWithPrecision(date, precision) : undefined);
|
setValue('closing_date', date ? toDateWithPrecision(date, precision) : undefined);
|
||||||
setValue('closing_date_precision', precision);
|
setValue('closing_date_precision', precision);
|
||||||
|
|||||||
@@ -711,7 +711,7 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
|||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
<FlexibleDateInput
|
<FlexibleDateInput
|
||||||
value={watch('opening_date') ? parseDateOnly(watch('opening_date')!) : undefined}
|
value={watch('opening_date') ? parseDateOnly(watch('opening_date')!) : undefined}
|
||||||
precision={(watch('opening_date_precision') as DatePrecision) || 'day'}
|
precision={(watch('opening_date_precision') as DatePrecision) || 'exact'}
|
||||||
onChange={(date, precision) => {
|
onChange={(date, precision) => {
|
||||||
setValue('opening_date', date ? toDateWithPrecision(date, precision) : undefined);
|
setValue('opening_date', date ? toDateWithPrecision(date, precision) : undefined);
|
||||||
setValue('opening_date_precision', precision);
|
setValue('opening_date_precision', precision);
|
||||||
@@ -724,7 +724,7 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
|||||||
|
|
||||||
<FlexibleDateInput
|
<FlexibleDateInput
|
||||||
value={watch('closing_date') ? parseDateOnly(watch('closing_date')!) : undefined}
|
value={watch('closing_date') ? parseDateOnly(watch('closing_date')!) : undefined}
|
||||||
precision={(watch('closing_date_precision') as DatePrecision) || 'day'}
|
precision={(watch('closing_date_precision') as DatePrecision) || 'exact'}
|
||||||
onChange={(date, precision) => {
|
onChange={(date, precision) => {
|
||||||
setValue('closing_date', date ? toDateWithPrecision(date, precision) : undefined);
|
setValue('closing_date', date ? toDateWithPrecision(date, precision) : undefined);
|
||||||
setValue('closing_date_precision', precision);
|
setValue('closing_date_precision', precision);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export function RichCompanyDisplay({ data, actionType, showAllFields = true }: R
|
|||||||
{data.founded_date ? (
|
{data.founded_date ? (
|
||||||
<FlexibleDateDisplay
|
<FlexibleDateDisplay
|
||||||
date={data.founded_date}
|
date={data.founded_date}
|
||||||
precision={(data.founded_date_precision as DatePrecision) || 'day'}
|
precision={(data.founded_date_precision as DatePrecision) || 'exact'}
|
||||||
className="font-medium"
|
className="font-medium"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ export function RichParkDisplay({ data, actionType, showAllFields = true }: Rich
|
|||||||
<span className="text-muted-foreground">Opened:</span>{' '}
|
<span className="text-muted-foreground">Opened:</span>{' '}
|
||||||
<FlexibleDateDisplay
|
<FlexibleDateDisplay
|
||||||
date={data.opening_date}
|
date={data.opening_date}
|
||||||
precision={(data.opening_date_precision as DatePrecision) || 'day'}
|
precision={(data.opening_date_precision as DatePrecision) || 'exact'}
|
||||||
className="font-medium"
|
className="font-medium"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -175,7 +175,7 @@ export function RichParkDisplay({ data, actionType, showAllFields = true }: Rich
|
|||||||
<span className="text-muted-foreground">Closed:</span>{' '}
|
<span className="text-muted-foreground">Closed:</span>{' '}
|
||||||
<FlexibleDateDisplay
|
<FlexibleDateDisplay
|
||||||
date={data.closing_date}
|
date={data.closing_date}
|
||||||
precision={(data.closing_date_precision as DatePrecision) || 'day'}
|
precision={(data.closing_date_precision as DatePrecision) || 'exact'}
|
||||||
className="font-medium"
|
className="font-medium"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -606,7 +606,7 @@ export function RichRideDisplay({ data, actionType, showAllFields = true }: Rich
|
|||||||
<span className="text-muted-foreground">Opened:</span>{' '}
|
<span className="text-muted-foreground">Opened:</span>{' '}
|
||||||
<FlexibleDateDisplay
|
<FlexibleDateDisplay
|
||||||
date={data.opening_date}
|
date={data.opening_date}
|
||||||
precision={(data.opening_date_precision as DatePrecision) || 'day'}
|
precision={(data.opening_date_precision as DatePrecision) || 'exact'}
|
||||||
className="font-medium"
|
className="font-medium"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -616,7 +616,7 @@ export function RichRideDisplay({ data, actionType, showAllFields = true }: Rich
|
|||||||
<span className="text-muted-foreground">Closed:</span>{' '}
|
<span className="text-muted-foreground">Closed:</span>{' '}
|
||||||
<FlexibleDateDisplay
|
<FlexibleDateDisplay
|
||||||
date={data.closing_date}
|
date={data.closing_date}
|
||||||
precision={(data.closing_date_precision as DatePrecision) || 'day'}
|
precision={(data.closing_date_precision as DatePrecision) || 'exact'}
|
||||||
className="font-medium"
|
className="font-medium"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ interface TimelineEventCardProps {
|
|||||||
|
|
||||||
// ⚠️ IMPORTANT: Use parseDateForDisplay to prevent timezone shifts
|
// ⚠️ IMPORTANT: Use parseDateForDisplay to prevent timezone shifts
|
||||||
// YYYY-MM-DD strings must be interpreted as local dates, not UTC
|
// YYYY-MM-DD strings must be interpreted as local dates, not UTC
|
||||||
const formatEventDate = (date: string, precision: string = 'day') => {
|
const formatEventDate = (date: string, precision: string = 'exact') => {
|
||||||
const dateObj = parseDateForDisplay(date);
|
const dateObj = parseDateForDisplay(date);
|
||||||
|
|
||||||
switch (precision) {
|
switch (precision) {
|
||||||
|
|||||||
@@ -3708,7 +3708,7 @@ export async function submitTimelineEventUpdate(
|
|||||||
entity_id: originalEvent.entity_id,
|
entity_id: originalEvent.entity_id,
|
||||||
event_type: changedFields.event_type !== undefined ? changedFields.event_type : originalEvent.event_type,
|
event_type: changedFields.event_type !== undefined ? changedFields.event_type : originalEvent.event_type,
|
||||||
event_date: changedFields.event_date !== undefined ? (typeof changedFields.event_date === 'string' ? changedFields.event_date : changedFields.event_date.toISOString().split('T')[0]) : originalEvent.event_date,
|
event_date: changedFields.event_date !== undefined ? (typeof changedFields.event_date === 'string' ? changedFields.event_date : changedFields.event_date.toISOString().split('T')[0]) : originalEvent.event_date,
|
||||||
event_date_precision: (changedFields.event_date_precision !== undefined ? changedFields.event_date_precision : originalEvent.event_date_precision) || 'day',
|
event_date_precision: (changedFields.event_date_precision !== undefined ? changedFields.event_date_precision : originalEvent.event_date_precision) || 'exact',
|
||||||
title: changedFields.title !== undefined ? changedFields.title : originalEvent.title,
|
title: changedFields.title !== undefined ? changedFields.title : originalEvent.title,
|
||||||
description: changedFields.description !== undefined ? changedFields.description : originalEvent.description,
|
description: changedFields.description !== undefined ? changedFields.description : originalEvent.description,
|
||||||
from_value: changedFields.from_value !== undefined ? changedFields.from_value : originalEvent.from_value,
|
from_value: changedFields.from_value !== undefined ? changedFields.from_value : originalEvent.from_value,
|
||||||
|
|||||||
@@ -257,14 +257,14 @@ export function generateRandomCompany(type: 'manufacturer' | 'operator' | 'desig
|
|||||||
// Add full founded date with precision
|
// Add full founded date with precision
|
||||||
if (shouldPopulateField(density, counter, 'medium')) {
|
if (shouldPopulateField(density, counter, 'medium')) {
|
||||||
companyData.founded_date = `${foundedYear}-01-01`;
|
companyData.founded_date = `${foundedYear}-01-01`;
|
||||||
companyData.founded_date_precision = randomItem(['year', 'month', 'day']);
|
companyData.founded_date_precision = randomItem(['year', 'month', 'exact']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add defunct date for some companies
|
// Add defunct date for some companies
|
||||||
if (shouldPopulateField(density, counter, 'low') && Math.random() > 0.85) {
|
if (shouldPopulateField(density, counter, 'low') && Math.random() > 0.85) {
|
||||||
const defunctYear = randomInt(foundedYear + 10, 2024);
|
const defunctYear = randomInt(foundedYear + 10, 2024);
|
||||||
companyData.defunct_date = `${defunctYear}-12-31`;
|
companyData.defunct_date = `${defunctYear}-12-31`;
|
||||||
companyData.defunct_date_precision = randomItem(['year', 'month', 'day']);
|
companyData.defunct_date_precision = randomItem(['year', 'month', 'exact']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add source URL
|
// Add source URL
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ export function randomDate(startYear: number, endYear: number): string {
|
|||||||
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randomDatePrecision(): 'day' | 'month' | 'year' {
|
export function randomDatePrecision(): 'exact' | 'month' | 'year' {
|
||||||
return randomItem(['day', 'month', 'year']);
|
return randomItem(['exact', 'month', 'year']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export interface TimelineEventDatabaseRecord {
|
|||||||
entity_type: 'park' | 'ride' | 'company' | 'ride_model';
|
entity_type: 'park' | 'ride' | 'company' | 'ride_model';
|
||||||
event_type: string;
|
event_type: string;
|
||||||
event_date: string;
|
event_date: string;
|
||||||
event_date_precision: 'day' | 'month' | 'year';
|
event_date_precision: 'exact' | 'month' | 'year' | 'decade' | 'century' | 'approximate';
|
||||||
title: string;
|
title: string;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
from_value?: string | null;
|
from_value?: string | null;
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ export interface TimelineEventItemData {
|
|||||||
entity_type: 'park' | 'ride' | 'company' | 'ride_model';
|
entity_type: 'park' | 'ride' | 'company' | 'ride_model';
|
||||||
event_type: string;
|
event_type: string;
|
||||||
event_date: string; // ISO date
|
event_date: string; // ISO date
|
||||||
event_date_precision: 'day' | 'month' | 'year';
|
event_date_precision: 'exact' | 'month' | 'year' | 'decade' | 'century' | 'approximate';
|
||||||
title: string;
|
title: string;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
from_value?: string | null;
|
from_value?: string | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user