mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
fix(tours): keep editor dropdowns inside the sidebar
This commit is contained in:
@@ -12,7 +12,7 @@ import type { Day } from '../../../types'
|
||||
import { toggleTourPlacing } from '../../../store/tourPlaceToolStore'
|
||||
import { publishTourFerrataCrossings } from '../../../store/tourFerrataCrossingStore'
|
||||
import { TourPlannerRail, TourPlannerToursRail } from './TourPlannerPanels'
|
||||
import { hikePlannerDefaults } from '../../../../tests/helpers/tourPlannerStub'
|
||||
import { hikePlannerDefaults, mockTourEditorLayout } from '../../../../tests/helpers/tourPlannerStub'
|
||||
import { tourRepo } from '../../../repo/tourRepo'
|
||||
import { useTripStore } from '../../../store/tripStore'
|
||||
import type { TourStage } from '../stages/tourStages'
|
||||
@@ -132,6 +132,12 @@ beforeEach(() => {
|
||||
seedStore(useSettingsStore, { settings: { distance_unit: 'metric' } })
|
||||
})
|
||||
|
||||
function openDifficulty() {
|
||||
const trigger = screen.getByRole('button', { name: 'Maximum trail difficulty' })
|
||||
mockTourEditorLayout(trigger.parentElement ?? trigger)
|
||||
fireEvent.click(trigger)
|
||||
}
|
||||
|
||||
describe('TourPlannerToursRail', () => {
|
||||
it('MDT-02: a multi-day tour unfolds its stages in the list, a day tour has nothing to unfold', async () => {
|
||||
vi.spyOn(tourRepo, 'detail').mockResolvedValue({ tour, waypoints: [] })
|
||||
@@ -702,6 +708,7 @@ describe('TourPlannerRail', () => {
|
||||
render(<TourPlannerRail planner={controller} />)
|
||||
|
||||
expect(screen.getByLabelText('Tour name')).toBeDisabled()
|
||||
expect(screen.getByTestId('tour-type-select')).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Maximum trail difficulty' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Back to Tours' })).toBeDisabled()
|
||||
@@ -765,7 +772,7 @@ describe('TourPlannerRail', () => {
|
||||
const controller = planner({ mode: { type: 'new-draft' }, setMaxHikingDifficulty: setDifficulty, acknowledgeAlpine: acknowledge })
|
||||
const { unmount } = render(<TourPlannerRail planner={controller} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Maximum trail difficulty' }))
|
||||
openDifficulty()
|
||||
fireEvent.click(screen.getByRole('button', { name: /T4: Alpine hiking/ }))
|
||||
expect(screen.getByRole('heading', { name: 'Enable alpine routing?' })).toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Enable alpine routing' }))
|
||||
@@ -775,7 +782,7 @@ describe('TourPlannerRail', () => {
|
||||
|
||||
// The planner remembers the answer, so a rail that mounts anew does not ask again.
|
||||
render(<TourPlannerRail planner={planner({ mode: { type: 'new-draft' }, setMaxHikingDifficulty: setDifficulty, alpineAcknowledged: true })} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Maximum trail difficulty' }))
|
||||
openDifficulty()
|
||||
fireEvent.click(screen.getByRole('button', { name: /T5: Demanding alpine hiking/ }))
|
||||
expect(screen.queryByRole('heading', { name: 'Enable alpine routing?' })).not.toBeInTheDocument()
|
||||
expect(setDifficulty).toHaveBeenLastCalledWith(5)
|
||||
@@ -785,7 +792,7 @@ describe('TourPlannerRail', () => {
|
||||
const setDifficulty = vi.fn()
|
||||
render(<TourPlannerRail planner={planner({ mode: { type: 'new-draft' }, setMaxHikingDifficulty: setDifficulty })} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Maximum trail difficulty' }))
|
||||
openDifficulty()
|
||||
fireEvent.click(screen.getByRole('button', { name: /T4: Alpine hiking/ }))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
expect(setDifficulty).not.toHaveBeenCalled()
|
||||
@@ -802,7 +809,7 @@ describe('TourPlannerRail', () => {
|
||||
})} />
|
||||
}
|
||||
render(<StatefulDifficultyRail />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Maximum trail difficulty' }))
|
||||
openDifficulty()
|
||||
|
||||
for (const label of [
|
||||
'T1: Hiking',
|
||||
@@ -818,6 +825,22 @@ describe('TourPlannerRail', () => {
|
||||
expect(screen.getAllByRole('status').some(el => /T3 routes may include exposed/.test(el.textContent ?? ''))).toBe(true)
|
||||
})
|
||||
|
||||
it('dismisses an open tour type list when saving locks the editor', () => {
|
||||
const controller = planner({ mode: { type: 'new-draft' } })
|
||||
const { rerender } = render(<TourPlannerRail planner={controller} />)
|
||||
const trigger = screen.getByTestId('tour-type-select')
|
||||
mockTourEditorLayout(trigger)
|
||||
fireEvent.click(trigger)
|
||||
expect(screen.getByRole('group', { name: 'Tour type' })).toBeInTheDocument()
|
||||
|
||||
rerender(<TourPlannerRail planner={{ ...controller, isSaving: true }} />)
|
||||
expect(trigger).toBeDisabled()
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(screen.queryByTestId('tour-type-option-hike')).not.toBeInTheDocument()
|
||||
rerender(<TourPlannerRail planner={controller} />)
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('TOUR-PLANNER-RAIL-009: neutral shows only the Plan new entry and new-draft guidance hides after the first waypoint', () => {
|
||||
const controller = planner({ mode: { type: 'neutral' } })
|
||||
const { rerender } = render(<TourPlannerRail planner={controller} />)
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useRailHeadProps } from './railHead'
|
||||
import EmptyState from '../../shared/EmptyState'
|
||||
import { useToast } from '../../shared/Toast'
|
||||
import { Tooltip } from '../../shared/Tooltip'
|
||||
import { PopoverBoundary } from '../../shared/useAnchoredPopover'
|
||||
import { BOX } from '../../Planner/bookings/bookingParts'
|
||||
import { BarButton, SoftPill } from '../../Planner/planParts'
|
||||
import TourListRow from '../TourListRow'
|
||||
@@ -335,6 +336,7 @@ export function TourPlannerRail({ planner,
|
||||
const { t } = useTranslation()
|
||||
const [confirmDiscard, setConfirmDiscard] = useState(false)
|
||||
const [pendingDifficulty, setPendingDifficulty] = useState<1 | 2 | 3 | 4 | 5 | 6 | null>(null)
|
||||
const editorScrollRef = useRef<HTMLDivElement>(null)
|
||||
const isSaving = planner.isSaving
|
||||
// Nothing in the editor changes while the viewer may not edit or a save is in flight.
|
||||
const locked = !canEdit || isSaving
|
||||
@@ -389,44 +391,46 @@ export function TourPlannerRail({ planner,
|
||||
</BarButton>
|
||||
</div>
|
||||
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3 py-3.5">
|
||||
<TourRemoteChangeNotice planner={planner} />
|
||||
<WalkImportDraftNotice planner={planner} />
|
||||
<WalkRoutePendingNotice planner={planner} />
|
||||
<TourNameField planner={planner} locked={locked} />
|
||||
<div ref={editorScrollRef} data-testid="tour-planner-editor-scroll" className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3 py-3.5">
|
||||
<PopoverBoundary value={editorScrollRef}>
|
||||
<TourRemoteChangeNotice planner={planner} />
|
||||
<WalkImportDraftNotice planner={planner} />
|
||||
<WalkRoutePendingNotice planner={planner} />
|
||||
<TourNameField planner={planner} locked={locked} />
|
||||
|
||||
<TourTypeFields planner={planner} locked={locked} />
|
||||
<TourTypeFields planner={planner} locked={locked} />
|
||||
|
||||
<TourStageModeField planner={planner} locked={locked} />
|
||||
<TourStageModeField planner={planner} locked={locked} />
|
||||
|
||||
{recordedTrack?.available && <RecordedTrackCard recordedTrack={recordedTrack} disabled={isSaving} />}
|
||||
{recordedTrack?.available && <RecordedTrackCard recordedTrack={recordedTrack} disabled={isSaving} />}
|
||||
|
||||
<UnreachableNotice planner={planner} />
|
||||
<WalkFerryNotice planner={planner} />
|
||||
<UnreachableNotice planner={planner} />
|
||||
<WalkFerryNotice planner={planner} />
|
||||
|
||||
<TourStageLossNotice planner={planner} />
|
||||
<TourStageDayNotice planner={planner} />
|
||||
<TourStageLossNotice planner={planner} />
|
||||
<TourStageDayNotice planner={planner} />
|
||||
|
||||
<TourWaypointList planner={planner} canEdit={canEdit} isSaving={isSaving} tourPlaceIds={tourPlaceIds} />
|
||||
<TourWaypointList planner={planner} canEdit={canEdit} isSaving={isSaving} tourPlaceIds={tourPlaceIds} />
|
||||
|
||||
<BikeWaysCard planner={planner} />
|
||||
<BikeWaysCard planner={planner} />
|
||||
|
||||
<RunWaysCard planner={planner} />
|
||||
<RunWaysCard planner={planner} />
|
||||
|
||||
<HorseRoutesCard planner={planner} />
|
||||
<HorseRoutesCard planner={planner} />
|
||||
|
||||
<SkiPlannerSummary planner={planner} />
|
||||
<SkiPlannerSummary planner={planner} />
|
||||
|
||||
{planner.tourType === 'hike' && (
|
||||
<HikeWaysCard tripId={planner.tripId} route={planner.route} routeCurrent={planner.routeCurrent}
|
||||
routingLimit={planner.maxHikingDifficulty} />
|
||||
)}
|
||||
{planner.tourType === 'hike' && (
|
||||
<HikeWaysCard tripId={planner.tripId} route={planner.route} routeCurrent={planner.routeCurrent}
|
||||
routingLimit={planner.maxHikingDifficulty} />
|
||||
)}
|
||||
|
||||
<TourPoiSearchCard planner={planner} />
|
||||
<TourPoiSearchCard planner={planner} />
|
||||
|
||||
<PaddleEditorCards planner={planner} locked={locked} checklist={paddleChecklist} />
|
||||
<PaddleEditorCards planner={planner} locked={locked} checklist={paddleChecklist} />
|
||||
|
||||
<TourDetailsSection planner={planner} locked={locked} onDifficultyChange={changeDifficulty} />
|
||||
<TourDetailsSection planner={planner} locked={locked} onDifficultyChange={changeDifficulty} />
|
||||
</PopoverBoundary>
|
||||
</div>
|
||||
|
||||
<TourEditorRailFooter planner={planner} canEdit={canEdit} locked={locked} isSavedEdit={isSavedEdit} onDiscard={requestClose} />
|
||||
|
||||
@@ -111,7 +111,7 @@ function BikeProfileField({ planner }: { planner: TourPlannerController }) {
|
||||
* discipline and, for cross-country, the technique, then what the piste router
|
||||
* is asked for. A short line says how its legs are laid.
|
||||
*/
|
||||
function SkiFields({ planner }: { planner: TourPlannerController }) {
|
||||
function SkiFields({ planner, locked }: TourTypeFieldsProps) {
|
||||
const { t } = useTranslation();
|
||||
const { choice } = planner.ski;
|
||||
return (
|
||||
@@ -121,7 +121,7 @@ function SkiFields({ planner }: { planner: TourPlannerController }) {
|
||||
{t('tours.ski.plannedHint')}
|
||||
</span>
|
||||
{choice.discipline !== null && (
|
||||
<SkiRouteOptions discipline={choice.discipline} options={choice.options} onChange={planner.ski.setOption} />
|
||||
<SkiRouteOptions discipline={choice.discipline} options={choice.options} onChange={planner.ski.setOption} locked={locked} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -157,7 +157,7 @@ export function TourTypeFields({ planner, locked }: TourTypeFieldsProps) {
|
||||
|
||||
{planner.isRun && <RunFields planner={planner} locked={locked} />}
|
||||
|
||||
{planner.isSki && <SkiFields planner={planner} />}
|
||||
{planner.isSki && <SkiFields planner={planner} locked={locked} />}
|
||||
|
||||
{planner.isPaddle && (
|
||||
<div data-testid="tour-planner-paddle-fields" className="flex min-w-0 flex-col gap-3">
|
||||
|
||||
@@ -47,7 +47,10 @@ export function TourTypeSelect<T extends ImportableTourType = PlannableTourType>
|
||||
const { t } = useTranslation();
|
||||
const valueId = useId();
|
||||
const offered: readonly ImportableTourType[] = types ?? PLANNER_TOUR_TYPES;
|
||||
const list = usePopoverList(offered.indexOf(value), { estimatedHeight: 50 * offered.length + 20 });
|
||||
const list = usePopoverList(offered.indexOf(value), {
|
||||
estimatedHeight: 50 * offered.length + 20,
|
||||
disabled,
|
||||
});
|
||||
const { open, toggle, triggerRef, listId } = list;
|
||||
const label = t('tours.planner.tourType');
|
||||
const pick = (type: T) => {
|
||||
|
||||
@@ -47,6 +47,7 @@ interface SkiRouteOptionsProps {
|
||||
discipline: SkiDiscipline;
|
||||
options: SkiRouteOptionsInput | null | undefined;
|
||||
onChange: (patch: Partial<SkiRouteOptionsInput>) => void;
|
||||
locked?: boolean;
|
||||
}
|
||||
|
||||
/** One switch of the piste router on its own row, its label beside it. */
|
||||
@@ -102,7 +103,7 @@ function LiftClasses({ avoided, onChange }: { avoided: SkiLiftClass[]; onChange:
|
||||
* weigh most for a downhill skier, groomed and lit trails for cross-country,
|
||||
* the lifts for anyone who rides them. Every change plans the tour again.
|
||||
*/
|
||||
export function SkiRouteOptions({ discipline, options, onChange }: SkiRouteOptionsProps) {
|
||||
export function SkiRouteOptions({ discipline, options, onChange, locked }: SkiRouteOptionsProps) {
|
||||
const { t } = useTranslation();
|
||||
const read = new Set(skiOptionsReadBy(discipline));
|
||||
const current: Options = { ...DEFAULT_SKI_ROUTE_OPTIONS, ...options };
|
||||
@@ -119,6 +120,7 @@ export function SkiRouteOptions({ discipline, options, onChange }: SkiRouteOptio
|
||||
<CustomSelect
|
||||
id="tour-planner-ski-difficulty"
|
||||
ariaLabel={t('tours.ski.options.maxDifficulty')}
|
||||
disabled={locked}
|
||||
size="sm"
|
||||
value={current.max_difficulty}
|
||||
onChange={(value) => onChange({ max_difficulty: value as SkiDifficulty })}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { analyzeRouteGeometry } from '../../utils/routeGeometry'
|
||||
import TourListRow from './TourListRow'
|
||||
import { TourPlannerRail, TourPlannerToursRail } from './planner/TourPlannerPanels'
|
||||
import type { TourPlannerController } from './planner/useTourPlanner'
|
||||
import { hikePlannerDefaults } from '../../../tests/helpers/tourPlannerStub'
|
||||
import { hikePlannerDefaults, mockTourEditorLayout } from '../../../tests/helpers/tourPlannerStub'
|
||||
|
||||
vi.mock('../../../../server/src/config', () => { throw new Error('Config initialization is forbidden in client tests') })
|
||||
vi.mock('../../../../server/src/db/database', () => { throw new Error('Legacy database imports are forbidden in client tests') })
|
||||
@@ -151,7 +151,9 @@ describe('Tours English and German copy', () => {
|
||||
}
|
||||
rerender(<TourPlannerRail planner={planner({ mode: { type: 'new-draft' }, status: 'ready', error: 'save' })} />)
|
||||
expect(screen.getByLabelText(toursText(de, 'tours.planner.status.saveFailed'))).toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button', { name: toursText(de, 'tours.planner.maxDifficulty') }))
|
||||
const difficulty = screen.getByRole('button', { name: toursText(de, 'tours.planner.maxDifficulty') })
|
||||
mockTourEditorLayout(difficulty.parentElement ?? difficulty)
|
||||
fireEvent.click(difficulty)
|
||||
fireEvent.click(screen.getByRole('button', { name: toursText(de, 'tours.planner.difficulty.t4') }))
|
||||
expect(screen.getByRole('heading', { name: toursText(de, 'tours.planner.difficulty.alpineTitle') })).toBeInTheDocument()
|
||||
expect(screen.getByText(toursText(de, 'tours.planner.difficulty.alpineBody'))).toBeInTheDocument()
|
||||
@@ -187,4 +189,4 @@ describe('Tours English and German copy', () => {
|
||||
expect(await screen.findByText(toursText(fr, 'tours.planner.neutralTitle'))).toBeInTheDocument()
|
||||
assertNoRawToursKeys()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user