mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-23 07:11: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.
826 lines
37 KiB
TypeScript
826 lines
37 KiB
TypeScript
// FE-PLANNER-RESMODAL-001 to FE-PLANNER-RESMODAL-052
|
|
import { render, screen, waitFor, fireEvent } from '../../../tests/helpers/render';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { server } from '../../../tests/helpers/msw/server';
|
|
import { useAuthStore } from '../../store/authStore';
|
|
import { useTripStore } from '../../store/tripStore';
|
|
import { useAddonStore } from '../../store/addonStore';
|
|
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
|
import {
|
|
buildUser,
|
|
buildTrip,
|
|
buildDay,
|
|
buildPlace,
|
|
buildAssignment,
|
|
buildReservation,
|
|
buildTripFile,
|
|
} from '../../../tests/helpers/factories';
|
|
import { ReservationModal } from './ReservationModal';
|
|
|
|
// Mock react-router-dom useParams
|
|
vi.mock('react-router-dom', async (importActual) => {
|
|
const actual = await importActual<typeof import('react-router-dom')>();
|
|
return { ...actual, useParams: () => ({ id: '1' }) };
|
|
});
|
|
|
|
// Mock CustomDatePicker as a simple text input
|
|
vi.mock('../shared/CustomDateTimePicker', () => ({
|
|
CustomDatePicker: ({ value, onChange, placeholder }: { value: string; onChange: (v: string) => void; placeholder?: string }) => (
|
|
<input
|
|
data-testid="date-picker"
|
|
type="text"
|
|
value={value}
|
|
onChange={e => onChange(e.target.value)}
|
|
placeholder={placeholder ?? 'YYYY-MM-DD'}
|
|
/>
|
|
),
|
|
}));
|
|
|
|
// Mock CustomTimePicker as a simple text input
|
|
vi.mock('../shared/CustomTimePicker', () => ({
|
|
default: ({ value, onChange, placeholder }: { value: string; onChange: (v: string) => void; placeholder?: string }) => (
|
|
<input
|
|
data-testid="time-picker"
|
|
type="text"
|
|
value={value}
|
|
onChange={e => onChange(e.target.value)}
|
|
placeholder={placeholder ?? '00:00'}
|
|
/>
|
|
),
|
|
}));
|
|
|
|
const defaultProps = {
|
|
isOpen: true,
|
|
onClose: vi.fn(),
|
|
onSave: vi.fn().mockResolvedValue(undefined),
|
|
reservation: null,
|
|
days: [],
|
|
places: [],
|
|
assignments: {},
|
|
selectedDayId: null,
|
|
files: [],
|
|
onFileUpload: vi.fn().mockResolvedValue(undefined),
|
|
onFileDelete: vi.fn().mockResolvedValue(undefined),
|
|
accommodations: [],
|
|
};
|
|
|
|
beforeEach(() => {
|
|
resetAllStores();
|
|
seedStore(useAuthStore, { user: buildUser(), isAuthenticated: true });
|
|
seedStore(useTripStore, { trip: buildTrip({ id: 1 }), budgetItems: [] });
|
|
// addonStore: budget addon disabled
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('ReservationModal', () => {
|
|
// ── Rendering ──────────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-001: renders without crashing', () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
expect(document.body).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-002: shows "New Reservation" title for new reservation', () => {
|
|
render(<ReservationModal {...defaultProps} reservation={null} />);
|
|
expect(screen.getByText(/New Reservation/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-003: shows "Edit Reservation" title when editing', () => {
|
|
const res = buildReservation({ title: 'Nice Dinner', type: 'restaurant' });
|
|
render(<ReservationModal {...defaultProps} reservation={res} />);
|
|
expect(screen.getByText(/Edit Reservation/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-004: title input is required — onSave not called with empty title', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
const submitBtn = screen.getByRole('button', { name: /^Add$/i });
|
|
await userEvent.click(submitBtn);
|
|
expect(onSave).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-005: all 5 type buttons are visible (transport types removed)', () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
expect(screen.getByRole('button', { name: /Accommodation/i })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /Restaurant/i })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /Event/i })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /Tour/i })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: /Other/i })).toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: /^Flight$/i })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: /^Train$/i })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: /^Car$/i })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: /^Cruise$/i })).not.toBeInTheDocument();
|
|
});
|
|
|
|
// ── Type selection ──────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-006: clicking Event type button activates it', async () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
const eventBtn = screen.getByRole('button', { name: /Event/i });
|
|
await userEvent.click(eventBtn);
|
|
expect(eventBtn).toHaveClass('bg-[var(--text-primary)]');
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-008: hotel type shows check-in/check-out time fields', async () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
await userEvent.click(screen.getByRole('button', { name: /Accommodation/i }));
|
|
const checkInLabels = screen.getAllByText(/Check-in/i);
|
|
expect(checkInLabels.length).toBeGreaterThanOrEqual(1);
|
|
expect(screen.getByText(/Check-out/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-009: restaurant type shows location field', async () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
await userEvent.click(screen.getByRole('button', { name: /Restaurant/i }));
|
|
expect(screen.getByPlaceholderText(/Address, Airport/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-010: hotel type hides assignment picker', async () => {
|
|
const day = buildDay({ id: 1, title: 'Day 1' });
|
|
const place = buildPlace({ name: 'Museum' });
|
|
const assignment = buildAssignment({ id: 99, day_id: 1, place });
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
days={[day]}
|
|
assignments={{ '1': [assignment] }}
|
|
/>
|
|
);
|
|
// Switch to hotel type
|
|
await userEvent.click(screen.getByRole('button', { name: /Accommodation/i }));
|
|
expect(screen.queryByText(/Link to day assignment/i)).not.toBeInTheDocument();
|
|
});
|
|
|
|
// ── Form population from existing reservation ──────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-011: editing pre-fills title', () => {
|
|
const res = buildReservation({ title: 'Paris Hotel', type: 'hotel', status: 'confirmed' });
|
|
render(<ReservationModal {...defaultProps} reservation={res} />);
|
|
expect(screen.getByDisplayValue('Paris Hotel')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-012: editing pre-fills confirmation number', () => {
|
|
const res = buildReservation({ confirmation_number: 'XYZ123' });
|
|
render(<ReservationModal {...defaultProps} reservation={res} />);
|
|
expect(screen.getByDisplayValue('XYZ123')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-013: editing pre-fills notes', () => {
|
|
const res = buildReservation({ notes: 'Breakfast included' });
|
|
render(<ReservationModal {...defaultProps} reservation={res} />);
|
|
expect(screen.getByDisplayValue('Breakfast included')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-014: editing pre-fills type — restaurant type shows location field', () => {
|
|
const res = buildReservation({ type: 'restaurant', location: 'Via Roma 1' });
|
|
render(<ReservationModal {...defaultProps} reservation={res} />);
|
|
expect(screen.getByDisplayValue('Via Roma 1')).toBeInTheDocument();
|
|
});
|
|
|
|
// ── Validation ──────────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-015: end datetime before start shows error and blocks submit', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
const addToast = vi.fn();
|
|
window.__addToast = addToast;
|
|
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
// Fill in the title
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'My Flight');
|
|
|
|
// Set start date/time via the date-picker inputs (mocked as text inputs)
|
|
// reservation_time is rendered as two separate pickers: date part and time part
|
|
const datePickers = screen.getAllByTestId('date-picker');
|
|
const timePickers = screen.getAllByTestId('time-picker');
|
|
|
|
// First date picker = start date, second = end date
|
|
fireEvent.change(datePickers[0], { target: { value: '2025-06-10' } });
|
|
fireEvent.change(timePickers[0], { target: { value: '10:00' } });
|
|
// End date before start date
|
|
fireEvent.change(datePickers[1], { target: { value: '2025-06-09' } });
|
|
fireEvent.change(timePickers[1], { target: { value: '09:00' } });
|
|
|
|
// When isEndBeforeStart=true the submit button is disabled, so fire submit on the form directly.
|
|
// The Save button now lives in the Modal's sticky footer (outside the <form>), so we query
|
|
// the form by tag instead of walking up from the button.
|
|
const form = document.querySelector('form')!;
|
|
fireEvent.submit(form);
|
|
|
|
expect(onSave).not.toHaveBeenCalled();
|
|
expect(addToast).toHaveBeenCalledWith(
|
|
expect.stringMatching(/End date\/time must be after start/i),
|
|
'error',
|
|
undefined,
|
|
);
|
|
|
|
delete window.__addToast;
|
|
});
|
|
|
|
// ── Submit flow ─────────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-016: submitting valid restaurant booking calls onSave with correct shape', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Restaurant/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Le Jules Verne');
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ title: 'Le Jules Verne', type: 'restaurant' })
|
|
);
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-017: status confirmed — onSave called with status confirmed', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Test Booking');
|
|
|
|
// The status CustomSelect renders as a button for its trigger — check for "Pending" text and change it
|
|
// CustomSelect renders a div/button with the current value label. We look for the status select area.
|
|
// Since CustomSelect is not mocked, we find the select by its displayed value.
|
|
// The easiest approach: render with a reservation that has status 'confirmed'
|
|
const res = buildReservation({ status: 'confirmed', type: 'flight', title: 'My Booking' });
|
|
const { unmount } = render(<ReservationModal {...defaultProps} reservation={res} onSave={onSave} />);
|
|
const updateBtn = screen.getAllByRole('button', { name: /Update/i })[0];
|
|
await userEvent.click(updateBtn);
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ status: 'confirmed' })
|
|
);
|
|
unmount();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-018: onClose NOT called after successful save (parent controls closing)', async () => {
|
|
const onClose = vi.fn();
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onClose={onClose} onSave={onSave} />);
|
|
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Test Booking');
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
// The component does NOT call onClose after save — the parent controls that
|
|
expect(onClose).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-019: save button is disabled while saving', async () => {
|
|
let resolveOnSave: () => void;
|
|
const onSave = vi.fn().mockReturnValue(
|
|
new Promise<void>(resolve => { resolveOnSave = resolve; })
|
|
);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Test Booking');
|
|
|
|
const submitBtn = screen.getByRole('button', { name: /^Add$/i });
|
|
await userEvent.click(submitBtn);
|
|
|
|
// While promise is pending, the button should be disabled
|
|
await waitFor(() => {
|
|
expect(screen.getByRole('button', { name: /Saving/i })).toBeDisabled();
|
|
});
|
|
|
|
// Cleanup
|
|
resolveOnSave!();
|
|
});
|
|
|
|
// ── Assignment linking ──────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-020: assignment picker appears when days/assignments are populated (non-hotel)', () => {
|
|
const day = buildDay({ id: 1, title: 'Day 1' });
|
|
const place = buildPlace({ name: 'Museum' });
|
|
const assignment = buildAssignment({ id: 99, day_id: 1, order_index: 0, place });
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
days={[day]}
|
|
assignments={{ '1': [assignment] }}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText(/Link to day assignment/i)).toBeInTheDocument();
|
|
});
|
|
|
|
// ── Files ──────────────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-022: attached files shown for existing reservation', () => {
|
|
const res = buildReservation({ id: 5 });
|
|
const file = buildTripFile({
|
|
id: 1,
|
|
trip_id: 1,
|
|
original_name: 'ticket.pdf',
|
|
});
|
|
// Add reservation_id field manually (not in standard TripFile type but used in component)
|
|
(file as any).reservation_id = 5;
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
files={[file]}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText('ticket.pdf')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-023: Cancel button calls onClose', async () => {
|
|
const onClose = vi.fn();
|
|
render(<ReservationModal {...defaultProps} onClose={onClose} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Cancel/i }));
|
|
expect(onClose).toHaveBeenCalled();
|
|
});
|
|
|
|
// ── Budget addon ─────────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-024: budget section visible when budget addon is enabled', () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
|
|
loaded: true,
|
|
});
|
|
render(<ReservationModal {...defaultProps} />);
|
|
expect(screen.getByText(/^Price$/i)).toBeInTheDocument();
|
|
expect(screen.getByText(/Budget category/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-025: budget price input accepts valid decimal', async () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
|
|
loaded: true,
|
|
});
|
|
render(<ReservationModal {...defaultProps} />);
|
|
const priceInput = screen.getByPlaceholderText('0.00');
|
|
await userEvent.type(priceInput, '99.99');
|
|
expect((priceInput as HTMLInputElement).value).toBe('99.99');
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-026: budget hint shown when price > 0', async () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
|
|
loaded: true,
|
|
});
|
|
render(<ReservationModal {...defaultProps} />);
|
|
const priceInput = screen.getByPlaceholderText('0.00');
|
|
await userEvent.type(priceInput, '50');
|
|
expect(screen.getByText(/budget entry will be created/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-027: budget fields included in onSave when price is set', async () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
|
|
loaded: true,
|
|
});
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Hotel Paris');
|
|
await userEvent.type(screen.getByPlaceholderText('0.00'), '120');
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ create_budget_entry: expect.objectContaining({ total_price: 120 }) })
|
|
);
|
|
});
|
|
|
|
// ── File upload ───────────────────────────────────────────────────────────────
|
|
|
|
it('FE-PLANNER-RESMODAL-028: pending file added for new reservation on file input change', async () => {
|
|
render(<ReservationModal {...defaultProps} reservation={null} />);
|
|
|
|
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
|
|
const testFile = new File(['content'], 'document.pdf', { type: 'application/pdf' });
|
|
|
|
fireEvent.change(fileInput, { target: { files: [testFile] } });
|
|
|
|
// Pending file name should appear in the list
|
|
await waitFor(() => {
|
|
expect(screen.getByText('document.pdf')).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-029: attach file button is rendered when onFileUpload provided', () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
expect(screen.getByRole('button', { name: /Attach file/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-030: hotel type — saving calls onSave with correct hotel shape', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Accommodation/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Grand Hotel');
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ title: 'Grand Hotel', type: 'hotel' })
|
|
);
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-031: event type — saving calls onSave with event type', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Event/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Louvre Museum');
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ title: 'Louvre Museum', type: 'event' })
|
|
);
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-032: edit mode — save button shows "Update"', () => {
|
|
const res = buildReservation({ title: 'My Trip', type: 'other' });
|
|
render(<ReservationModal {...defaultProps} reservation={res} />);
|
|
expect(screen.getByRole('button', { name: /^Update$/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-033: modal is closed when isOpen=false', () => {
|
|
render(<ReservationModal {...defaultProps} isOpen={false} />);
|
|
// When isOpen=false the Modal component should hide content
|
|
expect(screen.queryByText(/New Reservation/i)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-034: location and confirmation number inputs are present', () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
expect(screen.getByPlaceholderText(/Address, Airport/i)).toBeInTheDocument();
|
|
expect(screen.getByPlaceholderText(/e\.g\. ABC12345/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-036: file upload to existing reservation calls onFileUpload', async () => {
|
|
const onFileUpload = vi.fn().mockResolvedValue(undefined);
|
|
const res = buildReservation({ id: 10, title: 'My Trip', type: 'other' });
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
onFileUpload={onFileUpload}
|
|
/>
|
|
);
|
|
|
|
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
|
|
const testFile = new File(['content'], 'boarding-pass.pdf', { type: 'application/pdf' });
|
|
fireEvent.change(fileInput, { target: { files: [testFile] } });
|
|
|
|
await waitFor(() => expect(onFileUpload).toHaveBeenCalled());
|
|
const [fd] = onFileUpload.mock.calls[0] as [FormData];
|
|
expect(fd.get('file')).toBeTruthy();
|
|
// FormData.append coerces numbers to strings
|
|
expect(fd.get('reservation_id')).toBe('10');
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-037: link existing file button appears when unattached files exist', () => {
|
|
const res = buildReservation({ id: 5 });
|
|
// File NOT attached to this reservation
|
|
const unattachedFile = buildTripFile({ id: 99, original_name: 'invoice.pdf' });
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
files={[unattachedFile]}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByRole('button', { name: /Link existing file/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-038: clicking "link existing file" shows file picker dropdown', async () => {
|
|
const res = buildReservation({ id: 5 });
|
|
const unattachedFile = buildTripFile({ id: 99, original_name: 'invoice.pdf' });
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
files={[unattachedFile]}
|
|
/>
|
|
);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Link existing file/i }));
|
|
expect(screen.getByText('invoice.pdf')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-039: clicking file in picker links it and closes picker', async () => {
|
|
server.use(
|
|
http.post('/api/trips/1/files/99/link', () => HttpResponse.json({ success: true })),
|
|
http.get('/api/trips/1/files', () => HttpResponse.json({ files: [] })),
|
|
);
|
|
|
|
const res = buildReservation({ id: 5 });
|
|
const unattachedFile = buildTripFile({ id: 99, original_name: 'invoice.pdf' });
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
files={[unattachedFile]}
|
|
/>
|
|
);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Link existing file/i }));
|
|
await userEvent.click(screen.getByText('invoice.pdf'));
|
|
|
|
// After linking, the file is moved to attached files and the "Link existing file" button disappears
|
|
// (all files are now attached, so the picker condition becomes false)
|
|
await waitFor(() => {
|
|
expect(screen.queryByRole('button', { name: /Link existing file/i })).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-040: removing pending file removes it from list', async () => {
|
|
render(<ReservationModal {...defaultProps} reservation={null} />);
|
|
|
|
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
|
|
const testFile = new File(['content'], 'draft.pdf', { type: 'application/pdf' });
|
|
fireEvent.change(fileInput, { target: { files: [testFile] } });
|
|
|
|
await waitFor(() => expect(screen.getByText('draft.pdf')).toBeInTheDocument());
|
|
|
|
// Click the X next to the pending file
|
|
const removeButtons = screen.getAllByRole('button');
|
|
const pendingFileRow = screen.getByText('draft.pdf').closest('div')!;
|
|
const removeBtn = pendingFileRow.querySelector('button')!;
|
|
await userEvent.click(removeBtn);
|
|
|
|
await waitFor(() => expect(screen.queryByText('draft.pdf')).not.toBeInTheDocument());
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-041: budget section not shown when addon disabled', () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
expect(screen.queryByPlaceholderText('0.00')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-042: hotel type metadata saved with check-in time', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Accommodation/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Grand Hotel');
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ title: 'Grand Hotel', type: 'hotel' })
|
|
);
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-043: hover styles applied to file picker items', async () => {
|
|
const res = buildReservation({ id: 5 });
|
|
const unattachedFile = buildTripFile({ id: 99, original_name: 'invoice.pdf' });
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
files={[unattachedFile]}
|
|
/>
|
|
);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /Link existing file/i }));
|
|
const filePickerItem = screen.getByText('invoice.pdf').closest('button')!;
|
|
fireEvent.mouseEnter(filePickerItem);
|
|
fireEvent.mouseLeave(filePickerItem);
|
|
// Just testing the handlers don't throw
|
|
expect(filePickerItem).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-044: budget category dropdown options include existing categories', () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
|
|
loaded: true,
|
|
});
|
|
seedStore(useTripStore, {
|
|
trip: buildTrip({ id: 1 }),
|
|
budgetItems: [
|
|
{ id: 1, trip_id: 1, name: 'Flight ticket', total_price: 300, category: 'Transport', paid_by_user_id: null, persons: 1, members: [], expense_date: null },
|
|
],
|
|
});
|
|
render(<ReservationModal {...defaultProps} />);
|
|
// Budget section is visible
|
|
expect(screen.getByText(/Budget category/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-045: tour type shows time pickers', async () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
await userEvent.click(screen.getByRole('button', { name: /^Tour$/i }));
|
|
await waitFor(() => {
|
|
expect(screen.getAllByTestId('time-picker').length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-046: other type renders and saves correctly', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
await userEvent.click(screen.getByRole('button', { name: /^Other$/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Misc item');
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
await waitFor(() => expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ type: 'other' })));
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-047: clicking budget category select changes the value', async () => {
|
|
seedStore(useAddonStore, {
|
|
addons: [{ id: 'budget', name: 'Budget', type: 'budget', icon: '', enabled: true }],
|
|
loaded: true,
|
|
});
|
|
seedStore(useTripStore, {
|
|
trip: buildTrip({ id: 1 }),
|
|
budgetItems: [
|
|
{ id: 1, trip_id: 1, name: 'Ticket', total_price: 100, category: 'Transport', paid_by_user_id: null, persons: 1, members: [], expense_date: null },
|
|
],
|
|
});
|
|
render(<ReservationModal {...defaultProps} />);
|
|
|
|
// Open the budget category CustomSelect (shows placeholder "Auto (from booking type)")
|
|
const budgetCategoryBtn = screen.getByText(/Auto \(from booking type\)/i).closest('button')!;
|
|
await userEvent.click(budgetCategoryBtn);
|
|
|
|
// Click the "Transport" category option
|
|
await waitFor(() => expect(screen.getByText('Transport')).toBeInTheDocument());
|
|
await userEvent.click(screen.getByText('Transport'));
|
|
|
|
// The select should now show "Transport"
|
|
expect(screen.getByText('Transport')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-048: clicking attach file button triggers file input', async () => {
|
|
render(<ReservationModal {...defaultProps} />);
|
|
const attachBtn = screen.getByRole('button', { name: /Attach file/i });
|
|
// Mock click on hidden file input
|
|
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
|
|
const clickSpy = vi.spyOn(fileInput, 'click').mockImplementation(() => {});
|
|
await userEvent.click(attachBtn);
|
|
expect(clickSpy).toHaveBeenCalled();
|
|
clickSpy.mockRestore();
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-049: unlinking a linked file removes it from attached list', async () => {
|
|
// First link the file, then unlink it via the X button
|
|
server.use(
|
|
http.post('/api/trips/1/files/42/link', () => HttpResponse.json({ success: true })),
|
|
http.get('/api/trips/1/files/42/links', () => HttpResponse.json({ links: [{ id: 1, reservation_id: 7 }] })),
|
|
http.delete('/api/trips/1/files/42/link/1', () => HttpResponse.json({ success: true })),
|
|
http.get('/api/trips/1/files', () => HttpResponse.json({ files: [] })),
|
|
);
|
|
|
|
const res = buildReservation({ id: 7 });
|
|
// File is NOT attached (no reservation_id) — it will be in the "link existing" picker
|
|
const looseFile = buildTripFile({ id: 42, original_name: 'receipt.pdf' });
|
|
|
|
render(
|
|
<ReservationModal
|
|
{...defaultProps}
|
|
reservation={res}
|
|
files={[looseFile]}
|
|
/>
|
|
);
|
|
|
|
// Link the file via the picker
|
|
await userEvent.click(screen.getByRole('button', { name: /Link existing file/i }));
|
|
await waitFor(() => expect(screen.getByText('receipt.pdf')).toBeInTheDocument());
|
|
await userEvent.click(screen.getByText('receipt.pdf'));
|
|
|
|
// File is now in attached list; "Link existing file" button gone
|
|
await waitFor(() =>
|
|
expect(screen.queryByRole('button', { name: /Link existing file/i })).not.toBeInTheDocument()
|
|
);
|
|
|
|
// Click the X to unlink
|
|
const fileRow = screen.getByText('receipt.pdf').closest('div')!;
|
|
const unlinkBtn = fileRow.querySelector('button[type="button"]')!;
|
|
await userEvent.click(unlinkBtn);
|
|
|
|
// File removed from attached list and "Link existing file" button reappears
|
|
await waitFor(() => {
|
|
expect(screen.getByRole('button', { name: /Link existing file/i })).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-035: hotel type saves correctly', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Accommodation$/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Hotel Test');
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
expect.objectContaining({ type: 'hotel' })
|
|
);
|
|
});
|
|
|
|
// ── Hotel day-range picker — non-monotonic IDs (issue #929) ───────────────
|
|
// Mirrors DayDetailPanel-056/057 for the ReservationModal path.
|
|
// ID layout: day_number 1-9 → IDs 17-25, day_number 10-16 → IDs 1-7.
|
|
|
|
function buildNonMonotonicDaysRM() {
|
|
return [
|
|
buildDay({ id: 17, trip_id: 1, date: '2026-04-30', day_number: 1 }),
|
|
buildDay({ id: 18, trip_id: 1, date: '2026-05-01', day_number: 2 }),
|
|
buildDay({ id: 19, trip_id: 1, date: '2026-05-02', day_number: 3 }),
|
|
buildDay({ id: 20, trip_id: 1, date: '2026-05-03', day_number: 4 }),
|
|
buildDay({ id: 21, trip_id: 1, date: '2026-05-04', day_number: 5 }),
|
|
buildDay({ id: 22, trip_id: 1, date: '2026-05-05', day_number: 6 }),
|
|
buildDay({ id: 23, trip_id: 1, date: '2026-05-06', day_number: 7 }),
|
|
buildDay({ id: 24, trip_id: 1, date: '2026-05-07', day_number: 8 }),
|
|
buildDay({ id: 25, trip_id: 1, date: '2026-05-08', day_number: 9 }),
|
|
buildDay({ id: 1, trip_id: 1, date: '2026-05-09', day_number: 10 }),
|
|
buildDay({ id: 2, trip_id: 1, date: '2026-05-10', day_number: 11 }),
|
|
buildDay({ id: 3, trip_id: 1, date: '2026-05-11', day_number: 12 }),
|
|
buildDay({ id: 4, trip_id: 1, date: '2026-05-12', day_number: 13 }),
|
|
buildDay({ id: 5, trip_id: 1, date: '2026-05-13', day_number: 14 }),
|
|
buildDay({ id: 6, trip_id: 1, date: '2026-05-14', day_number: 15 }),
|
|
buildDay({ id: 7, trip_id: 1, date: '2026-05-15', day_number: 16 }),
|
|
] as any[];
|
|
}
|
|
|
|
it('FE-PLANNER-RESMODAL-050: non-monotonic IDs — end picker with low ID does not clobber start', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
const days = buildNonMonotonicDaysRM();
|
|
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} days={days} />);
|
|
|
|
// Switch to hotel type
|
|
await userEvent.click(screen.getByRole('button', { name: /^Accommodation$/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Overlap Hotel');
|
|
|
|
// Open start picker (first "Select day" trigger) and select Day 1 (id=17)
|
|
const startTrigger = () => screen.getAllByRole('button').filter(b => b.textContent?.includes('Select day') || b.textContent?.startsWith('Day '))[0];
|
|
await userEvent.click(startTrigger());
|
|
await userEvent.click(screen.getAllByRole('button').find(b => b.textContent?.startsWith('Day 1') && !b.textContent?.startsWith('Day 1 ') || b.textContent?.trim() === 'Day 1')!);
|
|
|
|
// Open end picker and select Day 16 (id=7, low ID but last positionally)
|
|
const endTrigger = () => screen.getAllByRole('button').filter(b => b.textContent?.includes('Select day') || /^Day \d+/.test(b.textContent?.trim() ?? ''))[1];
|
|
await userEvent.click(endTrigger());
|
|
await userEvent.click(screen.getAllByRole('button').find(b => b.textContent?.startsWith('Day 16'))!);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
const saved = onSave.mock.calls[0][0];
|
|
// start must stay id=17 (Day 1) — old Math.max would clobber it to id=7
|
|
expect(saved.create_accommodation?.start_day_id).toBe(17);
|
|
expect(saved.create_accommodation?.end_day_id).toBe(7);
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-051: non-monotonic IDs — start picker does not collapse end when start has high ID', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
const days = buildNonMonotonicDaysRM();
|
|
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} days={days} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Accommodation$/i }));
|
|
await userEvent.type(screen.getByPlaceholderText(/e\.g\. Lufthansa/i), 'Span Hotel');
|
|
|
|
// Set end to Day 16 (id=7) first
|
|
const endTrigger = () => screen.getAllByRole('button').filter(b => b.textContent?.includes('Select day') || /^Day \d+/.test(b.textContent?.trim() ?? ''))[1];
|
|
await userEvent.click(endTrigger());
|
|
await userEvent.click(screen.getAllByRole('button').find(b => b.textContent?.startsWith('Day 16'))!);
|
|
|
|
// Set start to Day 9 (id=25, high ID but earlier by position than Day 16)
|
|
// Old code: Math.max(25, 7) = 25 → end collapses to Day 9.
|
|
// New code: position(id=25)=8 < position(id=7)=15 → end stays id=7.
|
|
const startTrigger = () => screen.getAllByRole('button').filter(b => b.textContent?.includes('Select day') || /^Day \d+/.test(b.textContent?.trim() ?? ''))[0];
|
|
await userEvent.click(startTrigger());
|
|
await userEvent.click(screen.getAllByRole('button').find(b => b.textContent?.startsWith('Day 9'))!);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
const saved = onSave.mock.calls[0][0];
|
|
expect(saved.create_accommodation?.start_day_id).toBe(25); // Day 9
|
|
expect(saved.create_accommodation?.end_day_id).toBe(7); // Day 16 — must NOT have collapsed
|
|
});
|
|
|
|
it('FE-PLANNER-RESMODAL-052: hotel with no accommodation_id sends assignment_id as null (issue #934)', async () => {
|
|
const onSave = vi.fn().mockResolvedValue(undefined);
|
|
// Hotel reservation with assignment_id set but no accommodation
|
|
const res = buildReservation({
|
|
id: 10, title: 'Stale Hotel', type: 'hotel', status: 'confirmed',
|
|
accommodation_id: null, assignment_id: 99,
|
|
} as any);
|
|
|
|
render(<ReservationModal {...defaultProps} onSave={onSave} reservation={res} />);
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /^Update$/i }));
|
|
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave.mock.calls[0][0].assignment_id).toBeNull();
|
|
});
|
|
});
|