mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
0b7cee0b0d
On an iPad or an unfolded foldable the list screens kept one phone-wide column in the middle of the page. They now lay out for the room they have: - Transports, bookings, polls and tasks put their cards in a grid of as many phone-wide columns as the page holds (CardGrid), three on a 13" iPad on its side, two upright, one in a narrow Split View. - Costs: with room for two panes (split size class) the summary (total, owe and owed, settle up, final budget, categories) stands in a pane of its own beside the expenses, each scrolling on its own (TabPanes). The search field sits in the expenses' column again instead of running past it. - Files: a grid of tiles with each photo's picture; with room for two panes the picked file is previewed beside the grid with what it belongs to and its actions, the way Files on an iPad does. The signed preview address comes through fileRepo.previewUrl. - Packing: the categories stand in columns, each card whole in its column; the action menu drops from its button at a popover's width. - To-dos: the four smart filters as tiles and the trip's lists in a pane beside the tasks, which take the filter's name as their head. - Collab: the chat stays in view at the trailing edge beside the notes, links or polls, and the header switches only the board. The chat keeps its place in the tree, so a fold or a rotation into two panes keeps the draft; a chat at its newest message stays there when its box changes size. Notes stand as a board in columns. - Administration and settings share a section list beside the page (MSectionNav); the stats grid takes four columns. - Collections: the lists stand in a column beside the places, which take two columns, and the head names the list on show. - Journal: the entries become a feed beside the map, under their days, with photo, place and the start of the story, in step with the map like the strip of cards it replaces; it fades out under the header. - The assistant opens as a tall panel at the trailing edge over a dimmed page, as Slide Over would, instead of covering the whole screen. - The rail fits every name: a word too wide for it shrinks the label before it is hyphenated, and the admin entry uses its short name. - The journeys and notifications headers keep to their column. - The address screen of the native shell sets the photo as a panel beside the choices on a large screen on its side. On a foldable that reports its fold, a leading pane ends at the fold and a trailing one starts there. Phones keep their layout.
217 lines
9.0 KiB
TypeScript
217 lines
9.0 KiB
TypeScript
// FE-JRN-CAROUSEL-001 to FE-JRN-CAROUSEL-010: the card carousel over the journey map,
|
|
// behind both the phone journey screen and the narrow desktop and public timeline.
|
|
import { act, renderHook } from '@testing-library/react';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import type { JourneyMapHandle } from './JourneyMap';
|
|
import { useJourneyCarouselSync, type JourneyCarouselSyncOptions } from './useJourneyCarouselSync';
|
|
|
|
interface Entry {
|
|
id: number;
|
|
entry_date: string;
|
|
}
|
|
|
|
const ENTRIES: Entry[] = [
|
|
{ id: 1, entry_date: '2026-05-01' },
|
|
{ id: 2, entry_date: '2026-05-01' },
|
|
{ id: 3, entry_date: '2026-05-02' },
|
|
];
|
|
|
|
type Options = JourneyCarouselSyncOptions<Entry>;
|
|
|
|
function setup(over: Partial<Options> = {}) {
|
|
const props: Options = {
|
|
entries: ENTRIES,
|
|
mapEntries: [{ id: '1' }, { id: '3' }],
|
|
onOpenEntry: vi.fn(),
|
|
...over,
|
|
};
|
|
const hook = renderHook((p: Options) => useJourneyCarouselSync(p), { initialProps: props });
|
|
const map = { focusMarker: vi.fn(), highlightMarker: vi.fn(), invalidateSize: vi.fn() };
|
|
(hook.result.current.mapRef as { current: JourneyMapHandle | null }).current = map as unknown as JourneyMapHandle;
|
|
const cards = ENTRIES.map((_, i) => {
|
|
const node = document.createElement('div');
|
|
node.scrollIntoView = vi.fn();
|
|
node.getBoundingClientRect = () => ({ left: i * 100, width: 100 }) as DOMRect;
|
|
hook.result.current.cardRefs.current.set(i, node);
|
|
return node;
|
|
});
|
|
return { ...hook, props, map, cards };
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
describe('useJourneyCarouselSync', () => {
|
|
it('FE-JRN-CAROUSEL-001: groups the scrubber days by date', () => {
|
|
const { result } = setup();
|
|
expect(result.current.scrubberDays.map((d) => d.date)).toEqual(['2026-05-01', '2026-05-02']);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-002: the map focuses a card with a marker and clears the highlight for one without', () => {
|
|
const { result, map } = setup();
|
|
result.current.syncMapToCard(2);
|
|
expect(map.focusMarker).toHaveBeenCalledWith('3');
|
|
result.current.syncMapToCard(1);
|
|
expect(map.highlightMarker).toHaveBeenCalledWith(null);
|
|
result.current.syncMapToCard(9);
|
|
expect(map.focusMarker).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-003: a map that is not ready yet is ignored', () => {
|
|
const { result, map } = setup();
|
|
map.focusMarker.mockImplementation(() => {
|
|
throw new Error('not ready');
|
|
});
|
|
expect(() => result.current.syncMapToCard(0)).not.toThrow();
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-004: a marker brings its card to the centre', () => {
|
|
const { result, cards } = setup();
|
|
act(() => result.current.handleMarkerClick('3'));
|
|
expect(result.current.activeIndex).toBe(2);
|
|
expect(cards[2].scrollIntoView).toHaveBeenCalledWith({ behavior: 'smooth', inline: 'center', block: 'nearest' });
|
|
act(() => result.current.handleMarkerClick('99'));
|
|
expect(result.current.activeIndex).toBe(2);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-005: a tap opens the active card and centres another, moving the map only on the phone', () => {
|
|
const desktop = setup();
|
|
act(() => desktop.result.current.handleCardTap(ENTRIES[0], 0));
|
|
expect(desktop.props.onOpenEntry).toHaveBeenCalledWith(ENTRIES[0]);
|
|
act(() => desktop.result.current.handleCardTap(ENTRIES[2], 2));
|
|
expect(desktop.result.current.activeIndex).toBe(2);
|
|
expect(desktop.map.focusMarker).not.toHaveBeenCalled();
|
|
|
|
const phone = setup({ syncMapOnTap: true });
|
|
act(() => phone.result.current.handleCardTap(ENTRIES[2], 2));
|
|
expect(phone.map.focusMarker).toHaveBeenCalledWith('3');
|
|
expect(phone.props.onOpenEntry).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-006: a day on the scrubber lands on its first entry', () => {
|
|
const { result, map, cards } = setup();
|
|
act(() => result.current.jumpToDay('2026-05-02'));
|
|
expect(result.current.activeIndex).toBe(2);
|
|
expect(map.focusMarker).toHaveBeenCalledWith('3');
|
|
expect(cards[2].scrollIntoView).toHaveBeenCalled();
|
|
act(() => result.current.jumpToDay('2030-01-01'));
|
|
expect(result.current.activeIndex).toBe(2);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-007: once scrolling settles the card nearest the centre becomes active', () => {
|
|
const carousel = document.createElement('div');
|
|
carousel.getBoundingClientRect = () => ({ left: 0 }) as DOMRect;
|
|
Object.defineProperty(carousel, 'clientWidth', { value: 500 });
|
|
const hook = renderHook(
|
|
(p: Options) => {
|
|
const sync = useJourneyCarouselSync(p);
|
|
(sync.carouselRef as { current: HTMLDivElement | null }).current = carousel;
|
|
return sync;
|
|
},
|
|
{ initialProps: { entries: [], mapEntries: [{ id: '3' }], onOpenEntry: vi.fn() } }
|
|
);
|
|
const map = { focusMarker: vi.fn(), highlightMarker: vi.fn(), invalidateSize: vi.fn() };
|
|
(hook.result.current.mapRef as { current: JourneyMapHandle | null }).current = map as unknown as JourneyMapHandle;
|
|
// The listener attaches once there are cards.
|
|
hook.rerender({ entries: ENTRIES, mapEntries: [{ id: '3' }], onOpenEntry: vi.fn() });
|
|
ENTRIES.forEach((_, i) => {
|
|
const node = document.createElement('div');
|
|
node.getBoundingClientRect = () => ({ left: i * 200, width: 100 }) as DOMRect;
|
|
hook.result.current.cardRefs.current.set(i, node);
|
|
});
|
|
|
|
carousel.dispatchEvent(new Event('scroll'));
|
|
act(() => vi.advanceTimersByTime(60));
|
|
carousel.dispatchEvent(new Event('scroll'));
|
|
act(() => vi.advanceTimersByTime(89));
|
|
expect(hook.result.current.activeIndex).toBe(0);
|
|
act(() => vi.advanceTimersByTime(1));
|
|
// Centre 250: card 1 spans 200 to 300.
|
|
expect(hook.result.current.activeIndex).toBe(1);
|
|
expect(map.highlightMarker).toHaveBeenCalledWith(null);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-008: a marker card opens its entry by id, wherever the carousel stands (#2885)', () => {
|
|
const { result, props } = setup();
|
|
act(() => result.current.openEntryById('3'));
|
|
expect(props.onOpenEntry).toHaveBeenCalledWith(ENTRIES[2]);
|
|
expect(result.current.activeIndex).toBe(0);
|
|
act(() => result.current.openEntryById('99'));
|
|
expect(props.onOpenEntry).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-009: a carousel scrolled to either end settles on the card at that end (#2851)', () => {
|
|
const carousel = document.createElement('div');
|
|
carousel.getBoundingClientRect = () => ({ left: 0 }) as DOMRect;
|
|
Object.defineProperty(carousel, 'clientWidth', { value: 300 });
|
|
Object.defineProperty(carousel, 'scrollWidth', { value: 600 });
|
|
const hook = renderHook(
|
|
(p: Options) => {
|
|
const sync = useJourneyCarouselSync(p);
|
|
(sync.carouselRef as { current: HTMLDivElement | null }).current = carousel;
|
|
return sync;
|
|
},
|
|
{ initialProps: { entries: [], mapEntries: [], onOpenEntry: vi.fn() } }
|
|
);
|
|
hook.rerender({ entries: ENTRIES, mapEntries: [], onOpenEntry: vi.fn() });
|
|
// Card 1 sits at the centre (150) in both positions: only the ends decide.
|
|
[0, 100, 200].forEach((left, i) => {
|
|
const node = document.createElement('div');
|
|
node.getBoundingClientRect = () => ({ left, width: 100 }) as DOMRect;
|
|
hook.result.current.cardRefs.current.set(i, node);
|
|
});
|
|
const settleAt = (scrollLeft: number) => {
|
|
Object.defineProperty(carousel, 'scrollLeft', { value: scrollLeft, configurable: true });
|
|
carousel.dispatchEvent(new Event('scroll'));
|
|
act(() => {
|
|
vi.advanceTimersByTime(90);
|
|
});
|
|
};
|
|
|
|
settleAt(300);
|
|
expect(hook.result.current.activeIndex).toBe(2);
|
|
settleAt(150);
|
|
expect(hook.result.current.activeIndex).toBe(1);
|
|
// Right to left: the scroll position runs negative from the start.
|
|
settleAt(-300);
|
|
expect(hook.result.current.activeIndex).toBe(2);
|
|
settleAt(0);
|
|
expect(hook.result.current.activeIndex).toBe(0);
|
|
});
|
|
|
|
it('FE-JRN-CAROUSEL-010: a strip that comes back (the feed on a wide window gave way to it) is tracked again', () => {
|
|
const carousel = document.createElement('div');
|
|
carousel.getBoundingClientRect = () => ({ left: 0 }) as DOMRect;
|
|
Object.defineProperty(carousel, 'clientWidth', { value: 500 });
|
|
let strip: HTMLDivElement | null = null;
|
|
const hook = renderHook(
|
|
(p: Options) => {
|
|
const sync = useJourneyCarouselSync(p);
|
|
(sync.carouselRef as { current: HTMLDivElement | null }).current = strip;
|
|
return sync;
|
|
},
|
|
{ initialProps: { entries: ENTRIES, mapEntries: [], onOpenEntry: vi.fn(), layoutKey: true } }
|
|
);
|
|
ENTRIES.forEach((_, i) => {
|
|
const node = document.createElement('div');
|
|
node.getBoundingClientRect = () => ({ left: i * 200, width: 100 }) as DOMRect;
|
|
hook.result.current.cardRefs.current.set(i, node);
|
|
});
|
|
|
|
// The strip mounts with the layout's turn, with the same entries as before.
|
|
strip = carousel;
|
|
hook.rerender({ entries: ENTRIES, mapEntries: [], onOpenEntry: vi.fn(), layoutKey: false });
|
|
carousel.dispatchEvent(new Event('scroll'));
|
|
act(() => {
|
|
vi.advanceTimersByTime(90);
|
|
});
|
|
expect(hook.result.current.activeIndex).toBe(1);
|
|
});
|
|
});
|