mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
fix(mobile): share the bookings tabs' sections, and fit two tests to the sheets they test
Both bookings tabs built the same status sections; listSections in the shared filter hook now does it once. The photo sort test looks for the sheet in the document, as the sheet is portalled to the body, and the saved place test expects the notes the sheet now sends.
This commit is contained in:
@@ -1,7 +1,20 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import type { Day, Reservation } from '../../../types';
|
||||
import { groupTransports, onTravelers } from './bookingsModel';
|
||||
import { groupTransports, onTravelers, type StatusGroups } from './bookingsModel';
|
||||
|
||||
/**
|
||||
* The status sections both tabs list, in their order, leaving out the empty ones.
|
||||
* Bookings never fill `transit`, so that section only ever shows among transports.
|
||||
*/
|
||||
export function listSections(groups: StatusGroups, t: (key: string) => string) {
|
||||
return [
|
||||
{ id: 'confirmed', label: t('reservations.confirmed'), rows: groups.confirmed },
|
||||
{ id: 'pending', label: t('reservations.pending'), rows: groups.pending },
|
||||
{ id: 'transit', label: t('reservations.type.transit'), rows: groups.transit },
|
||||
{ id: 'past', label: t('reservations.past'), rows: groups.past },
|
||||
].filter((s) => s.rows.length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The traveller filter and the folded sections of the phone's bookings and
|
||||
|
||||
@@ -10,7 +10,7 @@ import { CardGrid, Field, ReservationPluginSlots, SectionHeader, StatusDot, TabS
|
||||
import { STATUS_COLOR, type MTabScreenProps } from './tabModel'
|
||||
import { cardWhen, parseTransportMeta, timeRange } from './transportsModel'
|
||||
import { BOOKING_TYPE_COLOR, hotelStayTimes } from '../../../../components/Planner/bookings/bookingsModel'
|
||||
import { useReservationListFilter } from '../../../../components/Planner/bookings/useReservationListFilter'
|
||||
import { listSections, useReservationListFilter } from '../../../../components/Planner/bookings/useReservationListFilter'
|
||||
import { useReservationCard } from '../../../../components/Planner/bookings/useReservationCard'
|
||||
import { orderedEndpoints, seatCells } from '../../../../utils/flightLegs'
|
||||
import { filesFor } from '../../../../utils/reservationFiles'
|
||||
@@ -33,11 +33,7 @@ export default function MBookingsTab({ planner, shell }: MTabScreenProps) {
|
||||
} = useReservationListFilter(allBookings, days, planner.tripMembers.length)
|
||||
const canEdit = planner.can('reservation_edit', planner.trip)
|
||||
|
||||
const sections = [
|
||||
{ id: 'confirmed', label: t('reservations.confirmed'), rows: groups.confirmed },
|
||||
{ id: 'pending', label: t('reservations.pending'), rows: groups.pending },
|
||||
{ id: 'past', label: t('reservations.past'), rows: groups.past },
|
||||
].filter(s => s.rows.length > 0)
|
||||
const sections = listSections(groups, t)
|
||||
|
||||
return (
|
||||
<TabScroller wide="full">
|
||||
|
||||
@@ -8,7 +8,7 @@ import { CardGrid, Field, ReservationPluginSlots, SectionHeader, StatusDot, TabS
|
||||
import { STATUS_COLOR, type MTabScreenProps } from './tabModel'
|
||||
import { cardWhen, parseTransportMeta } from './transportsModel'
|
||||
import { TRANSPORT_TYPE_COLOR } from '../../../../components/Planner/bookings/bookingsModel'
|
||||
import { useReservationListFilter } from '../../../../components/Planner/bookings/useReservationListFilter'
|
||||
import { listSections, useReservationListFilter } from '../../../../components/Planner/bookings/useReservationListFilter'
|
||||
import { useReservationCard } from '../../../../components/Planner/bookings/useReservationCard'
|
||||
import { orderedEndpoints, seatCells } from '../../../../utils/flightLegs'
|
||||
import { filesFor } from '../../../../utils/reservationFiles'
|
||||
@@ -30,12 +30,7 @@ export default function MTransportsTab({ planner, shell }: MTabScreenProps) {
|
||||
} = useReservationListFilter(allTransports, days, planner.tripMembers.length)
|
||||
const canEdit = planner.can('day_edit', planner.trip)
|
||||
|
||||
const sections = [
|
||||
{ id: 'confirmed', label: t('reservations.confirmed'), rows: groups.confirmed },
|
||||
{ id: 'pending', label: t('reservations.pending'), rows: groups.pending },
|
||||
{ id: 'transit', label: t('reservations.type.transit'), rows: groups.transit },
|
||||
{ id: 'past', label: t('reservations.past'), rows: groups.past },
|
||||
].filter(s => s.rows.length > 0)
|
||||
const sections = listSections(groups, t)
|
||||
|
||||
return (
|
||||
<TabScroller wide="full">
|
||||
|
||||
@@ -204,6 +204,8 @@ describe('MCollPlaceSheet', () => {
|
||||
],
|
||||
category_id: 3,
|
||||
label_ids: [11, 12],
|
||||
// No notes on this place, and none written (#3168).
|
||||
notes: null,
|
||||
}))
|
||||
// Back to the read view.
|
||||
await waitFor(() => expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument())
|
||||
|
||||
@@ -1011,13 +1011,14 @@ describe('MJourneyEntrySheet reading view', () => {
|
||||
|
||||
it('FE-MOB-JENTRY-062: the photos of a saved entry can be dragged into order, a reader cannot move them (#2851)', () => {
|
||||
const entry = buildEntry({ id: 5, photos: [buildPhoto(100), buildPhoto(101)] });
|
||||
const { container, unmount } = mountSheet(entry);
|
||||
expect(container.querySelector('[data-touch-drag]')).not.toBeNull();
|
||||
expect(container.querySelectorAll('[draggable="true"]').length).toBeGreaterThanOrEqual(2);
|
||||
// The sheet is portalled to the body, so the rendered container holds none of it.
|
||||
const { unmount } = mountSheet(entry);
|
||||
expect(document.querySelector('[data-touch-drag]')).not.toBeNull();
|
||||
expect(document.querySelectorAll('[draggable="true"]').length).toBeGreaterThanOrEqual(2);
|
||||
unmount();
|
||||
|
||||
const read = mountSheet(entry, { readOnly: true });
|
||||
expect(read.container.querySelector('[data-touch-drag]')).toBeNull();
|
||||
mountSheet(entry, { readOnly: true });
|
||||
expect(document.querySelector('[data-touch-drag]')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-MOB-JENTRY-061: a viewer without the editor keeps the locked sheet it always had', () => {
|
||||
|
||||
Reference in New Issue
Block a user