Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

test: bring the packing, todo and dashboard changes in line with the CI gates

Mauricea65342574abd
diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json
index a6e2971fb..0fee320d2 100644
--- a/client/scripts/eslint-baseline.json
+++ b/client/scripts/eslint-baseline.json
@@ -1,20 +1,20 @@
{
"src": {
- "@typescript-eslint/no-non-null-assertion": 375,
- "@typescript-eslint/no-misused-promises": 838,
+ "@typescript-eslint/no-non-null-assertion": 368,
+ "@typescript-eslint/no-misused-promises": 820,
"no-console": 88,
"complexity": 217,
"@typescript-eslint/no-explicit-any": 143,
"trek/no-swallowed-catch": 128,
"max-params": 31,
- "trek/store-without-selector": 67,
- "react-hooks/refs": 553,
- "react-hooks/set-state-in-effect": 192,
- "@typescript-eslint/no-floating-promises": 163,
+ "trek/store-without-selector": 66,
+ "react-hooks/refs": 534,
+ "react-hooks/set-state-in-effect": 189,
+ "@typescript-eslint/no-floating-promises": 162,
"react-hooks/exhaustive-deps": 113,
"@typescript-eslint/no-unused-vars": 122,
"react-hooks/immutability": 28,
- "max-lines-per-function": 128,
+ "max-lines-per-function": 127,
"react-hooks/static-components": 50,
"react-hooks/preserve-manual-memoization": 12,
"no-useless-assignment": 7,
@@ -31,11 +31,11 @@
},
"suppressed": {
"@typescript-eslint/no-explicit-any": 38,
- "react-hooks/exhaustive-deps": 45
+ "react-hooks/exhaustive-deps": 44
},
"tests": {
"@typescript-eslint/no-explicit-any": 489,
- "@typescript-eslint/no-non-null-assertion": 1905,
+ "@typescript-eslint/no-non-null-assertion": 1877,
"@typescript-eslint/no-misused-promises": 22,
"@typescript-eslint/no-unused-vars": 51,
"@typescript-eslint/no-floating-promises": 33,
diff --git a/client/scripts/strict-baseline.json b/client/scripts/strict-baseline.json
index 45fe004df..5e95cff2c 100644
--- a/client/scripts/strict-baseline.json
+++ b/client/scripts/strict-baseline.json
@@ -44,7 +44,6 @@
"src/components/Map/transitGeometry.ts": 1,
"src/components/Map/useMarkerThumbs.ts": 1,
"src/components/PDF/TripPDF.tsx": 38,
- "src/components/Packing/PackingListPanelItemRow.test.tsx": 2,
"src/components/Planner/DayPlanSidebar.constants.ts": 1,
"src/components/Planner/DayPlanSidebar.tsx": 52,
"src/components/Planner/DayPlanSidebarNoteModal.test.tsx": 1,
diff --git a/client/src/components/Packing/PackingItemDetail.test.tsx b/client/src/components/Packing/PackingItemDetail.test.tsx
index 952ed6474..f20b44d44 100644
--- a/client/src/components/Packing/PackingItemDetail.test.tsx
+++ b/client/src/components/Packing/PackingItemDetail.test.tsx
@@ -15,7 +15,10 @@ import type { TripMember } from './usePackingListPanel';
type Props = ComponentProps<typeof PackingItemDetail>;
-const toastSpy = vi.fn((_message: string, _type?: string, _duration?: number) => 0);
+const toastError = vi.hoisted(() => vi.fn());
+vi.mock('../shared/Toast', () => ({
+ useToast: () => ({ success: vi.fn(), error: toastError, info: vi.fn(), warning: vi.fn() }),
+}));
const MEMBERS = [
{ id: 1, username: 'owner' },
{ id: 2, username: 'alice' },
@@ -75,14 +78,12 @@ function capturePut() {
beforeEach(() => {
resetAllStores();
- toastSpy.mockClear();
- window.__addToast = toastSpy;
+ toastError.mockClear();
seedStore(useAuthStore, { user: buildUser({ id: 1 }), isAuthenticated: true });
seedStore(useTripStore, { trip: buildTrip({ id: 1 }), packingItems: [buildPackingItem({ id: 1, name: 'Tent' })] });
});
afterEach(() => {
- delete window.__addToast;
vi.restoreAllMocks();
});
@@ -115,7 +116,7 @@ describe('PackingItemDetail — name and list', () => {
const input = dialog.getByRole('textbox', { name: 'Rename' });
fireEvent.change(input, { target: { value: 'Tarp' } });
fireEvent.blur(input);
- await waitFor(() => expect(toastSpy).toHaveBeenCalledWith('Failed to save', 'error', undefined));
+ await waitFor(() => expect(toastError).toHaveBeenCalledWith('Failed to save'));
});
it('FE-PACKDETAIL-004: the List choice moves the item and leaves the current list alone', async () => {
diff --git a/client/src/components/Packing/PackingItemDetail.tsx b/client/src/components/Packing/PackingItemDetail.tsx
index 6894e525b..c87d6c102 100644
--- a/client/src/components/Packing/PackingItemDetail.tsx
+++ b/client/src/components/Packing/PackingItemDetail.tsx
@@ -488,6 +488,24 @@ function Amounts({
);
}
+/** Which of the people sections the window shows, and with which handlers. */
+function sectionsFor({
+ item,
+ canEdit,
+ tripMembers,
+ currentUserId,
+ onSetSharing,
+ onClone,
+ onJoin,
+ onLeave,
+}: Readonly<PackingItemDetailProps>) {
+ const { isCommon, isOwner, sharedToMe, canClone } = packingItemAccess(item, currentUserId);
+ const bringers = canEdit && isCommon && onJoin && onLeave && tripMembers.length > 0 ? { onJoin, onLeave } : null;
+ const sharing = canEdit && isOwner && onSetSharing ? onSetSharing : null;
+ const clone = canEdit && canClone && onClone ? onClone : null;
+ return { bringers, sharing, sharedToMe, clone };
+}
+
/**
* Everything about one packing item in one small window at its row: which list,
* how many and how many are packed, weight and bag, who brings it and who sees
@@ -507,10 +525,6 @@ export function PackingItemDetail(props: Readonly<PackingItemDetailProps>) {
onCreateBag,
tripMembers,
currentUserId,
- onSetSharing,
- onClone,
- onJoin,
- onLeave,
onDelete,
} = props;
const { t } = useTranslation();
@@ -526,10 +540,7 @@ export function PackingItemDetail(props: Readonly<PackingItemDetailProps>) {
toast.error(t('packing.toast.saveError'));
}
};
- const { isCommon, isOwner, sharedToMe, canClone } = packingItemAccess(item, currentUserId);
- const bringers = canEdit && isCommon && onJoin && onLeave && tripMembers.length > 0 ? { onJoin, onLeave } : null;
- const sharing = canEdit && isOwner && onSetSharing ? onSetSharing : null;
- const clone = canEdit && canClone && onClone ? onClone : null;
+ const { bringers, sharing, sharedToMe, clone } = sectionsFor(props);
return createPortal(
<>
diff --git a/client/src/components/Packing/PackingListPanelItemRow.test.tsx b/client/src/components/Packing/PackingListPanelItemRow.test.tsx
index eb9c06f89..f2f45dd02 100644
--- a/client/src/components/Packing/PackingListPanelItemRow.test.tsx
+++ b/client/src/components/Packing/PackingListPanelItemRow.test.tsx
@@ -95,7 +95,7 @@ describe('ArtikelZeile — at rest', () => {
const { container } = setup({ item: buildPackingItem({ id: 1, name: 'Socks', quantity: 5, packed_quantity: 2 } as Partial<PackingItem>) })
expect(screen.getByText('2/5')).toBeInTheDocument()
expect(screen.queryByText('×5')).toBeNull()
- expect(container.querySelector<HTMLElement>('.packing-check')!.style.borderColor).toBe('var(--accent)')
+ expect(container.querySelector<HTMLElement>('.packing-check')?.getAttribute('style')).toContain('solid var(--accent)')
})
it('FE-W5ROW-006: hovering brings up the chevron, leaving puts it away', () => {
@@ -161,7 +161,9 @@ describe('ArtikelZeile — badges', () => {
expect(badge).toHaveTextContent('B+1')
fireEvent.mouseEnter(badge)
const rows = within(await screen.findByRole('tooltip')).getAllByRole('listitem')
- expect(rows.map(r => r.textContent)).toEqual(['Bob', 'cleo'])
+ expect(rows).toHaveLength(2)
+ expect(rows[0]).toHaveTextContent('Bob')
+ expect(rows[1]).toHaveTextContent('cleo')
})
it('FE-W5ROW-012: co-bringers alone still show, without an owner', () => {
@@ -169,7 +171,7 @@ describe('ArtikelZeile — badges', () => {
item: buildPackingItem({ id: 1, name: 'Stove', is_private: 0, owner_id: null, owner_username: null, contributors: [{ user_id: 2, username: 'alice' }] } as unknown as Partial<PackingItem>),
tripMembers: MEMBERS,
})
- expect(screen.getByLabelText('brought by alice')).toHaveTextContent(/^A$/)
+ expect(screen.getByLabelText('brought by alice')).toHaveTextContent(/^a$/i)
})
it('FE-W5ROW-013: a private item shows no bringer faces', () => {
diff --git a/client/src/components/Packing/PackingListPanelViewTabs.tsx b/client/src/components/Packing/PackingListPanelViewTabs.tsx
index ba3aaef8a..906db9edc 100644
--- a/client/src/components/Packing/PackingListPanelViewTabs.tsx
+++ b/client/src/components/Packing/PackingListPanelViewTabs.tsx
@@ -8,7 +8,7 @@ import type { PackingState } from './usePackingListPanel'
* Lists menu, so the row asks one question and answers one.
*/
export function PackingViewTabs(S: PackingState) {
- const { view, setView, t, items, abgehakt, viewTotal, fortschritt } = S
+ const { view, setView, t, items, abgehakt, viewTotal, fortschritt, inlineHeader } = S
const commonCount = items.filter(i => !i.is_private).length
const personalCount = items.filter(i => !!i.is_private).length
@@ -39,7 +39,8 @@ export function PackingViewTabs(S: PackingState) {
{viewPill('common', <Users size={14} />, t('packing.viewCommon'), commonCount)}
{viewPill('personal', <UserRound size={14} />, t('packing.viewPersonal'), personalCount)}
</div>
- {viewTotal > 0 && (
+ {/* The standalone panel says it in its own header already. */}
+ {!inlineHeader && viewTotal > 0 && (
<div className="ms-auto inline-flex items-center gap-2.5 text-caption tabular-nums text-content-muted">
{fortschritt === 100 ? (
<span className="inline-flex items-center gap-1.5 font-semibold text-success"><CheckCheck size={14} strokeWidth={2.5} />{t('packing.allPacked')}</span>
diff --git a/client/src/components/shared/dialogFocus.test.ts b/client/src/components/shared/dialogFocus.test.ts
deleted file mode 100644
index ece940a41..000000000
--- a/client/src/components/shared/dialogFocus.test.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { afterEach, describe, expect, it, vi } from 'vitest';
-import { focusDialog } from './dialogFocus';
-
-function panelWith(html: string): HTMLElement {
- const panel = document.createElement('div');
- panel.tabIndex = -1;
- panel.innerHTML = html;
- document.body.appendChild(panel);
- return panel;
-}
-
-describe('focusDialog', () => {
- const realMatchMedia = window.matchMedia;
- afterEach(() => {
- window.matchMedia = realMatchMedia;
- document.body.innerHTML = '';
- });
-
- const desktop = () => {
- Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: 1400 });
- window.matchMedia = vi
- .fn()
- .mockImplementation((q: string) => ({
- matches: q.includes('pointer: fine'),
- media: q,
- addEventListener: vi.fn(),
- removeEventListener: vi.fn(),
- })) as unknown as typeof window.matchMedia;
- };
-
- it('FE-DIALOGFOCUS-001: on a desktop the first text field takes the focus', () => {
- desktop();
- const panel = panelWith('<input id="a" type="text"><input id="b" type="text">');
- focusDialog(panel);
- expect(document.activeElement?.id).toBe('a');
- });
-
- it('FE-DIALOGFOCUS-002: a field marked as the start wins over the first one', () => {
- desktop();
- const panel = panelWith('<input id="a" type="text"><input id="b" type="text" data-initial-focus>');
- focusDialog(panel);
- expect(document.activeElement?.id).toBe('b');
- });
-
- it('FE-DIALOGFOCUS-003: a focus already inside stays where it is', () => {
- desktop();
- const panel = panelWith('<input id="a" type="text"><input id="b" type="text" data-initial-focus>');
- (panel.querySelector('#a') as HTMLElement).focus();
- focusDialog(panel);
- expect(document.activeElement?.id).toBe('a');
- });
-});
diff --git a/client/src/components/shared/dialogFocus.test.tsx b/client/src/components/shared/dialogFocus.test.tsx
index 55e70178e..27cc05d36 100644
--- a/client/src/components/shared/dialogFocus.test.tsx
+++ b/client/src/components/shared/dialogFocus.test.tsx
@@ -1,10 +1,10 @@
-// FE-SHARED-DIALOGFOCUS-001 to FE-SHARED-DIALOGFOCUS-009
+// FE-SHARED-DIALOGFOCUS-001 to FE-SHARED-DIALOGFOCUS-010
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useState } from 'react'
import { render, screen, fireEvent } from '../../../tests/helpers/render'
import { DialogShell } from './DialogShell'
import Modal from './Modal'
-import { firstTextField } from './dialogFocus'
+import { firstTextField, focusDialog } from './dialogFocus'
/** A desktop with a mouse: the only case the first field takes the focus. */
function asDesktop() {
@@ -138,4 +138,18 @@ describe('Modal focus (#1302)', () => {
fireEvent.keyDown(save, { key: 'Tab' })
expect(screen.getByRole('button', { name: 'Close' })).toHaveFocus()
})
+
+ it('FE-SHARED-DIALOGFOCUS-010: a field marked as the start wins over the first one, a focus inside stays', () => {
+ restore = asDesktop()
+ const panel = document.createElement('div')
+ panel.tabIndex = -1
+ panel.innerHTML = '<input id="first" type="text"><input id="start" type="text" data-initial-focus>'
+ document.body.appendChild(panel)
+ focusDialog(panel)
+ expect(document.activeElement?.id).toBe('start')
+ ;(panel.querySelector('#first') as HTMLElement).focus()
+ focusDialog(panel)
+ expect(document.activeElement?.id).toBe('first')
+ panel.remove()
+ })
})
diff --git a/client/src/mobile/screens/trip/tabs/MTodoListTab.tsx b/client/src/mobile/screens/trip/tabs/MTodoListTab.tsx
index faa654509..1147a8a0f 100644
--- a/client/src/mobile/screens/trip/tabs/MTodoListTab.tsx
+++ b/client/src/mobile/screens/trip/tabs/MTodoListTab.tsx
@@ -101,7 +101,7 @@ export default function MTodoListTab({ planner }: { planner: TripPlanner }) {
<div className="flex items-center gap-[10px] rounded-2xl border border-m-rowbr bg-m-sheetop px-[14px] py-[12px]">
<div className="min-w-0 flex-1">
<div className="text-caption font-semibold tabular-nums text-m-ink">
- {items.length > 0 && pct === 100 ? t('todo.allDone') : t('todo.progressCount', { done: counts.done, total: items.length })}
+ {progressLabel(t, counts.done, items.length)}
</div>
<div className="mt-[7px] h-[5px] overflow-hidden rounded-full bg-m-ic">
<div className="h-full rounded-full bg-m-act" style={{ width: `${pct}%` }} />
@@ -249,6 +249,11 @@ export default function MTodoListTab({ planner }: { planner: TripPlanner }) {
)
}
+/** How far the list has come, in words: done once every task is. */
+function progressLabel(t: TripPlanner['t'], done: number, total: number): string {
+ return total > 0 && done === total ? t('todo.allDone') : t('todo.progressCount', { done, total })
+}
+
function OptionRow({ icon, label, count, on, onClick }: Readonly<{ icon?: ReactNode; label: string; count?: number; on: boolean; onClick: () => void }>) {
return (
<button type="button" onClick={onClick} aria-pressed={on}
diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx
index c202b873e..245fed2d2 100644
--- a/client/src/pages/DashboardPage.tsx
+++ b/client/src/pages/DashboardPage.tsx
@@ -761,6 +761,7 @@ function UpcomingTool({ items, locale, onOpen }: {
const timeStr = parsed.time ? formatTime(parsed.time, locale, timeFormat) : null
const typeClass = RES_TYPE_CLASS[r.type] || 'other'
const moment = MOMENT_LABEL[r.type]
+ const where = moment ? t(moment) : (r.location || r.place_name || r.trip_title)
return (
<div className="upc-item" key={upcomingKey(r)} onClick={() => onOpen(r.trip_id)}
role="button" data-no-press tabIndex={0}
@@ -772,9 +773,7 @@ function UpcomingTool({ items, locale, onOpen }: {
</div>
<div className="s">
{timeStr && <span className="upc-chip"><Clock size={11} />{timeStr}</span>}
- {(moment || r.location || r.place_name || r.trip_title) && (
- <span className="upc-chip"><span className="upc-chip-text">{moment ? t(moment) : (r.location || r.place_name || r.trip_title)}</span></span>
- )}
+ {where && <span className="upc-chip"><span className="upc-chip-text">{where}</span></span>}
</div>
</div>
<div className={`upc-type ${typeClass}`}>
diff --git a/client/src/pages/TripPlannerPage.wiring.test.tsx b/client/src/pages/TripPlannerPage.wiring.test.tsx
index a5e9986f3..ad37e2afd 100644
--- a/client/src/pages/TripPlannerPage.wiring.test.tsx
+++ b/client/src/pages/TripPlannerPage.wiring.test.tsx
@@ -1458,6 +1458,7 @@ describe('TripPlannerPage — lists tab', () => {
renderPage({ activeTab: 'listen', packingItems: [buildPackingItem({ checked: 0 })] })
await screen.findByTestId('packing-list-panel')
+ openListsMenu()
fireEvent.click(screen.getByRole('button', { name: /Save as template/i }))
expect(props('packingPanel').saveTemplateSignal).toBe(1)
})
@@ -1466,6 +1467,7 @@ describe('TripPlannerPage — lists tab', () => {
renderPage({ activeTab: 'listen', packingItems: [buildPackingItem({ checked: 0 })] })
await screen.findByTestId('packing-list-panel')
+ openListsMenu()
expect(screen.queryByRole('button', { name: /Save as template/i })).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: /Import/i }))
expect(props('packingPanel').openImportSignal).toBe(1)
@@ -1480,7 +1482,7 @@ describe('TripPlannerPage — lists tab', () => {
expect(props('applyTemplate').visibility).toBe('personal')
})
- it('FE-PAGE-TPW-044b: export and import sit in the header as icons, export following the open view (#875, #1420)', async () => {
+ it('FE-PAGE-TPW-044b: export and import sit in the Lists menu, export following the open view (#875, #1420)', async () => {
renderPage({ activeTab: 'listen', packingItems: [buildPackingItem({ checked: 0 })] })
await screen.findByTestId('packing-list-panel')
@@ -1490,12 +1492,18 @@ describe('TripPlannerPage — lists tab', () => {
act(() => { props('packingPanel').onViewChange('personal') })
expect(props('exportMenu').view).toBe('personal')
- const importButton = screen.getByRole('button', { name: 'Import' })
- expect(importButton).toHaveAttribute('title', 'Import')
- expect(importButton).toHaveTextContent('')
+ expect(props('exportMenu').variant).toBe('menu')
+ openListsMenu()
+ expect(screen.getByRole('button', { name: 'Import' })).toBeInTheDocument()
})
})
+/** The Lists bar's "..." beside Add list, which holds templates, import and export. */
+function openListsMenu() {
+ const trigger = screen.getAllByRole('button', { name: 'Show more' }).find(b => b.getAttribute('aria-haspopup') === 'menu')
+ if (trigger) fireEvent.click(trigger)
+}
+
describe('TripPlannerPage — modals', () => {
it('FE-PAGE-TPW-045: closing the place form clears every editing slot', () => {
renderPage()