mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 14:21:46 +00:00
20791a29a7
* Migrate TREK 3 to NestJS + React 19 with a shared Zod contract layer
Brownfield strangler migration of the backend onto NestJS modules
(auth, trips, days, places, assignments, packing, todo, budget,
reservations, collab, files, photos, journey, share, settings, backup,
oidc, oauth, admin, atlas, vacay, weather, airports, maps, categories,
tags, notifications, system-notices) served through a per-prefix
dispatcher, keeping the existing SQLite/better-sqlite3 DB and JWT
httpOnly cookie auth, with behavioural parity for every route.
Client: React 19 upgrade, "page = wiring container + data hook"
pattern across all pages, per-domain Zustand stores bound to
@trek/shared contracts, and decomposition of the large components
(DayPlanSidebar, PackingListPanel, CollabNotes, FileManager,
MemoriesPanel, PlacesSidebar, CollabChat, SystemNoticeModal,
BudgetPanel, PlaceFormModal, ...) into focused render units backed by
in-file hooks.
Apply the shared global request pipeline (helmet/CSP, CORS, HSTS,
forced HTTPS, the global MFA policy and request logging) to the NestJS
instance as well, so a migrated route is protected identically to the
legacy fallback rather than bypassing it.
* Finish the NestJS migration — drop the legacy Express app
NestJS now serves the whole surface: every /api domain plus the platform
routes (uploads, /mcp, the OAuth/MCP SDK + /.well-known metadata and the
production SPA fallback). Removed server/src/app.ts, all of
server/src/routes/* and the strangler dispatcher; index.ts and the
integration suite share a single buildApp() bootstrap so prod and tests
can't drift.
- Platform/transport routes extracted to nest/platform/platform.routes.ts
and mounted before app.init() — Nest's router answers an unmatched
request with a 404, so a route registered after init is never reached.
The SPA fallback is a NotFoundException filter and the catch-all uses a
RegExp (Express 5's path-to-regexp rejects a bare '*').
- New modules: memories (/api/integrations/memories — the Journey
gallery's Immich/Synology proxy), addons (GET /api/addons) and the
cross-trip GET /api/reservations/upcoming.
- TrekExceptionFilter reproduces the old multer / err.statusCode handling
so upload rejections keep their 400/413 { error } body and non-ASCII
filenames survive (defParamCharset).
- addTripToJourney and the MCP get_journey_share_link tool gained the
trip-access check they were missing.
- Re-pointed the 34 integration tests + the websocket test onto the Nest
app; removed the now-meaningless Express-vs-Nest parity tests and a few
orphaned client components.
* Restore the reset-password rate limit and fix copyTrip reservation links
Two correctness/security gaps the NestJS migration introduced:
- POST /api/auth/reset-password lost its per-IP rate limiter. Restore it
(5 attempts / 15 min on a dedicated bucket, same as the old resetLimiter)
so reset tokens can't be brute-forced unthrottled. Covered by AUTH-019.
- copyTripById did not copy reservations.end_day_id (a day reference — now
remapped through dayMap like day_id) or needs_review, so a duplicated trip
lost multi-day transport end-day links and reset the review flag.
* Clean up dead code, dedupe helpers, fix the reset-password contract
- Remove server exports orphaned by the Express removal: the immich
album-link helpers, seven route-only service exports, getFileByIdFull;
de-export internal-only helpers (utcSuffix).
- De-duplicate verifyTripAccess (9 identical copies -> services/tripAccess.ts)
and avatarUrl (3 -> services/avatarUrl.ts); name the bcrypt cost
(BCRYPT_COST) and the email regex (EMAIL_REGEX). Public API unchanged.
- resetPasswordRequestSchema declared `password`, but the client sends and
the service reads `new_password` — rename it so the contract matches and
the client types resolve.
- Make ATLAS-013 deterministic: stub the admin-1 GeoJSON download instead of
fetching ~4600 features from GitHub during the test (it hung the suite).
* Make the client typecheck runnable (vitest/vite ambient types)
The client had no `typecheck` script and tsc couldn't even start (the
baseUrl deprecation errored out, same as server/shared already silence).
Add `ignoreDeprecations: "6.0"` to match the other workspaces, a `typecheck`
npm script, and a src/vite-env.d.ts referencing vite/client + vitest/globals
so tsc knows the test globals (describe/it/expect/vi). This turns ~3600
phantom "Cannot find name" errors into a real, measurable count (~590 actual
type errors remain, to be worked down). Type-only; no runtime change.
* Derive client domain types from the shared schema contracts
Add entity/response Zod schemas to @trek/shared (place, trip, assignment, day, budget, packing, reservation), each matched against the producing server service, and re-export them from client types.ts instead of the hand-written duplicates that had drifted (name/title, amount/total_price, owner_id/user_id, cover_url/cover_image, ...). Updates the call sites and test fixtures the corrected types surfaced; type-only, no runtime behaviour change.
* chore(db): log swallowed errors in addon-disable migration + guard against destructive migrations
The migration that disables the legacy "memories" addon swallowed any
error in an empty catch, as did ~30 other catch blocks in the migration
runner (column adds, the journey rebuild, index probes). Replace each
silent catch with the existing console.warn('[migrations] ...') log so
failures are visible. Control flow is unchanged: every step stays
non-fatal, nothing new is thrown.
Add a static guardrail test that scans the migration source and fails
when a new destructive statement (DROP TABLE / DROP COLUMN / TRUNCATE /
DELETE FROM / ALTER ... DROP) appears outside a reviewed allowlist, and
when an empty/silent catch block is reintroduced. The existing
destructive statements are all legitimate table rebuilds or
bounded cleanups and are recorded in the allowlist with a reason.
* Re-check SSRF on every redirect hop when resolving short links
Replace the one-shot checkSsrf + fetch(redirect:'follow') in the maps and place short-link resolvers with safeFetchFollow, which follows redirects manually and re-runs checkSsrf against the DNS-pinned IP of each hop (max 5). A redirect to an internal/loopback address is now blocked even when the initial URL is public, while legitimate cross-host redirects (goo.gl -> maps.google.com) still resolve.
* Reject WebSocket tokens minted before a password change
Stamp the user's password_version onto the ephemeral ws token and verify it on connect, closing the socket (4001) when it no longer matches, so a token issued before a password reset can't be replayed. Tokens minted without a version are treated as version 0, matching the JWT pv-claim semantics.
* fix(i18n): guard locale key parity and finish the OAuth consent page strings
Every non-en locale now exposes the exact same flat key set as en. Keys that
had drifted out of sync are backfilled with the English source value (tagged
en-fallback) so t() resolves a real string instead of relying on the silent
runtime fallback; no existing translation was touched and no key was removed.
Add a parity test that imports each aggregated locale bundle and asserts its
key set matches en, with a diagnostic listing of any missing/extra keys. This
complements the file-level check in shared/scripts by guarding the merged
export the app actually serves.
Finish internationalising OAuthAuthorizePage: the ~15 remaining hardcoded
English chrome strings now go through oauth.authorize.* keys (English source
in en, en-fallback placeholders elsewhere). Markup and behaviour are unchanged.
* Add semantic theme color tokens to Tailwind
Map the CSS theme variables from src/index.css (:root light / .dark dark) to named Tailwind utilities — bg-surface, text-content, border-edge, bg-accent and their variants. This gives components a Tailwind-native target for the theme colors so we can replace inline `style={{ ... 'var(--...)' }}` with utility classes without changing the rendered values.
* Surface silent store failures to the user and validate API responses in dev
Reservation toggle, todo/packing toggle and budget reorder were swallowing API errors after rolling back, so the user saw the change silently snap back with no explanation. Route those failures through the existing toast channel (new store/notify.ts bridges to window.__addToast, the same channel SystemNoticeBanner uses); the reservation toggle re-throws so ReservationsPanel's own translated toast finally fires. Also wire the existing parseInDev/checkInDev response validation into the maps and notification-test endpoints to catch contract drift in dev.
* Migrate static theme inline styles to Tailwind utilities and extract page sub-components
Replace the static, color-only inline `style={{ ... 'var(--bg-primary)' ... }}` props with the new semantic Tailwind utilities (bg-surface, text-content, border-edge, ...) wherever the result is byte-identical; dynamic/conditional theme styles and hardcoded status colors are left inline. Extract the Atlas country-search autocomplete, the Admin update banner, and two Journey dialogs into their own presentational components to shrink the oversized page files, keeping behaviour and markup identical.
* Remove the unrouted photos page and its dead photo components
PhotosPage was never wired into the router and its usePhotos hook read a tripStore photos slice that was never implemented; the Photos gallery, lightbox and upload components were only reachable through it. Per-trip photos now live in the Journey gallery (Immich/Synology). Removed the dead page, hook and components — the live Journey PhotoLightbox is a separate component and stays.
* Resolve the remaining client type errors and the trip.title navbar bug
Drive the client typecheck to zero without any/ts-ignore: convert the tripId route param to a number once at the page boundary so it matches the numeric props and store actions it feeds, fix trip.name -> trip.title (the wire field is title, so the old read rendered blank in the files/offline views), and tighten the scattered handler-arity, DOM-cast and untyped-payload sites. No runtime behaviour change.
* Convert the remaining dynamic and hardcoded inline styles to Tailwind utilities
Second styling pass over the components and pages: move conditional theme colors into className ternaries (bg-accent / bg-surface-hover etc.), turn reused CSSProperties constants into className constants, and express static hardcoded hex/rgba colors as Tailwind arbitrary values so the exact rendered colour is preserved. Truly dynamic styling (computed geometry, gradients, multi-part shadows, data-driven colours, the undefined --sidebar/--nav layout vars) stays inline as it cannot be expressed as a static class. Updated three component tests that asserted the old inline active-state styles to assert the equivalent utility class instead.
Verified: client typecheck 0, full client suite green, and a live light/dark render check in the dev server confirms the semantic theme tokens resolve correctly (the earlier 'transparent popups' were a stale dev server that pre-dated the tailwind.config token addition, not a code issue).
* Add eslint flat-config for client and server and gate typecheck, lint and pages in CI
client and server had lint scripts but no eslint config (only shared was linted in CI). Add flat configs mirroring shared's stack (js + typescript-eslint recommended + eslint-config-prettier) plus the client's react-hooks/react-refresh plugins. Pre-existing patterns in this never-linted code (explicit any, require() in the CommonJS server, empty catches, exhaustive-deps) are set to 'warn' rather than 'error' so the gate passes at 0 errors without a repo-wide reformat — these can be ratcheted to errors over time. Wire blocking typecheck + lint + lint:pages steps into the client and server CI jobs (now that both typechecks are clean) and promote the server typecheck from informational to blocking.
* Decompose the remaining God Components into hooks, helpers and sub-components
FE6: split the oversized page and panel components into thin layout shells plus colocated use<Component> hooks, .constants.ts, .helpers.ts (with tests) and presentational sub-components, following the established 'logic in a hook, render in slices' pattern. Behaviour, markup, classes and effect order are unchanged. Largest reductions: PackingListPanel 1598->42, FileManager 1055->36, AdminPage 1525->167, BudgetPanel 1266->146, JourneyDetailPage 2822->547, PlacesSidebar 945->66, CollabChat 861->106, CollabNotes 1417->532. DayPlanSidebar's drag-and-drop render body was left intact (ref-identity sensitive) and only its toolbar/modals/constants were extracted.
* Fix duplicate React keys in the file-assign place list
When a place is assigned to the same day more than once it appeared twice in a day's list, so the place-button key={p.id} collided and React warned about duplicate keys. Key by place id + render index so siblings stay unique. Pre-existing in the old FileManager; behaviour unchanged.
* Format the shared package and drop an unused import to satisfy the lint gate
The i18n and schema changes added code that wasn't prettier-formatted, and place.schema.ts imported categorySchema without using it. Run prettier over shared and remove the import so 'npm run lint' + 'format:check' pass.
* Install all workspaces in the server CI job so SWC's native binary is present
The server vitest config transforms via unplugin-swc, which needs @swc/core's platform-specific native binary. A workspace-scoped 'npm ci --workspace server' skips that optional dependency, so vitest failed to load the config on the Linux runner. Use a full 'npm ci'.
* Re-resolve dependencies with npm install in the server CI job for SWC
Full 'npm ci' still skipped @swc/core's Linux native binary because the committed lockfile was generated on Windows and lacks the Linux optional-dep install metadata. 'npm install' re-resolves and fetches the platform-matching binary, which the server's unplugin-swc transform needs to load vitest.config.ts.
* Install @swc/core's Linux binary explicitly in the server CI job
Neither npm ci nor npm install fetched @swc/core-linux-x64-gnu on the Linux runner because the lockfile was generated on Windows and lacks the Linux optional-dep metadata. Add a step that installs the matching @swc/core-linux-x64-gnu version (no-save, no-lockfile) so unplugin-swc can load the server's vitest config.
* Use legacy-peer-deps when installing the SWC Linux binary in CI
The explicit @swc/core-linux-x64-gnu install re-resolved the tree and hit the pre-existing lucide-react/react-19 peer conflict that the lockfile was generated around. Add --legacy-peer-deps so the step matches the project's resolution and installs the binary.
* Keep the lockfile when installing the SWC binary so other deps stay pinned
Dropping --no-package-lock made npm re-resolve the whole tree and upgrade eslint, whose newer recommended config flagged no-useless-assignment as an error in the server lint step. Keep the lockfile so only @swc/core-linux-x64-gnu is added and every other dependency (incl. eslint) stays at its locked version.
1561 lines
49 KiB
TypeScript
1561 lines
49 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
import React from 'react';
|
|
import { render, screen, waitFor, act, fireEvent } from '../../tests/helpers/render';
|
|
import { Routes, Route } from 'react-router-dom';
|
|
import { resetAllStores, seedStore } from '../../tests/helpers/store';
|
|
import { buildUser, buildTrip, buildDay, buildPlace, buildAssignment } from '../../tests/helpers/factories';
|
|
import { useAuthStore } from '../store/authStore';
|
|
import { useTripStore } from '../store/tripStore';
|
|
import TripPlannerPage from './TripPlannerPage';
|
|
import { server } from '../../tests/helpers/msw/server';
|
|
import { http, HttpResponse } from 'msw';
|
|
|
|
// Mock Leaflet-dependent components
|
|
vi.mock('../components/Map/MapView', () => ({
|
|
MapView: () => React.createElement('div', { 'data-testid': 'map-view' }),
|
|
}));
|
|
|
|
vi.mock('react-leaflet', () => ({
|
|
MapContainer: ({ children }: { children: React.ReactNode }) =>
|
|
React.createElement('div', { 'data-testid': 'map-container' }, children),
|
|
TileLayer: () => null,
|
|
Marker: ({ children }: { children?: React.ReactNode }) => React.createElement('div', null, children),
|
|
Tooltip: ({ children }: { children?: React.ReactNode }) => React.createElement('div', null, children),
|
|
Polyline: () => null,
|
|
CircleMarker: () => null,
|
|
Circle: () => null,
|
|
useMap: () => ({ fitBounds: vi.fn(), getCenter: vi.fn(() => ({ lat: 0, lng: 0 })) }),
|
|
}));
|
|
|
|
vi.mock('react-leaflet-cluster', () => ({
|
|
default: ({ children }: { children: React.ReactNode }) => React.createElement('div', null, children),
|
|
}));
|
|
|
|
vi.mock('leaflet', () => {
|
|
const L = {
|
|
divIcon: vi.fn(() => ({})),
|
|
latLngBounds: vi.fn(() => ({ extend: vi.fn(), isValid: vi.fn(() => true) })),
|
|
icon: vi.fn(() => ({})),
|
|
};
|
|
return { default: L, ...L };
|
|
});
|
|
|
|
// Mock the WebSocket hook so we can verify it's called
|
|
const mockUseTripWebSocket = vi.fn();
|
|
vi.mock('../hooks/useTripWebSocket', () => ({
|
|
useTripWebSocket: (...args: unknown[]) => mockUseTripWebSocket(...args),
|
|
}));
|
|
|
|
// Prop-capturing refs for mock components — populated on each render
|
|
const capturedDayPlanSidebarProps: { current: Record<string, any> } = { current: {} };
|
|
const capturedPlacesSidebarProps: { current: Record<string, any> } = { current: {} };
|
|
|
|
// Mock heavy sub-components (capture props for handler testing)
|
|
vi.mock('../components/Planner/DayPlanSidebar', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedDayPlanSidebarProps.current = props;
|
|
return React.createElement('div', { 'data-testid': 'day-plan-sidebar' });
|
|
},
|
|
}));
|
|
|
|
vi.mock('../components/Planner/PlacesSidebar', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedPlacesSidebarProps.current = props;
|
|
return React.createElement('div', { 'data-testid': 'places-sidebar' });
|
|
},
|
|
}));
|
|
|
|
const capturedPlaceInspectorProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Planner/PlaceInspector', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedPlaceInspectorProps.current = props;
|
|
return React.createElement('div', { 'data-testid': 'place-inspector' });
|
|
},
|
|
}));
|
|
|
|
const capturedDayDetailPanelProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Planner/DayDetailPanel', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedDayDetailPanelProps.current = props;
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
vi.mock('../components/Memories/MemoriesPanel', () => ({
|
|
default: () => React.createElement('div', { 'data-testid': 'memories-panel' }),
|
|
}));
|
|
|
|
vi.mock('../components/Collab/CollabPanel', () => ({
|
|
default: () => React.createElement('div', { 'data-testid': 'collab-panel' }),
|
|
}));
|
|
|
|
const capturedFileManagerProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Files/FileManager', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedFileManagerProps.current = props;
|
|
return React.createElement('div', { 'data-testid': 'file-manager' });
|
|
},
|
|
}));
|
|
|
|
vi.mock('../components/Budget/BudgetPanel', () => ({
|
|
default: () => React.createElement('div', { 'data-testid': 'budget-panel' }),
|
|
}));
|
|
|
|
vi.mock('../components/Packing/PackingListPanel', () => ({
|
|
default: () => React.createElement('div', { 'data-testid': 'packing-list-panel' }),
|
|
}));
|
|
|
|
vi.mock('../components/Todo/TodoListPanel', () => ({
|
|
default: () => React.createElement('div', { 'data-testid': 'todo-list-panel' }),
|
|
}));
|
|
|
|
// Prop-capturing mocks for modal components (enable calling onSave/onDelete/etc. in tests)
|
|
const capturedReservationsPanelProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Planner/ReservationsPanel', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedReservationsPanelProps.current = props;
|
|
return React.createElement('div', { 'data-testid': 'reservations-panel' });
|
|
},
|
|
}));
|
|
|
|
const capturedPlaceFormModalProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Planner/PlaceFormModal', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedPlaceFormModalProps.current = props;
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
const capturedReservationModalProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Planner/ReservationModal', () => ({
|
|
ReservationModal: (props: Record<string, any>) => {
|
|
capturedReservationModalProps.current = props;
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
const capturedConfirmDialogProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/shared/ConfirmDialog', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedConfirmDialogProps.current = props;
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
const capturedTripFormModalProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Trips/TripFormModal', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedTripFormModalProps.current = props;
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
const capturedTripMembersModalProps: { current: Record<string, any> } = { current: {} };
|
|
vi.mock('../components/Trips/TripMembersModal', () => ({
|
|
default: (props: Record<string, any>) => {
|
|
capturedTripMembersModalProps.current = props;
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
// Configurable usePlaceSelection mock — lets tests set a specific selected place
|
|
const mockPlaceSelectionState: { selectedPlaceId: number | null; selectedAssignmentId: number | null } = {
|
|
selectedPlaceId: null,
|
|
selectedAssignmentId: null,
|
|
};
|
|
const mockSetSelectedPlaceId = vi.fn();
|
|
const mockSelectAssignment = vi.fn();
|
|
|
|
vi.mock('../hooks/usePlaceSelection', () => ({
|
|
usePlaceSelection: () => ({
|
|
selectedPlaceId: mockPlaceSelectionState.selectedPlaceId,
|
|
selectedAssignmentId: mockPlaceSelectionState.selectedAssignmentId,
|
|
setSelectedPlaceId: mockSetSelectedPlaceId,
|
|
selectAssignment: mockSelectAssignment,
|
|
}),
|
|
}));
|
|
|
|
// Helper to seed a complete trip store state with mocked actions
|
|
function seedTripStore(overrides: { id?: number; tripName?: string; withMocks?: boolean } = {}) {
|
|
const { id = 42, tripName = 'Test Trip', withMocks = true } = overrides;
|
|
// Use `title` because TripPlannerPage reads trip.title
|
|
const trip = { ...buildTrip({ id }), title: tripName };
|
|
const day = buildDay({ trip_id: id });
|
|
|
|
const mockLoadTrip = withMocks ? vi.fn().mockResolvedValue(undefined) : undefined;
|
|
const mockLoadFiles = withMocks ? vi.fn().mockResolvedValue(undefined) : undefined;
|
|
const mockLoadReservations = withMocks ? vi.fn().mockResolvedValue(undefined) : undefined;
|
|
|
|
seedStore(useTripStore, {
|
|
trip,
|
|
isLoading: false,
|
|
days: [day],
|
|
places: [],
|
|
assignments: {},
|
|
packingItems: [],
|
|
todoItems: [],
|
|
categories: [],
|
|
reservations: [],
|
|
budgetItems: [],
|
|
files: [],
|
|
...(withMocks && {
|
|
loadTrip: mockLoadTrip,
|
|
loadFiles: mockLoadFiles,
|
|
loadReservations: mockLoadReservations,
|
|
}),
|
|
} as any);
|
|
|
|
return { trip, day, mockLoadTrip, mockLoadFiles, mockLoadReservations };
|
|
}
|
|
|
|
// Helper to render TripPlannerPage with route params
|
|
function renderPlannerPage(tripId: number | string) {
|
|
return render(
|
|
<Routes>
|
|
<Route path="/trips/:id" element={<TripPlannerPage />} />
|
|
</Routes>,
|
|
{ initialEntries: [`/trips/${tripId}`] },
|
|
);
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
resetAllStores();
|
|
mockUseTripWebSocket.mockReset();
|
|
mockSetSelectedPlaceId.mockReset();
|
|
mockSelectAssignment.mockReset();
|
|
mockPlaceSelectionState.selectedPlaceId = null;
|
|
mockPlaceSelectionState.selectedAssignmentId = null;
|
|
capturedDayPlanSidebarProps.current = {};
|
|
capturedPlacesSidebarProps.current = {};
|
|
capturedReservationsPanelProps.current = {};
|
|
capturedPlaceFormModalProps.current = {};
|
|
capturedReservationModalProps.current = {};
|
|
capturedConfirmDialogProps.current = {};
|
|
capturedDayDetailPanelProps.current = {};
|
|
capturedTripFormModalProps.current = {};
|
|
capturedTripMembersModalProps.current = {};
|
|
capturedFileManagerProps.current = {};
|
|
capturedPlaceInspectorProps.current = {};
|
|
seedStore(useAuthStore, { isAuthenticated: true, user: buildUser() });
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
describe('TripPlannerPage', () => {
|
|
describe('FE-PAGE-PLANNER-001: Calls loadTrip with route param on mount', () => {
|
|
it('calls loadTrip with the trip ID from URL params', async () => {
|
|
const { mockLoadTrip } = seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
await waitFor(() => {
|
|
expect(mockLoadTrip).toHaveBeenCalledWith(42);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-002: Loading state shown while loadTrip in progress', () => {
|
|
it('shows loading animation when isLoading is true', () => {
|
|
seedStore(useTripStore, {
|
|
trip: null,
|
|
isLoading: true,
|
|
days: [],
|
|
places: [],
|
|
assignments: {},
|
|
loadTrip: vi.fn().mockReturnValue(new Promise(() => {})),
|
|
loadFiles: vi.fn().mockResolvedValue(undefined),
|
|
loadReservations: vi.fn().mockResolvedValue(undefined),
|
|
} as any);
|
|
|
|
renderPlannerPage(99);
|
|
|
|
// Loading state: shows loading gif
|
|
const loadingImg = document.querySelector('img[alt="Loading"]');
|
|
expect(loadingImg).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-003: Error state shown if loadTrip fails', () => {
|
|
it('calls loadTrip and the action is called (even if it rejects)', async () => {
|
|
const mockLoadTrip = vi.fn().mockRejectedValue(new Error('Not found'));
|
|
const mockLoadFiles = vi.fn().mockResolvedValue(undefined);
|
|
const mockLoadReservations = vi.fn().mockResolvedValue(undefined);
|
|
|
|
seedStore(useTripStore, {
|
|
trip: null,
|
|
isLoading: false,
|
|
days: [],
|
|
places: [],
|
|
assignments: {},
|
|
loadTrip: mockLoadTrip,
|
|
loadFiles: mockLoadFiles,
|
|
loadReservations: mockLoadReservations,
|
|
} as any);
|
|
|
|
renderPlannerPage(999);
|
|
|
|
await waitFor(() => {
|
|
expect(mockLoadTrip).toHaveBeenCalledWith(999);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-004: Trip name in header after load', () => {
|
|
it('shows trip title in the Navbar after splash screen', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 7, tripName: 'Tokyo Adventure' });
|
|
|
|
renderPlannerPage(7);
|
|
|
|
// Run all pending timers (including the 1500ms splash timeout) synchronously
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText('Tokyo Adventure')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-005: Day plan sidebar renders', () => {
|
|
it('renders the DayPlanSidebar component after splash', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 3, tripName: 'Day Tabs Trip' });
|
|
|
|
renderPlannerPage(3);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-007: Places sidebar renders', () => {
|
|
it('renders the PlacesSidebar component after splash', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 5, tripName: 'Places Trip' });
|
|
|
|
renderPlannerPage(5);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('places-sidebar')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-008: WebSocket hook mounted', () => {
|
|
it('calls useTripWebSocket with the trip ID from URL params', async () => {
|
|
seedTripStore({ id: 15 });
|
|
|
|
renderPlannerPage(15);
|
|
|
|
await waitFor(() => {
|
|
expect(mockUseTripWebSocket).toHaveBeenCalledWith(15);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-009: Map view renders after splash', () => {
|
|
it('shows the MapView component after the splash screen is dismissed', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-010: Reservations tab renders ReservationsPanel', () => {
|
|
it('shows ReservationsPanel after clicking the Bookings tab', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const bookingsTab = await screen.findByTitle('Bookings');
|
|
fireEvent.click(bookingsTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('reservations-panel')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-011: Packing tab renders PackingListPanel', () => {
|
|
it('shows PackingListPanel after clicking the Lists tab with packing addon enabled', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ addons: [{ id: 'packing', type: 'packing' }] })
|
|
)
|
|
);
|
|
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const listsTab = await screen.findByTitle('Lists');
|
|
fireEvent.click(listsTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('packing-list-panel')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-012: Budget tab renders BudgetPanel', () => {
|
|
it('shows BudgetPanel after clicking the Budget tab with budget addon enabled', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ addons: [{ id: 'budget', type: 'budget' }] })
|
|
)
|
|
);
|
|
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const budgetTab = await screen.findByTitle('Budget');
|
|
fireEvent.click(budgetTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('budget-panel')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-013: Files tab renders FileManager', () => {
|
|
it('shows FileManager after clicking the Files tab with documents addon enabled', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ addons: [{ id: 'documents', type: 'documents' }] })
|
|
)
|
|
);
|
|
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const filesTab = await screen.findByTitle('Files');
|
|
fireEvent.click(filesTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('file-manager')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-014: Collab tab renders CollabPanel', () => {
|
|
it('shows CollabPanel after clicking the Collab tab with collab addon enabled', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ addons: [{ id: 'collab', type: 'collab' }] })
|
|
)
|
|
);
|
|
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const collabTab = await screen.findByTitle('Collab');
|
|
fireEvent.click(collabTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('collab-panel')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-015: Tab state persists in sessionStorage', () => {
|
|
it('saves the active tab ID to sessionStorage on tab change', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const bookingsTab = await screen.findByTitle('Bookings');
|
|
fireEvent.click(bookingsTab);
|
|
|
|
await waitFor(() => {
|
|
expect(sessionStorage.getItem('trip-tab-42')).toBe('buchungen');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-016: Left panel collapse toggle', () => {
|
|
it('collapses the left sidebar when the collapse button is clicked', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
const sidebarContainer = screen.getByTestId('day-plan-sidebar').parentElement!;
|
|
const collapseButton = sidebarContainer.previousElementSibling as HTMLElement;
|
|
|
|
fireEvent.click(collapseButton);
|
|
|
|
await waitFor(() => {
|
|
expect(sidebarContainer).toHaveStyle('opacity: 0');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-017: Trip navigation error redirects to dashboard', () => {
|
|
it('navigates to /dashboard when loadTrip rejects', async () => {
|
|
seedStore(useTripStore, {
|
|
trip: null,
|
|
isLoading: false,
|
|
days: [],
|
|
places: [],
|
|
assignments: {},
|
|
loadTrip: vi.fn().mockRejectedValue(new Error('Not found')),
|
|
loadFiles: vi.fn().mockResolvedValue(undefined),
|
|
loadReservations: vi.fn().mockResolvedValue(undefined),
|
|
} as any);
|
|
|
|
render(
|
|
<Routes>
|
|
<Route path="/trips/:id" element={<TripPlannerPage />} />
|
|
<Route path="/dashboard" element={<div data-testid="dashboard-page" />} />
|
|
</Routes>,
|
|
{ initialEntries: ['/trips/999'] },
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('dashboard-page')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
// FE-PAGE-PLANNER-018: Removed — MemoriesPanel moved to Journey addon
|
|
|
|
describe('FE-PAGE-PLANNER-019: Todo subtab in ListsContainer', () => {
|
|
it('shows TodoListPanel after switching to the Todo subtab inside Lists', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ addons: [{ id: 'packing', type: 'packing' }] })
|
|
)
|
|
);
|
|
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
// Navigate to the Lists tab first
|
|
const listsTab = await screen.findByTitle('Lists');
|
|
fireEvent.click(listsTab);
|
|
|
|
// Find the Todo subtab button inside ListsContainer and click it
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('packing-list-panel')).toBeInTheDocument();
|
|
});
|
|
|
|
// Click the Todo subtab
|
|
const todoButtons = screen.getAllByRole('button');
|
|
const todoSubtab = todoButtons.find(btn => btn.textContent?.includes('Todo') || btn.textContent?.includes('todo'));
|
|
if (todoSubtab) {
|
|
fireEvent.click(todoSubtab);
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('todo-list-panel')).toBeInTheDocument();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-020: handleSelectDay covers plan selection logic', () => {
|
|
it('calls handleSelectDay through captured DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call onSelectDay via the captured props — covers handleSelectDay body
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onSelectDay?.(day.id);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-021: handlePlaceClick covers place selection logic', () => {
|
|
it('calls handlePlaceClick through captured DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, { places: [place] } as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call onPlaceClick via captured props — covers handlePlaceClick body
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onPlaceClick?.(place.id, null);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-022: handleRemoveAssignment covers removal logic', () => {
|
|
it('calls onRemoveAssignment through captured DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
const place = buildPlace({ id: 1, trip_id: 42 });
|
|
const assignment = buildAssignment({ id: 10, day_id: day.id, place });
|
|
seedStore(useTripStore, {
|
|
assignments: { [String(day.id)]: [assignment] },
|
|
places: [place],
|
|
} as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call onRemoveAssignment — covers handleRemoveAssignment body
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onRemoveAssignment?.(day.id, assignment.id);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-023: handleAssignToDay covers assignment logic', () => {
|
|
it('calls onAssignToDay through captured PlacesSidebar props with a selected day', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, { selectedDayId: day.id } as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('places-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call onAssignToDay — covers handleAssignToDay body
|
|
await act(async () => {
|
|
capturedPlacesSidebarProps.current.onAssignToDay?.(1, day.id, 0);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-024: PlaceInspector renders when a place is selected', () => {
|
|
it('renders PlaceInspector when selectedPlaceId matches a store place', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
|
|
// Set selectedPlaceId before render so selectedPlace is computed non-null
|
|
mockPlaceSelectionState.selectedPlaceId = place.id;
|
|
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, { places: [place] } as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
// PlaceInspector is mocked as () => null so nothing visual renders,
|
|
// but the conditional block lines 776-818 are covered
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-025: dayOrderMap and dayPlaces computed with selectedDayId', () => {
|
|
it('renders the planner with a selectedDayId and assignments to cover memo logic', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
const assignment = buildAssignment({ id: 10, day_id: day.id, place, order_index: 0 });
|
|
seedStore(useTripStore, {
|
|
selectedDayId: day.id,
|
|
places: [place],
|
|
assignments: { [String(day.id)]: [assignment] },
|
|
} as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-026: handleReorder covers reorder logic', () => {
|
|
it('calls onReorder through captured DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
const place = buildPlace({ id: 1, trip_id: 42 });
|
|
const assignment = buildAssignment({ id: 10, day_id: day.id, place, order_index: 0 });
|
|
seedStore(useTripStore, {
|
|
places: [place],
|
|
assignments: { [String(day.id)]: [assignment] },
|
|
} as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onReorder?.(day.id, [assignment.id]);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-027: handleUpdateDayTitle covers title update logic', () => {
|
|
it('calls onUpdateDayTitle through captured DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onUpdateDayTitle?.(day.id, 'New Title');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-028: handleSavePlace add path covers addPlace logic', () => {
|
|
it('calls onSave on PlaceFormModal to exercise the add-place handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call onSave with editingPlace=null (add path)
|
|
await act(async () => {
|
|
await capturedPlaceFormModalProps.current.onSave?.({ name: 'Test Place', lat: 1, lng: 2 });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-029: handleSavePlace edit path covers updatePlace logic', () => {
|
|
it('calls onEditPlace then onSave on PlaceFormModal to exercise the edit-place handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, { places: [place] } as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Set editingPlace via captured props (uses the inline lambda that calls setEditingPlace)
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onEditPlace?.(place, null);
|
|
});
|
|
|
|
// Now onSave uses the edit path (editingPlace is set)
|
|
await act(async () => {
|
|
await capturedPlaceFormModalProps.current.onSave?.({ name: 'Updated', lat: 1, lng: 2 });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-030: confirmDeletePlace covers delete-place logic', () => {
|
|
it('calls onDeletePlace then ConfirmDialog onConfirm to exercise confirmDeletePlace', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, { places: [place] } as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Trigger setDeletePlaceId by calling onDeletePlace inline lambda
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onDeletePlace?.(place.id);
|
|
});
|
|
|
|
// Wait for ConfirmDialog to receive the updated onConfirm
|
|
await waitFor(() => {
|
|
expect(typeof capturedConfirmDialogProps.current.onConfirm).toBe('function');
|
|
});
|
|
|
|
// Call onConfirm to run confirmDeletePlace body
|
|
await act(async () => {
|
|
await capturedConfirmDialogProps.current.onConfirm?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-031: handleSaveReservation add path covers reservation creation', () => {
|
|
it('calls onSave on ReservationModal to exercise the add-reservation handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call onSave with editingReservation=null (add path)
|
|
await act(async () => {
|
|
await capturedReservationModalProps.current.onSave?.({ name: 'Test Booking', type: 'restaurant', status: 'confirmed' });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-032: handleDeleteReservation covers reservation deletion', () => {
|
|
it('calls onDelete from ReservationsPanel to exercise the delete-reservation handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const bookingsTab = await screen.findByTitle('Bookings');
|
|
fireEvent.click(bookingsTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('reservations-panel')).toBeInTheDocument();
|
|
});
|
|
|
|
await act(async () => {
|
|
await capturedReservationsPanelProps.current.onDelete?.(1);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-033: onDayDetail covers DayDetailPanel render path', () => {
|
|
it('shows DayDetailPanel section when onDayDetail is called via DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Triggers showDayDetail = day, covering DayDetailPanel conditional block
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onDayDetail?.(day);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-034: onRouteCalculated covers route state setters', () => {
|
|
it('calls onRouteCalculated with route data and null to cover both branches', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onRouteCalculated?.({
|
|
coordinates: [[1, 2], [3, 4]],
|
|
distanceText: '1 km',
|
|
durationText: '10 min',
|
|
walkingText: '15 min',
|
|
drivingText: '5 min',
|
|
});
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onRouteCalculated?.(null);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-035: onAddReservation covers reservation modal open', () => {
|
|
it('calls onAddReservation to open the ReservationModal', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onAddReservation?.(day.id);
|
|
});
|
|
|
|
// ReservationModal should now be open (isOpen=true in its props)
|
|
await waitFor(() => {
|
|
expect(capturedReservationModalProps.current.isOpen).toBe(true);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-036: handleUndo covers undo execution', () => {
|
|
it('calls onUndo through captured DayPlanSidebar props', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onUndo?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-038: DayDetailPanel onClose and onToggleCollapse callbacks', () => {
|
|
it('calls DayDetailPanel onClose and onToggleCollapse to cover those inline lambdas', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Set showDayDetail
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onDayDetail?.(day);
|
|
});
|
|
|
|
// Call onClose — covers line 766 lambda: setShowDayDetail(null); handleSelectDay(null)
|
|
await act(async () => {
|
|
capturedDayDetailPanelProps.current.onClose?.();
|
|
});
|
|
|
|
// Re-open to test onToggleCollapse
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onDayDetail?.(day);
|
|
});
|
|
|
|
// Call onToggleCollapse — covers line 771 lambda: setDayDetailCollapsed(c => !c)
|
|
await act(async () => {
|
|
capturedDayDetailPanelProps.current.onToggleCollapse?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-039: PlaceFormModal onClose covers modal close lambda', () => {
|
|
it('calls PlaceFormModal onClose to cover the modal close handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
|
|
// Covers line 954 onClose lambda body
|
|
await act(async () => {
|
|
capturedPlaceFormModalProps.current.onClose?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-040: ReservationModal onClose covers modal close lambda', () => {
|
|
it('calls ReservationModal onClose to cover the modal close handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
|
|
// Covers line 957 onClose lambda body
|
|
await act(async () => {
|
|
capturedReservationModalProps.current.onClose?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-041: handleSaveReservation edit path covers update reservation', () => {
|
|
it('calls onEdit then onSave on ReservationModal to exercise the edit-reservation handler', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
// Navigate to Bookings tab so ReservationsPanel is rendered
|
|
const bookingsTab = await screen.findByTitle('Bookings');
|
|
fireEvent.click(bookingsTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('reservations-panel')).toBeInTheDocument();
|
|
});
|
|
|
|
// Set editingReservation via captured onEdit prop (inline lambda in JSX)
|
|
const fakeReservation = { id: 1, trip_id: 42, name: 'Test', type: 'restaurant', status: 'confirmed' };
|
|
await act(async () => {
|
|
capturedReservationsPanelProps.current.onEdit?.(fakeReservation);
|
|
});
|
|
|
|
// Call onSave — now takes edit path (editingReservation is set)
|
|
await act(async () => {
|
|
await capturedReservationModalProps.current.onSave?.({
|
|
name: 'Updated Booking',
|
|
type: 'restaurant',
|
|
status: 'confirmed',
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-042: TripMembersModal onClose covers modal close lambda', () => {
|
|
it('calls TripMembersModal onClose to cover the inline lambda', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
|
|
// Covers TripMembersModal onClose lambda: () => setShowMembersModal(false)
|
|
await act(async () => {
|
|
capturedTripMembersModalProps.current.onClose?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-043: TripFormModal onClose covers modal close lambda', () => {
|
|
it('calls TripFormModal onClose to cover the inline lambda', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('map-view')).toBeInTheDocument();
|
|
});
|
|
|
|
// Covers TripFormModal onClose lambda: () => setShowTripForm(false)
|
|
await act(async () => {
|
|
capturedTripFormModalProps.current.onClose?.();
|
|
});
|
|
|
|
// Also cover TripFormModal onSave lambda
|
|
await act(async () => {
|
|
await capturedTripFormModalProps.current.onSave?.({ name: 'Updated Trip' });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-044: FileManager callbacks cover file operation lambdas', () => {
|
|
it('calls FileManager onUpload/onDelete/onUpdate to cover inline lambda bodies', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ addons: [{ id: 'documents', type: 'documents' }] })
|
|
)
|
|
);
|
|
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const filesTab = await screen.findByTitle('Files');
|
|
fireEvent.click(filesTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('file-manager')).toBeInTheDocument();
|
|
});
|
|
|
|
// Call FileManager callbacks — covers lines 928-930 lambda bodies
|
|
await act(async () => {
|
|
const fd = new FormData();
|
|
await capturedFileManagerProps.current.onUpload?.(fd).catch(() => {});
|
|
});
|
|
|
|
await act(async () => {
|
|
await capturedFileManagerProps.current.onDelete?.(1).catch(() => {});
|
|
});
|
|
|
|
await act(async () => {
|
|
capturedFileManagerProps.current.onUpdate?.(1, {});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-045: ReservationsPanel onNavigateToFiles covers inline lambda', () => {
|
|
it('calls onNavigateToFiles to cover the inline lambda body', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
const bookingsTab = await screen.findByTitle('Bookings');
|
|
fireEvent.click(bookingsTab);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('reservations-panel')).toBeInTheDocument();
|
|
});
|
|
|
|
// Covers line 907 lambda: () => handleTabChange('dateien')
|
|
await act(async () => {
|
|
capturedReservationsPanelProps.current.onNavigateToFiles?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-046: Invalid session tab resets to plan', () => {
|
|
it('resets activeTab to "plan" when saved tab is no longer in TRIP_TABS', async () => {
|
|
// Save a tab id that requires the "memories" addon (disabled by default)
|
|
sessionStorage.setItem('trip-tab-42', 'memories');
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
|
|
// The useEffect should detect the invalid tab and reset it
|
|
await waitFor(() => {
|
|
expect(sessionStorage.getItem('trip-tab-42')).toBe('plan');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-047: Desktop PlaceInspector onEdit with selectedAssignment', () => {
|
|
it('calls onEdit on desktop PlaceInspector with selectedAssignmentId to cover if-branch', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
const assignment = buildAssignment({ id: 10, day_id: 99, place, order_index: 0 });
|
|
|
|
mockPlaceSelectionState.selectedPlaceId = place.id;
|
|
mockPlaceSelectionState.selectedAssignmentId = assignment.id;
|
|
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, {
|
|
places: [place],
|
|
assignments: { '99': [assignment] },
|
|
} as any);
|
|
|
|
renderPlannerPage(42);
|
|
act(() => { vi.runAllTimers(); });
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('place-inspector')).toBeInTheDocument();
|
|
});
|
|
|
|
// onEdit with selectedAssignmentId set — covers lines 795-798 (if branch)
|
|
await act(async () => {
|
|
capturedPlaceInspectorProps.current.onEdit?.();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-048: Mobile PlaceInspector portal renders when isMobile is true', () => {
|
|
it('renders PlaceInspector in mobile portal and covers mobile callbacks', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
// Simulate mobile viewport
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 375 });
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
|
|
mockPlaceSelectionState.selectedPlaceId = place.id;
|
|
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, { places: [place] } as any);
|
|
|
|
renderPlannerPage(42);
|
|
act(() => { vi.runAllTimers(); });
|
|
vi.useRealTimers();
|
|
|
|
// Mobile portal renders the PlaceInspector (lines 830-879)
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('place-inspector')).toBeInTheDocument();
|
|
});
|
|
|
|
// onEdit without assignment — covers else branch at line 799
|
|
await act(async () => {
|
|
capturedPlaceInspectorProps.current.onEdit?.();
|
|
});
|
|
|
|
// onClose — covers mobile onClose lambda
|
|
await act(async () => {
|
|
capturedPlaceInspectorProps.current.onClose?.();
|
|
});
|
|
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1024 });
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-049: Mobile sidebar left panel opens via Plan button', () => {
|
|
it('clicking the mobile Plan button opens the left sidebar portal (lines 882-893)', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 375 });
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
act(() => { vi.runAllTimers(); });
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// The mobile portal buttons are rendered to document.body.
|
|
// The "Plan" tab button has title="Plan"; the mobile portal button does not.
|
|
const mobilePlanBtn = Array.from(document.body.querySelectorAll('button')).find(
|
|
b => b.textContent === 'Plan' && !b.getAttribute('title'),
|
|
);
|
|
|
|
if (mobilePlanBtn) {
|
|
await act(async () => { fireEvent.click(mobilePlanBtn); });
|
|
|
|
// Mobile sidebar portal renders DayPlanSidebar — now two instances
|
|
await waitFor(() => {
|
|
expect(screen.getAllByTestId('day-plan-sidebar').length).toBeGreaterThanOrEqual(2);
|
|
});
|
|
|
|
// Close the mobile sidebar via the X button inside the portal header
|
|
const closeButtons = Array.from(document.body.querySelectorAll('button')).filter(
|
|
b => !b.textContent || b.textContent.trim() === '',
|
|
);
|
|
if (closeButtons.length > 0) {
|
|
await act(async () => { fireEvent.click(closeButtons[0]); });
|
|
}
|
|
}
|
|
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1024 });
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-050: Mobile sidebar right panel opens via Places button', () => {
|
|
it('clicking the mobile Places button opens the right sidebar portal (lines 894)', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 375 });
|
|
|
|
seedTripStore({ id: 42 });
|
|
|
|
renderPlannerPage(42);
|
|
act(() => { vi.runAllTimers(); });
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('places-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// "Places" tab doesn't exist; the mobile portal "Places" button has no title
|
|
const mobilePlacesBtn = Array.from(document.body.querySelectorAll('button')).find(
|
|
b => b.textContent === 'Places' && !b.getAttribute('title'),
|
|
);
|
|
|
|
if (mobilePlacesBtn) {
|
|
await act(async () => { fireEvent.click(mobilePlacesBtn); });
|
|
|
|
// PlacesSidebar renders in mobile sidebar portal
|
|
await waitFor(() => {
|
|
expect(screen.getAllByTestId('places-sidebar').length).toBeGreaterThanOrEqual(2);
|
|
});
|
|
}
|
|
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1024 });
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-051: Mobile Plan sidebar stays mounted after onPlaceClick (issue #932)', () => {
|
|
it('does not unmount the mobile Plan portal when a place is tapped, preserving scroll position', async () => {
|
|
vi.useFakeTimers();
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 375 });
|
|
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
const assignment = buildAssignment({ id: 10, day_id: 99, place, order_index: 0 });
|
|
seedTripStore({ id: 42 });
|
|
seedStore(useTripStore, {
|
|
places: [place],
|
|
assignments: { '99': [assignment] },
|
|
} as any);
|
|
|
|
renderPlannerPage(42);
|
|
act(() => { vi.runAllTimers(); });
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Open the mobile Plan portal via the bottom-nav Plan button (selector mirrors FE-PAGE-PLANNER-049).
|
|
const mobilePlanBtn = Array.from(document.body.querySelectorAll('button')).find(
|
|
b => b.textContent === 'Plan' && !b.getAttribute('title'),
|
|
);
|
|
expect(mobilePlanBtn).toBeTruthy();
|
|
await act(async () => { fireEvent.click(mobilePlanBtn!); });
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getAllByTestId('day-plan-sidebar').length).toBe(2);
|
|
});
|
|
|
|
// The mock factory overwrites capturedDayPlanSidebarProps on each mount,
|
|
// so current holds the mobile portal instance's props.
|
|
const mobileOnPlaceClick = capturedDayPlanSidebarProps.current.onPlaceClick;
|
|
expect(typeof mobileOnPlaceClick).toBe('function');
|
|
|
|
await act(async () => {
|
|
mobileOnPlaceClick(place.id, assignment.id);
|
|
});
|
|
|
|
// Invariant: portal must NOT unmount — both instances persist.
|
|
// Pre-fix: collapses to 1 (setMobileSidebarOpen(null) destroyed scroll container).
|
|
// Post-fix: stays at 2, browser preserves scrollTop on the living DOM node.
|
|
expect(screen.getAllByTestId('day-plan-sidebar').length).toBe(2);
|
|
|
|
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1024 });
|
|
});
|
|
});
|
|
|
|
describe('FE-PAGE-PLANNER-037: onExpandedDaysChange covers mapPlaces hidden logic', () => {
|
|
it('calls onExpandedDaysChange to trigger mapPlaces hidden set computation', async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const { day } = seedTripStore({ id: 42 });
|
|
const place = buildPlace({ id: 1, trip_id: 42, lat: 48.8566, lng: 2.3522 });
|
|
const assignment = buildAssignment({ id: 10, day_id: day.id, place, order_index: 0 });
|
|
seedStore(useTripStore, {
|
|
places: [place],
|
|
assignments: { [String(day.id)]: [assignment] },
|
|
} as any);
|
|
|
|
renderPlannerPage(42);
|
|
|
|
act(() => { vi.runAllTimers(); });
|
|
|
|
vi.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('day-plan-sidebar')).toBeInTheDocument();
|
|
});
|
|
|
|
// Set expandedDayIds — some day not in the set → place is hidden in mapPlaces
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onExpandedDaysChange?.(new Set([999]));
|
|
});
|
|
|
|
// Then include the actual day → place is un-hidden
|
|
await act(async () => {
|
|
capturedDayPlanSidebarProps.current.onExpandedDaysChange?.(new Set([day.id]));
|
|
});
|
|
});
|
|
});
|
|
});
|