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.

fix(collections): let the phone dock add a place inside a list

Mauricea234653b2921
diff --git a/client/src/mobile/components/MBottomNav.test.tsx b/client/src/mobile/components/MBottomNav.test.tsx
new file mode 100644
index 000000000..6aacfb4dd
--- /dev/null
+++ b/client/src/mobile/components/MBottomNav.test.tsx
@@ -0,0 +1,100 @@
+// FE-COMP-MBOTTOMNAV-001 to FE-COMP-MBOTTOMNAV-007
+
+vi.mock('../../api/websocket', () => ({
+ connect: vi.fn(),
+ disconnect: vi.fn(),
+ getSocketId: vi.fn(() => null),
+ setRefetchCallback: vi.fn(),
+ setPreReconnectHook: vi.fn(),
+ addListener: vi.fn(),
+ removeListener: vi.fn(),
+}));
+
+const mockNavigate = vi.fn();
+vi.mock('react-router', async () => {
+ const actual = await vi.importActual<typeof import('react-router')>('react-router');
+ return { ...actual, useNavigate: () => mockNavigate };
+});
+
+import { render, screen } from '../../../tests/helpers/render';
+import userEvent from '@testing-library/user-event';
+import { useAuthStore } from '../../store/authStore';
+import { useAddonStore } from '../../store/addonStore';
+import { resetAllStores, seedStore } from '../../../tests/helpers/store';
+import { buildUser } from '../../../tests/helpers/factories';
+import MBottomNav from './MBottomNav';
+
+const currentUser = buildUser({ id: 1, username: 'testuser', email: '[email protected]' });
+
+const withCollections = () =>
+ seedStore(useAddonStore, {
+ addons: [{ id: 'collections', name: 'Collections', type: 'global', icon: 'bookmark', enabled: true }],
+ });
+
+beforeEach(() => {
+ resetAllStores();
+ mockNavigate.mockClear();
+ sessionStorage.clear();
+ seedStore(useAuthStore, { user: currentUser, isAuthenticated: true });
+});
+
+describe('MBottomNav', () => {
+ it('FE-COMP-MBOTTOMNAV-001: the dock "+" creates a trip on an unclaimed route', async () => {
+ const user = userEvent.setup();
+ render(<MBottomNav />, { initialEntries: ['/dashboard'] });
+ await user.click(screen.getByRole('button', { name: 'New Trip' }));
+ expect(mockNavigate).toHaveBeenCalledWith('/dashboard?create=1');
+ });
+
+ it('FE-COMP-MBOTTOMNAV-002: on the collections overview the "+" adds a place', async () => {
+ const user = userEvent.setup();
+ withCollections();
+ render(<MBottomNav />, { initialEntries: ['/collections'] });
+ await user.click(screen.getByRole('button', { name: 'Add a place' }));
+ expect(mockNavigate).toHaveBeenCalledWith('/collections?create=place');
+ });
+
+ // #1930: picking a list moves the route to /collections/:id, which the exact
+ // match missed — the "+" then created a trip instead of adding a place.
+ it('FE-COMP-MBOTTOMNAV-003: inside a collection the "+" adds a place, not a trip', async () => {
+ const user = userEvent.setup();
+ withCollections();
+ render(<MBottomNav />, { initialEntries: ['/collections/7'] });
+ await user.click(screen.getByRole('button', { name: 'Add a place' }));
+ expect(mockNavigate).toHaveBeenCalledWith('/collections/7?create=place');
+ expect(mockNavigate).not.toHaveBeenCalledWith('/dashboard?create=1');
+ });
+
+ it('FE-COMP-MBOTTOMNAV-004: the handoff keeps the list the user is looking at', async () => {
+ const user = userEvent.setup();
+ withCollections();
+ render(<MBottomNav />, { initialEntries: ['/collections/123'] });
+ await user.click(screen.getByRole('button', { name: 'Add a place' }));
+ expect(mockNavigate).toHaveBeenCalledWith('/collections/123?create=place');
+ });
+
+ it('FE-COMP-MBOTTOMNAV-005: on the journey list the "+" starts a journey', async () => {
+ const user = userEvent.setup();
+ seedStore(useAddonStore, {
+ addons: [{ id: 'journey', name: 'Journey', type: 'global', icon: 'compass', enabled: true }],
+ });
+ render(<MBottomNav />, { initialEntries: ['/journey'] });
+ await user.click(screen.getByRole('button', { name: 'New Journey' }));
+ expect(mockNavigate).toHaveBeenCalledWith('/journey?create=1');
+ });
+
+ it('FE-COMP-MBOTTOMNAV-006: inside a journey the "+" adds an entry', async () => {
+ const user = userEvent.setup();
+ seedStore(useAddonStore, {
+ addons: [{ id: 'journey', name: 'Journey', type: 'global', icon: 'compass', enabled: true }],
+ });
+ render(<MBottomNav />, { initialEntries: ['/journey/5'] });
+ await user.click(screen.getByRole('button', { name: 'Add Entry' }));
+ expect(mockNavigate).toHaveBeenCalledWith('/journey/5?create=entry');
+ });
+
+ it('FE-COMP-MBOTTOMNAV-007: /vacay yields the centre slot to the screen (#1811)', () => {
+ render(<MBottomNav />, { initialEntries: ['/vacay'] });
+ expect(screen.queryByRole('button', { name: 'New Trip' })).not.toBeInTheDocument();
+ });
+});
diff --git a/client/src/mobile/components/MBottomNav.tsx b/client/src/mobile/components/MBottomNav.tsx
index 0251ea4bf..48e96c86f 100644
--- a/client/src/mobile/components/MBottomNav.tsx
+++ b/client/src/mobile/components/MBottomNav.tsx
@@ -26,6 +26,7 @@ function useCreateAction(): { label: string; run: () => void } {
const onJourneyList = useMatch('/journey')
const onAtlas = useMatch('/atlas')
const onCollections = useMatch('/collections')
+ const inCollection = useMatch('/collections/:id')
if (inTrip) {
// The "+" is context-aware per active tab: Bookings → reservation,
@@ -47,8 +48,14 @@ function useCreateAction(): { label: string; run: () => void } {
if (onAtlas) {
return { label: t('atlas.searchCountry'), run: () => navigate('/atlas?search=1') }
}
- if (onCollections) {
- return { label: t('collections.addPlace'), run: () => navigate('/collections?create=place') }
+ if (onCollections || inCollection) {
+ // Picking a list moves the route to /collections/:id, so the exact match
+ // alone dropped the "+" through to creating a trip — the one state the
+ // screen is normally used in (#1930). The handoff keeps the id, otherwise
+ // adding would land on "All saved" and the sheet would ask for the list the
+ // user is already looking at.
+ const path = inCollection ? `/collections/${inCollection.params.id}` : '/collections'
+ return { label: t('collections.addPlace'), run: () => navigate(`${path}?create=place`) }
}
return { label: t('dashboard.newTrip'), run: () => navigate('/dashboard?create=1') }
}