mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
5d334d7ec8
A third scope, home, next to trip and journey: threads that name neither a trip nor a journey (the CHECK now only forbids both), reached under /api/assistant by their owner only. A home turn reads the user's trips through list_trips into a short card (under way, next, later, behind, undated), offers every read (a trip's on the id the model names, checked by the tool with the user's rights) and only the writes that take no trip or journey (atlas, vacation planner, collections, tour library, settings), all held as change cards. open_trip_chat answers with a card that goes on in that trip's own chat with the question waiting in its composer. On the desktop the window opens on the home chat outside a trip; its head lists the trips to switch into and a switched trip chat has the way back. On the phone the home chat opens full screen from the dashboard head and the dock's More list, and the card opens the trip with its chat. Both run on useAssistantHome.
114 lines
5.0 KiB
TypeScript
114 lines
5.0 KiB
TypeScript
// FE-COMP-MBOTTOMNAV-001 to FE-COMP-MBOTTOMNAV-008
|
|
|
|
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 { useAssistantStore } from '../../store/assistantStore';
|
|
import type { AiStatusResponse } from '@trek/shared';
|
|
import MBottomNav from './MBottomNav';
|
|
|
|
const currentUser = buildUser({ id: 1, username: 'testuser', email: 'test@example.com' });
|
|
|
|
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();
|
|
});
|
|
|
|
it('FE-COMP-MBOTTOMNAV-008: the More list leads with the assistant while it can run, and opens the home chat', async () => {
|
|
const user = userEvent.setup();
|
|
useAssistantStore.setState({ status: { available: true } as AiStatusResponse, window: { open: false, minimized: false } });
|
|
render(<MBottomNav />, { initialEntries: ['/atlas'] });
|
|
await user.click(screen.getByRole('button', { name: 'More' }));
|
|
await user.click(screen.getByRole('button', { name: 'Assistant' }));
|
|
expect(useAssistantStore.getState().window).toEqual({ open: true, minimized: false });
|
|
expect(mockNavigate).not.toHaveBeenCalled();
|
|
useAssistantStore.setState({ status: null, window: { open: false, minimized: false } });
|
|
});
|
|
});
|