mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
refactor(planner): split the tour day time growth out of four size-capped files
The place form's time section moves into PlaceFormTimeSection, its tour test into PlaceFormModal.tour.test.tsx over a shared tests/helpers/placeForm setup, the page hook hands the place form its close, day plan and tour, and the day plan's surface classes and tones move into dayPlanSurfaces. The size baseline drops to the new counts.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// FE-COMP-PLACEFORM-001 to FE-COMP-PLACEFORM-036, FE-PLANNER-PLACEFORM-016 to FE-PLANNER-PLACEFORM-067, plus FE-PLANNER-PLACEFORM-068 to -125
|
||||
// FE-COMP-PLACEFORM-001 to FE-COMP-PLACEFORM-036, FE-PLANNER-PLACEFORM-016 to FE-PLANNER-PLACEFORM-067, plus FE-PLANNER-PLACEFORM-068 to -124
|
||||
import { render, screen, waitFor, fireEvent, within, act } from '../../../tests/helpers/render';
|
||||
import type { TourListItem } from '@trek/shared';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { server } from '../../../tests/helpers/msw/server';
|
||||
@@ -12,47 +11,19 @@ import { usePermissionsStore } from '../../store/permissionsStore';
|
||||
import { usePluginStore } from '../../store/pluginStore';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import { buildUser, buildTrip, buildPlace, buildCategory, buildAssignment } from '../../../tests/helpers/factories';
|
||||
import { placeFormProps, seedPlaceFormStores } from '../../../tests/helpers/placeForm';
|
||||
import PlaceFormModal from './PlaceFormModal';
|
||||
|
||||
// Mock CustomTimePicker so we get a simple text input instead of the portal-heavy UI.
|
||||
// The aria props land on the input, as the real picker spreads them onto its own.
|
||||
vi.mock('../shared/CustomTimePicker', () => ({
|
||||
default: ({ value, onChange, placeholder, ...aria }: {
|
||||
value: string
|
||||
onChange: (v: string) => void
|
||||
placeholder?: string
|
||||
'aria-label'?: string
|
||||
'aria-describedby'?: string
|
||||
'aria-invalid'?: boolean
|
||||
}) => (
|
||||
<input
|
||||
{...aria}
|
||||
data-testid="time-picker"
|
||||
type="text"
|
||||
value={value}
|
||||
onChange={e => onChange(e.target.value)}
|
||||
placeholder={placeholder ?? '00:00'}
|
||||
/>
|
||||
),
|
||||
// CustomTimePicker as a plain text input, see TimePickerStub.
|
||||
vi.mock('../shared/CustomTimePicker', async () => ({
|
||||
default: (await import('../../../tests/helpers/placeForm')).TimePickerStub,
|
||||
}));
|
||||
|
||||
const defaultProps = {
|
||||
isOpen: true,
|
||||
onClose: vi.fn(),
|
||||
onSave: vi.fn(),
|
||||
place: null,
|
||||
prefillCoords: null,
|
||||
tripId: 1,
|
||||
categories: [],
|
||||
onCategoryCreated: vi.fn(),
|
||||
assignmentId: null,
|
||||
dayAssignments: [],
|
||||
};
|
||||
const defaultProps = placeFormProps;
|
||||
|
||||
beforeEach(() => {
|
||||
resetAllStores();
|
||||
seedStore(useAuthStore, { user: buildUser(), isAuthenticated: true, hasMapsKey: false });
|
||||
seedStore(useTripStore, { trip: buildTrip({ id: 1 }) });
|
||||
seedPlaceFormStores();
|
||||
});
|
||||
|
||||
describe('PlaceFormModal', () => {
|
||||
@@ -879,37 +850,6 @@ describe('PlaceFormModal', () => {
|
||||
expect(screen.getByDisplayValue('20:34')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-PLANNER-PLACEFORM-125: a tour with a start and no end says below its times the end it works out to (TIME-02)', () => {
|
||||
const place = buildPlace({ id: 7, name: 'Ridge', place_time: '09:00', end_time: null });
|
||||
const assignment = buildAssignment({ id: 42, day_id: 3, place });
|
||||
const tour: TourListItem = {
|
||||
place_id: 7,
|
||||
name: 'Ridge',
|
||||
tour_type: 'hike',
|
||||
distance: 8,
|
||||
elevation_gain: 300,
|
||||
elevation_loss: 300,
|
||||
duration: 150,
|
||||
planned_duration_minutes: null,
|
||||
break_additional_minutes: 30,
|
||||
difficulty: null,
|
||||
wanderer_ref: null,
|
||||
match_confidence: 1,
|
||||
max_hiking_difficulty: 2,
|
||||
planned: true,
|
||||
caution: false,
|
||||
};
|
||||
const { unmount } = render(
|
||||
<PlaceFormModal {...defaultProps} place={place} assignmentId={42} dayAssignments={[assignment]} tour={tour} />
|
||||
);
|
||||
expect(screen.getByTestId('tour-day-end-hint')).toHaveTextContent(
|
||||
'Left empty, the end is worked out: 12:00, the start plus the tour time of 3 h.'
|
||||
);
|
||||
unmount();
|
||||
render(<PlaceFormModal {...defaultProps} place={place} assignmentId={42} dayAssignments={[assignment]} />);
|
||||
expect(screen.queryByTestId('tour-day-end-hint')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-PLANNER-PLACEFORM-086: on a road trip the End says the drive leaves at it', () => {
|
||||
const place = buildPlace({ name: 'Test', place_time: '09:00', end_time: '14:00' });
|
||||
const assignment = buildAssignment({ id: 10, day_id: 5, place });
|
||||
|
||||
Reference in New Issue
Block a user