mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
feat(mobile): the tour detail edits on an iPad and an unfolded Duo
The phone's tour sheet reads the tour and plans it onto a day. In the wide and split size classes it now edits what the desktop's tour card edits, through the same useTourDetailActions: the name and the colour, a copy saved as a new tour, the recorded tracks, the packing list it points at and its files, for a member who may edit places. The phone is unchanged.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { fireEvent, render, screen } from '../../../../../tests/helpers/render'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { TourListItem } from '@trek/shared'
|
||||
import { buildPlace } from '../../../../../tests/helpers/factories'
|
||||
import { resetAllStores, seedStore } from '../../../../../tests/helpers/store'
|
||||
import { useSettingsStore } from '../../../../store/settingsStore'
|
||||
import type { TripPlanner } from '../MTripShell'
|
||||
import { MSelectedTourDetail } from './MTripSheets'
|
||||
import { _pinSizeClass } from '../../../../hooks/sizeClass'
|
||||
|
||||
const place = buildPlace({
|
||||
id: 42,
|
||||
@@ -58,6 +59,10 @@ function planner(overrides: Partial<TripPlanner> = {}): TripPlanner {
|
||||
} as unknown as TripPlanner
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
_pinSizeClass(null)
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
resetAllStores()
|
||||
vi.clearAllMocks()
|
||||
@@ -108,4 +113,31 @@ describe('MSelectedTourDetail', () => {
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
expect(document.querySelector('#tour-elevation-42')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('FE-MOB-TOURDETAIL-001: the phone reads the tour, with no way to rename it', () => {
|
||||
render(<MSelectedTourDetail planner={planner({ can: vi.fn<TripPlanner['can']>(() => true) })} />)
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-TOURDETAIL-002: an iPad edits the tour as the desktop card does, through the shared actions', async () => {
|
||||
_pinSizeClass('wide')
|
||||
const p = planner({ can: vi.fn<TripPlanner['can']>(() => true) })
|
||||
render(<MSelectedTourDetail planner={p} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
|
||||
const field = screen.getByRole('textbox', { name: 'Name' })
|
||||
fireEvent.change(field, { target: { value: 'Ridge walk long' } })
|
||||
fireEvent.keyDown(field, { key: 'Enter' })
|
||||
|
||||
await vi.waitFor(() => expect(p.tripActions.updatePlace).toHaveBeenCalledWith(7, 42, { name: 'Ridge walk long' }))
|
||||
await vi.waitFor(() => expect(p.reloadTourPlaceIds).toHaveBeenCalled())
|
||||
})
|
||||
|
||||
it('FE-MOB-TOURDETAIL-003: on an iPad a member who may not edit places still only reads', () => {
|
||||
_pinSizeClass('split')
|
||||
render(<MSelectedTourDetail planner={planner()} />)
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,6 +5,8 @@ import TourDetailDialog from '../../../../components/Tours/TourDetailDialog'
|
||||
import { useBookingExpenseEditor } from '../../../../pages/tripPlanner/useBookingExpenseEditor'
|
||||
import { applyTripCoverUpdate } from '../../../../pages/tripPlanner/tripCover'
|
||||
import { latestReservation } from '../../../../pages/tripPlanner/transportEditorOpeners'
|
||||
import { useTourDetailActions } from '../../../../pages/tripPlanner/useTourDetailActions'
|
||||
import { useIsWide } from '../../../../hooks/sizeClass'
|
||||
import MConfirmSheet from '../../settings/MConfirmSheet'
|
||||
import MDayImpactList from '../../../components/MDayImpactList'
|
||||
import MDaySheet from './MDaySheet'
|
||||
@@ -41,11 +43,18 @@ import { useLastOpen } from '../../../../components/shared/usePresence'
|
||||
* The one global mobile tour-detail owner, independent of which surface
|
||||
* selected it. The tour shows in a sheet like every other detail
|
||||
* (MTourDetailShell); it keeps the tour it showed last while it slides away.
|
||||
*
|
||||
* On the phone it reads, and plans the tour onto a day. On an iPad or an
|
||||
* unfolded Duo it edits what the desktop's tour card edits, through the same
|
||||
* useTourDetailActions: the name and colour, a copy saved as a new tour, the
|
||||
* recorded tracks, the packing list it points at and its files.
|
||||
*/
|
||||
export function MSelectedTourDetail({ planner }: Pick<MTripSheetsProps, 'planner'>) {
|
||||
const open = !!(planner.selectedTour && planner.selectedPlace)
|
||||
const tour = useLastOpen(planner.selectedTour, open)
|
||||
const place = useLastOpen(planner.selectedPlace, open)
|
||||
const actions = useTourDetailActions(planner)
|
||||
const canEdit = useIsWide() && planner.can('place_edit', planner.trip)
|
||||
if (!tour || !place) return null
|
||||
|
||||
return (
|
||||
@@ -59,9 +68,11 @@ export function MSelectedTourDetail({ planner }: Pick<MTripSheetsProps, 'planner
|
||||
selectedAssignmentId={planner.selectedAssignmentId}
|
||||
assignments={planner.assignments}
|
||||
files={planner.files}
|
||||
readOnly
|
||||
canEdit={false}
|
||||
{...(canEdit ? actions : {})}
|
||||
readOnly={!canEdit}
|
||||
canEdit={canEdit}
|
||||
canAssign={planner.can('day_edit', planner.trip)}
|
||||
onFileUpload={canEdit && planner.canUploadFiles ? (fd: FormData) => planner.tripActions.addFile(planner.tripId, fd) : undefined}
|
||||
onClose={() => planner.setSelectedPlaceId(null)}
|
||||
onAssignToDay={planner.handleAssignToDay}
|
||||
onRemoveAssignment={planner.handleRemoveAssignment}
|
||||
|
||||
Reference in New Issue
Block a user