mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
test(journey): keep the journey page suite's journal and handlers in its helper
The suite carried its sample journal and the journal's default handlers inline, and waiting for the reload in FE-PAGE-JOURNEYDETAIL-153 took it past its size limit. Both move to tests/helpers/journeyDetail.ts beside seedJourneyOwner; the file is 142 lines shorter and its size baseline follows.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
"src/components/Studio/countryShapes.ts": 2595,
|
||||
"src/index.css": 1636,
|
||||
"src/mobile/screens/admin/MAdminPluginsPanel.tsx": 1503,
|
||||
"src/pages/JourneyDetailPage.test.tsx": 4028,
|
||||
"src/pages/JourneyDetailPage.test.tsx": 3886,
|
||||
"src/pages/LoginPage.tsx": 1294,
|
||||
"src/pages/TripPlannerPage.tsx": 1128,
|
||||
"src/pages/atlas/useAtlas.ts": 1207,
|
||||
|
||||
@@ -5,7 +5,7 @@ import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { server } from '../../tests/helpers/msw/server';
|
||||
import { resetAllStores } from '../../tests/helpers/store';
|
||||
import { seedJourneyOwner } from '../../tests/helpers/journeyDetail';
|
||||
import { journeyNow as now, mockJourneyDetail, seedJourneyOwner, setupJourneyHandlers as setupDefaultHandlers } from '../../tests/helpers/journeyDetail';
|
||||
import { buildUser } from '../../tests/helpers/factories';
|
||||
import { useJourneyStore } from '../store/journeyStore';
|
||||
import JourneyDetailPage from './JourneyDetailPage';
|
||||
@@ -77,157 +77,6 @@ vi.mock('react-router', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
// ── Mock Data ────────────────────────────────────────────────────────────────
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
const mockJourneyDetail = {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
title: 'Italy 2026',
|
||||
subtitle: 'Rome, Florence, Venice',
|
||||
status: 'active',
|
||||
cover_image: null,
|
||||
cover_gradient: null,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
entries: [
|
||||
{
|
||||
id: 10,
|
||||
journey_id: 1,
|
||||
author_id: 1,
|
||||
type: 'entry',
|
||||
entry_date: '2026-03-15',
|
||||
title: 'Arrived in Rome',
|
||||
story: 'Amazing city!',
|
||||
location_name: 'Rome',
|
||||
location_lat: 41.9,
|
||||
location_lng: 12.5,
|
||||
mood: 'amazing',
|
||||
weather: 'sunny',
|
||||
tags: ['culture'],
|
||||
pros_cons: { pros: ['Great food'], cons: ['Crowded'] },
|
||||
visibility: 'private',
|
||||
sort_order: 0,
|
||||
entry_time: '10:00',
|
||||
photos: [
|
||||
{
|
||||
id: 100,
|
||||
entry_id: 10,
|
||||
photo_id: 100,
|
||||
provider: 'local',
|
||||
file_path: 'photos/test.jpg',
|
||||
asset_id: null,
|
||||
owner_id: null,
|
||||
thumbnail_path: null,
|
||||
caption: 'Colosseum',
|
||||
sort_order: 0,
|
||||
width: 800,
|
||||
height: 600,
|
||||
shared: 1,
|
||||
created_at: now,
|
||||
},
|
||||
],
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
journey_id: 1,
|
||||
author_id: 1,
|
||||
type: 'entry',
|
||||
entry_date: '2026-03-16',
|
||||
title: 'Florence Day',
|
||||
story: null,
|
||||
location_name: 'Florence',
|
||||
location_lat: 43.77,
|
||||
location_lng: 11.25,
|
||||
mood: 'good',
|
||||
weather: 'cloudy',
|
||||
tags: [],
|
||||
pros_cons: null,
|
||||
visibility: 'private',
|
||||
sort_order: 0,
|
||||
entry_time: null,
|
||||
photos: [],
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
},
|
||||
],
|
||||
trips: [
|
||||
{
|
||||
trip_id: 5,
|
||||
added_at: now,
|
||||
title: 'Italy Trip',
|
||||
start_date: '2026-03-14',
|
||||
end_date: '2026-03-20',
|
||||
cover_image: null,
|
||||
currency: 'EUR',
|
||||
place_count: 8,
|
||||
},
|
||||
],
|
||||
contributors: [
|
||||
{
|
||||
journey_id: 1,
|
||||
user_id: 1,
|
||||
role: 'owner',
|
||||
added_at: now,
|
||||
username: 'testuser',
|
||||
avatar: null,
|
||||
},
|
||||
],
|
||||
stats: { entries: 2, photos: 1, places: 2 },
|
||||
gallery: [
|
||||
{
|
||||
id: 100,
|
||||
journey_id: 1,
|
||||
photo_id: 100,
|
||||
provider: 'local',
|
||||
file_path: 'photos/test.jpg',
|
||||
asset_id: null,
|
||||
owner_id: null,
|
||||
thumbnail_path: null,
|
||||
caption: 'Colosseum',
|
||||
sort_order: 0,
|
||||
width: 800,
|
||||
height: 600,
|
||||
shared: 1,
|
||||
created_at: now,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// ── MSW Handlers ─────────────────────────────────────────────────────────────
|
||||
|
||||
function setupDefaultHandlers(journeyOverride?: Record<string, unknown>) {
|
||||
const journey = journeyOverride
|
||||
? { ...mockJourneyDetail, ...journeyOverride }
|
||||
: mockJourneyDetail;
|
||||
|
||||
server.use(
|
||||
http.get('/api/journeys/1', () => {
|
||||
return HttpResponse.json(journey);
|
||||
}),
|
||||
http.get('/api/addons', () => {
|
||||
return HttpResponse.json({
|
||||
addons: [
|
||||
{ id: 'journey', name: 'Journey', type: 'feature', icon: 'book', enabled: true },
|
||||
{ id: 'immich', name: 'Immich', type: 'photo_provider', icon: 'camera', enabled: true },
|
||||
],
|
||||
});
|
||||
}),
|
||||
http.get('/api/integrations/memories/:provider/status', () => {
|
||||
return HttpResponse.json({ connected: false });
|
||||
}),
|
||||
http.patch('/api/journeys/1', () => {
|
||||
return HttpResponse.json({ ...mockJourneyDetail, title: 'Updated' });
|
||||
}),
|
||||
http.get('/api/journeys/1/share-link', () => {
|
||||
return HttpResponse.json({ link: null });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// ── Setup ────────────────────────────────────────────────────────────────────
|
||||
|
||||
const ownerUser = buildUser({ id: 1, username: 'testuser' });
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { useAddonStore } from '../../src/store/addonStore';
|
||||
import { useAuthStore } from '../../src/store/authStore';
|
||||
import { usePermissionsStore } from '../../src/store/permissionsStore';
|
||||
import type { User } from '../../src/types';
|
||||
import { server } from './msw/server';
|
||||
import { seedStore } from './store';
|
||||
|
||||
/**
|
||||
@@ -15,3 +17,151 @@ export function seedJourneyOwner(user: User): void {
|
||||
addons: [{ id: 'immich', name: 'Immich', type: 'photo_provider', enabled: true } as never],
|
||||
});
|
||||
}
|
||||
|
||||
/** When the suite's journal was made; its entries and photos are dated by it. */
|
||||
export const journeyNow = Date.now();
|
||||
|
||||
/** The journal the page suite opens: an owner's active trip journal with entries, photos and a synced trip. */
|
||||
export const mockJourneyDetail = {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
title: 'Italy 2026',
|
||||
subtitle: 'Rome, Florence, Venice',
|
||||
status: 'active',
|
||||
cover_image: null,
|
||||
cover_gradient: null,
|
||||
created_at: journeyNow,
|
||||
updated_at: journeyNow,
|
||||
entries: [
|
||||
{
|
||||
id: 10,
|
||||
journey_id: 1,
|
||||
author_id: 1,
|
||||
type: 'entry',
|
||||
entry_date: '2026-03-15',
|
||||
title: 'Arrived in Rome',
|
||||
story: 'Amazing city!',
|
||||
location_name: 'Rome',
|
||||
location_lat: 41.9,
|
||||
location_lng: 12.5,
|
||||
mood: 'amazing',
|
||||
weather: 'sunny',
|
||||
tags: ['culture'],
|
||||
pros_cons: { pros: ['Great food'], cons: ['Crowded'] },
|
||||
visibility: 'private',
|
||||
sort_order: 0,
|
||||
entry_time: '10:00',
|
||||
photos: [
|
||||
{
|
||||
id: 100,
|
||||
entry_id: 10,
|
||||
photo_id: 100,
|
||||
provider: 'local',
|
||||
file_path: 'photos/test.jpg',
|
||||
asset_id: null,
|
||||
owner_id: null,
|
||||
thumbnail_path: null,
|
||||
caption: 'Colosseum',
|
||||
sort_order: 0,
|
||||
width: 800,
|
||||
height: 600,
|
||||
shared: 1,
|
||||
created_at: journeyNow,
|
||||
},
|
||||
],
|
||||
created_at: journeyNow,
|
||||
updated_at: journeyNow,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
journey_id: 1,
|
||||
author_id: 1,
|
||||
type: 'entry',
|
||||
entry_date: '2026-03-16',
|
||||
title: 'Florence Day',
|
||||
story: null,
|
||||
location_name: 'Florence',
|
||||
location_lat: 43.77,
|
||||
location_lng: 11.25,
|
||||
mood: 'good',
|
||||
weather: 'cloudy',
|
||||
tags: [],
|
||||
pros_cons: null,
|
||||
visibility: 'private',
|
||||
sort_order: 0,
|
||||
entry_time: null,
|
||||
photos: [],
|
||||
created_at: journeyNow,
|
||||
updated_at: journeyNow,
|
||||
},
|
||||
],
|
||||
trips: [
|
||||
{
|
||||
trip_id: 5,
|
||||
added_at: journeyNow,
|
||||
title: 'Italy Trip',
|
||||
start_date: '2026-03-14',
|
||||
end_date: '2026-03-20',
|
||||
cover_image: null,
|
||||
currency: 'EUR',
|
||||
place_count: 8,
|
||||
},
|
||||
],
|
||||
contributors: [
|
||||
{
|
||||
journey_id: 1,
|
||||
user_id: 1,
|
||||
role: 'owner',
|
||||
added_at: journeyNow,
|
||||
username: 'testuser',
|
||||
avatar: null,
|
||||
},
|
||||
],
|
||||
stats: { entries: 2, photos: 1, places: 2 },
|
||||
gallery: [
|
||||
{
|
||||
id: 100,
|
||||
journey_id: 1,
|
||||
photo_id: 100,
|
||||
provider: 'local',
|
||||
file_path: 'photos/test.jpg',
|
||||
asset_id: null,
|
||||
owner_id: null,
|
||||
thumbnail_path: null,
|
||||
caption: 'Colosseum',
|
||||
sort_order: 0,
|
||||
width: 800,
|
||||
height: 600,
|
||||
shared: 1,
|
||||
created_at: journeyNow,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/** The journal's own reads and writes, answered with that journal (merged with `journeyOverride`). */
|
||||
export function setupJourneyHandlers(journeyOverride?: Record<string, unknown>) {
|
||||
const journey = journeyOverride ? { ...mockJourneyDetail, ...journeyOverride } : mockJourneyDetail;
|
||||
|
||||
server.use(
|
||||
http.get('/api/journeys/1', () => {
|
||||
return HttpResponse.json(journey);
|
||||
}),
|
||||
http.get('/api/addons', () => {
|
||||
return HttpResponse.json({
|
||||
addons: [
|
||||
{ id: 'journey', name: 'Journey', type: 'feature', icon: 'book', enabled: true },
|
||||
{ id: 'immich', name: 'Immich', type: 'photo_provider', icon: 'camera', enabled: true },
|
||||
],
|
||||
});
|
||||
}),
|
||||
http.get('/api/integrations/memories/:provider/status', () => {
|
||||
return HttpResponse.json({ connected: false });
|
||||
}),
|
||||
http.patch('/api/journeys/1', () => {
|
||||
return HttpResponse.json({ ...mockJourneyDetail, title: 'Updated' });
|
||||
}),
|
||||
http.get('/api/journeys/1/share-link', () => {
|
||||
return HttpResponse.json({ link: null });
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user