mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
feat(native): pick the trip a widget shows in Edit Widget
Widgets followed the dashboard's trip only, which is the one under way, so a packing list or to-dos for a trip still being planned could not sit on the home screen. The trip, today, bookings, to-dos, packing and group widgets now take a trip in Edit Widget (an AppIntent with the trips running or ahead, Automatic by default, which keeps following the dashboard); the world map needs none. - The app writes a snapshot per trip running or ahead (at most six, the dashboard's order) and the list to pick from, under their own keys (feature widgetTrips, so an older binary never mistakes one for the dashboard's); bags, chat and polls are kept ten minutes, covers per trip - The widget extension targets iOS 17, which configurable widgets need; the apps are not released, so no installed widget goes away - The choices and their texts in the 28 languages of the gallery
This commit is contained in:
@@ -13,7 +13,15 @@ vi.mock('./trekShell', () => ({
|
||||
}));
|
||||
|
||||
import { TrekShell } from './trekShell';
|
||||
import { buildSnapshot, pickTrip, publishWidgets, todayOf, tripDayState, withBookings } from './widgets';
|
||||
import {
|
||||
buildSnapshot,
|
||||
pickTrip,
|
||||
publishWidgets,
|
||||
todayOf,
|
||||
tripDayState,
|
||||
widgetTripChoices,
|
||||
withBookings,
|
||||
} from './widgets';
|
||||
|
||||
const trip = (id: number, start: string | null, end: string | null, archived = 0) =>
|
||||
({ id, title: `Trip ${id}`, start_date: start, end_date: end, is_archived: archived }) as unknown as Trip;
|
||||
@@ -220,3 +228,28 @@ describe('the richer snapshot', () => {
|
||||
expect(snapshot).not.toHaveProperty('packing');
|
||||
});
|
||||
});
|
||||
|
||||
describe('widgets set to a trip', () => {
|
||||
it('offers the trips running or ahead, in the dashboard order, at most six', () => {
|
||||
const trips = [
|
||||
trip(1, '2026-01-01', '2026-01-05'),
|
||||
trip(2, '2026-12-01', '2026-12-05'),
|
||||
trip(3, '2026-11-04', '2026-11-12'),
|
||||
trip(4, '2026-11-20', '2026-11-22', 1),
|
||||
trip(5, null, null),
|
||||
...[6, 7, 8, 9, 10, 11].map((id) => trip(id, `2027-0${id - 5}-01`, `2027-0${id - 5}-03`)),
|
||||
];
|
||||
expect(widgetTripChoices(trips, '2026-11-06').map((t) => t.id)).toEqual([3, 2, 6, 7, 8, 9]);
|
||||
});
|
||||
|
||||
it('writes each trip under its own key and the list to pick from', async () => {
|
||||
vi.mocked(TrekShell.setWidgetSnapshot).mockClear();
|
||||
const snapshot = buildSnapshot(trip(2, '2026-12-01', '2026-12-05'), null, labels);
|
||||
await publishWidgets(snapshot, null, [
|
||||
{ id: 2, title: 'Trip 2', start: '2026-12-01', end: '2026-12-05', snapshot },
|
||||
]);
|
||||
const calls = vi.mocked(TrekShell.setWidgetSnapshot).mock.calls.map(([options]) => options);
|
||||
expect(calls.map((c) => c.key)).toEqual([undefined, 'trip.2', 'trips']);
|
||||
expect(JSON.parse(calls[2].json)).toEqual([{ id: 2, title: 'Trip 2', start: '2026-12-01', end: '2026-12-05' }]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user