mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
b41f6e3542
The public journey page on a phone shows the map with a card carousel, which always opened on the first entry. The owner's "newest first" choice for the link was ignored there, so readers following a running trip had to swipe through every day to reach the latest one (discussion #2851). The rule for where a journey opens moves out of the journal hook into journeyOpenAtEntryId, which the public page now uses as well: a newest-first link opens on the latest day, otherwise a running journey opens on today as the journal already does. The carousel also settles on the card at the end it is scrolled to. The last card can never reach the centre, so opening on the latest day used to activate the day before it, in the journal as well.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
// FE-JRN-OPENAT-001 to FE-JRN-OPENAT-005
|
|
import { describe, expect, it } from 'vitest';
|
|
import { journeyOpenAtEntryId } from './journeyOpenAt';
|
|
|
|
const entries = [
|
|
{ id: 3, entry_date: '2026-05-03' },
|
|
{ id: 1, entry_date: '2026-05-01' },
|
|
{ id: 2, entry_date: '2026-05-01' },
|
|
{ id: 5, entry_date: '2026-05-05' },
|
|
];
|
|
|
|
describe('journeyOpenAtEntryId', () => {
|
|
it('FE-JRN-OPENAT-001: a running journey opens on the first entry of today', () => {
|
|
expect(journeyOpenAtEntryId(entries, { today: '2026-05-03' })).toBe('3');
|
|
});
|
|
|
|
it('FE-JRN-OPENAT-002: a rest day lands on the last day written before it', () => {
|
|
expect(journeyOpenAtEntryId(entries, { today: '2026-05-04' })).toBe('3');
|
|
});
|
|
|
|
it('FE-JRN-OPENAT-003: a journey that is over, or not begun, opens at its start', () => {
|
|
expect(journeyOpenAtEntryId(entries, { today: '2026-06-01' })).toBeNull();
|
|
expect(journeyOpenAtEntryId(entries, { today: '2026-04-01' })).toBeNull();
|
|
});
|
|
|
|
it('FE-JRN-OPENAT-004: newest-first opens on the latest day, also after the trip', () => {
|
|
expect(journeyOpenAtEntryId(entries, { today: '2026-06-01', newestFirst: true })).toBe('5');
|
|
expect(journeyOpenAtEntryId(entries, { today: '2026-05-03', newestFirst: true })).toBe('5');
|
|
});
|
|
|
|
it('FE-JRN-OPENAT-005: an empty journey has nothing to open on', () => {
|
|
expect(journeyOpenAtEntryId([], { today: '2026-05-03', newestFirst: true })).toBeNull();
|
|
});
|
|
});
|