mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 22:16:26 +00:00
6c63a9bb60
* refactor(client): opt into the v7 router behaviour while still on v6 Turning the behaviour on separately from the version bump keeps the two failure modes apart: red here means a behaviour change, red on the bump means the import rewrite. The suite is unchanged either way — 527 files, 11099 tests. Only the two flags a non-data router understands are set; the rest belong to createBrowserRouter, which this app doesn't use. Both are applied at all six router mounts, so the tests exercise the same behaviour as production rather than validating v6 while prod runs v7. * fix(client): move to react-router 7.18.2 6.30.4 is affected by GHSA-wrjc-x8rr-h8h6 — open redirect through a backslash in Link and useNavigate, which this app uses in 41 places — and the 6.x line has no fix: react-router-dom 6.30.2 to 6.30.4 carries GHSA-jjmj-jmhj-qwj2 with no patched version at all. Staying is not an option, and 7.0 to 7.17 only swaps it for GHSA-chx6-hx7r-mcp5. The package rename comes with it: react-router-dom is a re-export shim in v7, so using it would only defer the same rewrite to the v8 jump. 77 occurrences across 60 files, all of them import specifiers and vi.mock strings. The surface is small — useNavigate, useParams, useSearchParams, useLocation, Routes, Route, Link, Navigate, useMatch, MemoryRouter, BrowserRouter — no data router, no loaders or actions. Nothing else had to change; the future flags from the previous commit are simply how v7 behaves, so they come back out. npm audit still reports GHSA-qwww-vcr4-c8h2 on react-router (RSC mode CSRF, fixed in 8.3.0). It needs RSC mode, which needs a server; this is a static SPA. Closing it means the v8 major, which is its own piece of work.
135 lines
5.6 KiB
TypeScript
135 lines
5.6 KiB
TypeScript
// FE-COMP-BOTTOMNAV-001 to FE-COMP-BOTTOMNAV-010
|
|
|
|
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 { useSettingsStore } from '../../store/settingsStore';
|
|
import { useAddonStore } from '../../store/addonStore';
|
|
import { usePluginStore } from '../../store/pluginStore';
|
|
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
|
import { buildUser, buildSettings } from '../../../tests/helpers/factories';
|
|
import BottomNav from './BottomNav';
|
|
|
|
const currentUser = buildUser({ id: 1, username: 'testuser', email: 'test@example.com' });
|
|
|
|
beforeEach(() => {
|
|
resetAllStores();
|
|
mockNavigate.mockClear();
|
|
sessionStorage.clear();
|
|
seedStore(useAuthStore, { user: currentUser, isAuthenticated: true });
|
|
});
|
|
|
|
describe('BottomNav', () => {
|
|
it('FE-COMP-BOTTOMNAV-001: renders without crashing', () => {
|
|
render(<BottomNav />);
|
|
expect(document.body).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-002: shows the dashboard nav item', () => {
|
|
render(<BottomNav />);
|
|
expect(screen.getByText('My Trips')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-003: centre create button creates a new trip by default', async () => {
|
|
const user = userEvent.setup();
|
|
render(<BottomNav />);
|
|
await user.click(screen.getByRole('button', { name: 'New Trip' }));
|
|
expect(mockNavigate).toHaveBeenCalledWith('/dashboard?create=1');
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-004: dashboard label translates when language is fr', async () => {
|
|
seedStore(useSettingsStore, { settings: buildSettings({ language: 'fr' }) });
|
|
render(<BottomNav />);
|
|
expect(await screen.findByText('Mes voyages')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-005: addon labels translate when language is fr', async () => {
|
|
seedStore(useSettingsStore, { settings: buildSettings({ language: 'fr' }) });
|
|
seedStore(useAddonStore, {
|
|
addons: [
|
|
{ id: 'vacay', name: 'Vacay', type: 'global', icon: 'calendar', enabled: true },
|
|
{ id: 'atlas', name: 'Atlas', type: 'global', icon: 'globe', enabled: true },
|
|
{ id: 'journey', name: 'Journey', type: 'global', icon: 'compass', enabled: true },
|
|
],
|
|
});
|
|
render(<BottomNav />);
|
|
expect(await screen.findByText('Vacances')).toBeInTheDocument();
|
|
expect(await screen.findByText('Atlas')).toBeInTheDocument();
|
|
expect(await screen.findByText('Journal de voyage')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-006: unknown addon id is not rendered', () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'foo', name: 'Foo Addon', type: 'global', icon: 'star', enabled: true }],
|
|
});
|
|
render(<BottomNav />);
|
|
expect(screen.queryByText('Foo Addon')).not.toBeInTheDocument();
|
|
});
|
|
|
|
// Context-aware "+" inside a trip — #1349
|
|
it('FE-COMP-BOTTOMNAV-007: in a trip, the "+" adds a place by default (plan tab)', async () => {
|
|
const user = userEvent.setup();
|
|
sessionStorage.setItem('trip-tab-42', 'plan');
|
|
render(<BottomNav />, { initialEntries: ['/trips/42'] });
|
|
await user.click(screen.getByRole('button', { name: 'Add Place/Activity' }));
|
|
expect(mockNavigate).toHaveBeenCalledWith('/trips/42?create=place');
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-008: Bookings tab → "+" creates a reservation', async () => {
|
|
const user = userEvent.setup();
|
|
sessionStorage.setItem('trip-tab-42', 'buchungen');
|
|
render(<BottomNav />, { initialEntries: ['/trips/42'] });
|
|
await user.click(screen.getByRole('button', { name: 'Manual Booking' }));
|
|
expect(mockNavigate).toHaveBeenCalledWith('/trips/42?create=reservation');
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-009: Transports tab → "+" creates a transport', async () => {
|
|
const user = userEvent.setup();
|
|
sessionStorage.setItem('trip-tab-42', 'transports');
|
|
render(<BottomNav />, { initialEntries: ['/trips/42'] });
|
|
await user.click(screen.getByRole('button', { name: 'Transport' }));
|
|
expect(mockNavigate).toHaveBeenCalledWith('/trips/42?create=transport');
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-010: Costs tab → "+" creates an expense', async () => {
|
|
const user = userEvent.setup();
|
|
sessionStorage.setItem('trip-tab-42', 'finanzplan');
|
|
render(<BottomNav />, { initialEntries: ['/trips/42'] });
|
|
await user.click(screen.getByRole('button', { name: 'Add expense' }));
|
|
expect(mockNavigate).toHaveBeenCalledWith('/trips/42?create=expense');
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-011: page plugin renders the icon its manifest declares', () => {
|
|
seedStore(usePluginStore, {
|
|
plugins: [{ id: 'trip-doctor', name: 'Trip Doctor', type: 'page', icon: 'Stethoscope' }],
|
|
});
|
|
const { container } = render(<BottomNav />);
|
|
expect(screen.getByText('Trip Doctor')).toBeInTheDocument();
|
|
expect(container.querySelector('.lucide-stethoscope')).not.toBeNull();
|
|
});
|
|
|
|
it('FE-COMP-BOTTOMNAV-012: page plugin with an unknown icon falls back to Blocks', () => {
|
|
seedStore(usePluginStore, {
|
|
plugins: [{ id: 'bogus', name: 'Bogus', type: 'page', icon: 'NotAnIcon' }],
|
|
});
|
|
const { container } = render(<BottomNav />);
|
|
expect(container.querySelector('.lucide-blocks')).not.toBeNull();
|
|
});
|
|
});
|