mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(ci): parse errors, two leaky tests and the lint ratchets after the parity round
This commit is contained in:
@@ -11,7 +11,7 @@ import type { AiStatusResponse } from '@trek/shared';
|
||||
import { useLocation } from 'react-router';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { act, fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
|
||||
import { act, cleanup, fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
|
||||
import { tripRepo } from '../../repo/tripRepo';
|
||||
import { chatOf, useAssistantStore } from '../../store/assistantStore';
|
||||
import type { Trip } from '../../types';
|
||||
@@ -104,6 +104,9 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Unmounted before the store gets its real actions back: a window still on screen would ask the real
|
||||
// loadStatus, whose failed request lands in a later case and hides the assistant there (status null).
|
||||
cleanup();
|
||||
useAssistantStore.setState(INITIAL, true);
|
||||
vi.restoreAllMocks();
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -200,6 +200,6 @@ export function useAiConnections({ phone = false }: { phone?: boolean } = {}) {
|
||||
canOpen: status?.available === true,
|
||||
openAssistant,
|
||||
isAdmin,
|
||||
openAdmin: () => navigate('/admin?tab=addons'),
|
||||
openAdmin: () => void navigate('/admin?tab=addons'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,6 +31,25 @@ function saveDismissedSuggestions(userId: number | undefined, dismissed: Set<num
|
||||
window.localStorage.setItem(key, JSON.stringify([...dismissed]))
|
||||
}
|
||||
|
||||
/** The journey events after which the list reads itself again. */
|
||||
const JOURNEY_LIST_EVENTS = ['journey:updated', 'journey:deleted', 'journey:contributor:changed'] as const
|
||||
|
||||
/**
|
||||
* A journey renamed, given other trips or deleted in another tab or through
|
||||
* MCP, or this user taken off one as a contributor: the list reads itself
|
||||
* again, once per burst. The spinner only shows over an empty list, so a
|
||||
* reread of a full one does not flash.
|
||||
*/
|
||||
function useJourneyListReread(loadJourneys: () => Promise<void>): void {
|
||||
useServerPing(JOURNEY_LIST_EVENTS, true, async () => {
|
||||
try {
|
||||
await loadJourneys()
|
||||
} catch {
|
||||
// A failed reread keeps the list on screen; the next event or visit reads it again.
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Journey list page logic — owns the journey store load, the create-journey
|
||||
* modal (title, available trips, selection), the search box, the trip
|
||||
@@ -63,17 +82,7 @@ export function useJourney() {
|
||||
useEffect(() => {
|
||||
loadJourneys()
|
||||
}, [])
|
||||
// A journey renamed, given other trips or deleted in another tab or through
|
||||
// MCP, or this user taken off one as a contributor: the list reads itself
|
||||
// again, once per burst. The spinner only shows over an empty list, so a
|
||||
// reread of a full one does not flash.
|
||||
useServerPing(['journey:updated', 'journey:deleted', 'journey:contributor:changed'], true, async () => {
|
||||
try {
|
||||
await loadJourneys()
|
||||
} catch {
|
||||
// A failed reread keeps the list on screen; the next event or visit reads it again.
|
||||
}
|
||||
})
|
||||
useJourneyListReread(loadJourneys)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
|
||||
@@ -279,7 +279,7 @@ describe('useTripPlanner — bootstrap', () => {
|
||||
await waitFor(() => expect(tripsApi.getMembers).toHaveBeenCalledTimes(1))
|
||||
|
||||
env.forcedOffline = true
|
||||
act(() => { result.current.refreshMembers() })
|
||||
await act(async () => { await result.current.refreshMembers() })
|
||||
|
||||
expect(tripsApi.getMembers).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
@@ -2845,7 +2845,7 @@ describe('useTripPlanner — misc state', () => {
|
||||
owner: { user_id: 1, username: 'owner' },
|
||||
members: [{ user_id: 2 }, { user_id: 3 }],
|
||||
})
|
||||
act(() => { result.current.refreshMembers() })
|
||||
await act(async () => { await result.current.refreshMembers() })
|
||||
|
||||
await waitFor(() => expect(result.current.tripMembers).toHaveLength(3))
|
||||
})
|
||||
|
||||
@@ -67,6 +67,21 @@ import { usePlannerTripView } from './usePlannerTripView'
|
||||
import { useIsPhone } from '../../mobile/useIsPhone'
|
||||
import { useRoadtripVias } from '../../components/Roadtrip/useRoadtripVias'
|
||||
|
||||
/**
|
||||
* The trip's roster from the server: the owner and the members. Null offline
|
||||
* or when it could not be read; the roster on screen then stays, and the next
|
||||
* member event or reload reads it again.
|
||||
*/
|
||||
async function fetchRoster(tripId: number): Promise<TripMember[] | null> {
|
||||
if (!tripId || isEffectivelyOffline()) return null
|
||||
try {
|
||||
const d = await tripsApi.getMembers(tripId)
|
||||
return [d.owner, ...(d.members || [])].filter(Boolean)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trip planner page logic, the big one. Owns the trip store wiring, addon
|
||||
* gating, accommodations/members loading, the tab + resizable-panel + selection
|
||||
@@ -178,13 +193,8 @@ export function useTripPlanner() {
|
||||
// Re-fetch the trip roster so consumers (Costs participants, Collab, …) pick up a
|
||||
// just-added guest or member without a full page reload.
|
||||
const refreshMembers = useCallback(async () => {
|
||||
if (!tripId || isEffectivelyOffline()) return
|
||||
try {
|
||||
const d = await tripsApi.getMembers(tripId)
|
||||
setTripMembers([d.owner, ...(d.members || [])].filter(Boolean))
|
||||
} catch {
|
||||
// The roster on screen stays; the next member event or reload reads it again.
|
||||
}
|
||||
const roster = await fetchRoster(tripId)
|
||||
if (roster) setTripMembers(roster)
|
||||
}, [tripId])
|
||||
// A member added, removed or renamed elsewhere, and the trip going away under us.
|
||||
useTripRosterSync(tripId, refreshMembers)
|
||||
@@ -420,7 +430,8 @@ export function useTripPlanner() {
|
||||
.then(rows => setTripMembers(rows))
|
||||
.catch(() => {})
|
||||
} else {
|
||||
void refreshMembers()
|
||||
// The roster lands from the read's callback, never synchronously inside the effect.
|
||||
void fetchRoster(tripId).then(roster => { if (roster) setTripMembers(roster) })
|
||||
}
|
||||
}
|
||||
}, [tripId])
|
||||
|
||||
@@ -65,6 +65,11 @@ interface NotificationState {
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
|
||||
/** What marking everything read leaves, here or in another tab: every notification read, none to count. */
|
||||
function allRead(state: NotificationState): Partial<NotificationState> {
|
||||
return { notifications: state.notifications.map(n => n.is_read ? n : { ...n, is_read: true }), unreadCount: 0 }
|
||||
}
|
||||
|
||||
export const useInAppNotificationStore = create<NotificationState>((set, get) => ({
|
||||
notifications: [],
|
||||
unreadCount: 0,
|
||||
@@ -130,10 +135,7 @@ export const useInAppNotificationStore = create<NotificationState>((set, get) =>
|
||||
markAllRead: async () => {
|
||||
try {
|
||||
await inAppNotificationsApi.markAllRead()
|
||||
set(state => ({
|
||||
notifications: state.notifications.map(n => ({ ...n, is_read: true })),
|
||||
unreadCount: 0,
|
||||
}))
|
||||
set(allRead)
|
||||
} catch {
|
||||
// best-effort
|
||||
}
|
||||
@@ -206,10 +208,5 @@ export const useInAppNotificationStore = create<NotificationState>((set, get) =>
|
||||
},
|
||||
|
||||
// Everything marked read at once elsewhere: the same end state markAllRead leaves.
|
||||
handleAllRead: () => {
|
||||
set(state => ({
|
||||
notifications: state.notifications.map(n => n.is_read ? n : { ...n, is_read: true }),
|
||||
unreadCount: 0,
|
||||
}))
|
||||
},
|
||||
handleAllRead: () => set(allRead),
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user