chore(lint): keep the fixes within the lint ratchets

No promise in a condition, sequential awaits through a reduce instead of a loop, no non-null assertions or any in the new tests, an awaited act, one options object for a stop edit and a handled rejection for the offline copy.
This commit is contained in:
Maurice
2026-11-23 16:09:34 +01:00
parent f6d52727f7
commit 8a9f5367b1
15 changed files with 65 additions and 31 deletions
@@ -29,10 +29,15 @@ describe('HelpGuideView: links', () => {
})
it('takes an admin guide to the tab its settings sit under', () => {
const { unmount } = render(<HelpGuideView guide={getHelpGuide('instance-keys')!} />)
const guideOf = (id: string) => {
const guide = getHelpGuide(id)
if (!guide) throw new Error(`no guide ${id}`)
return guide
}
const { unmount } = render(<HelpGuideView guide={guideOf('instance-keys')} />)
expect(screen.getByRole('link', { name: /^Go to/ })).toHaveAttribute('href', '/admin?tab=services')
unmount()
render(<HelpGuideView guide={getHelpGuide('auth-methods')!} />)
render(<HelpGuideView guide={guideOf('auth-methods')} />)
expect(screen.getByRole('link', { name: /^Go to/ })).toHaveAttribute('href', '/admin?tab=settings')
})
})
+6 -1
View File
@@ -18,6 +18,11 @@ const prefersReducedMotion = (): boolean =>
const stepMedia = (guide: HelpGuide, n: number): string =>
guide.media.clips?.includes(n) && !prefersReducedMotion() ? helpMedia.clip(guide.id, n) : helpMedia.step(guide.id, n)
/** Where a guide's "go to" link leads: its own route, else its screen's. */
function routeOf(guide: HelpGuide, screen: ReturnType<typeof getHelpContext>): string | undefined {
return guide.route ?? screen?.route
}
/**
* One guide, top to bottom: a header card that says where you are and how big
* the task is, the steps as a numbered rail with a picture each, what the
@@ -38,7 +43,7 @@ export default function HelpGuideView({ guide }: { guide: HelpGuide }): React.Re
const related = (guide.related ?? []).map(getHelpGuide).filter((g): g is HelpGuide => g !== null)
const Icon = helpIcon(guide.icon)
const ScreenIcon = screen ? helpIcon(screen.icon) : Icon
const screenRoute = useScreenRoute(guide.route ?? screen?.route)
const screenRoute = useScreenRoute(routeOf(guide, screen))
return (
<div className="trek-help-view flex flex-col gap-6">
@@ -208,7 +208,9 @@ describe('NativeImportSheet', () => {
answer = () => resolve([]);
})
);
act(() => void useTripAddonsStore.getState().load(1));
await act(async () => {
void useTripAddonsStore.getState().load(1);
});
expect(screen.getByRole('button', { name: /Japan/ })).toBeInTheDocument();
await act(async () => answer());
expect(screen.getByRole('button', { name: /Japan/ })).toBeInTheDocument();
+6 -2
View File
@@ -1031,9 +1031,13 @@ describe('useAdmin', () => {
await waitFor(() => expect(result.current.admin.isLoading).toBe(false));
expect(result.current.admin.activeTab).toBe('security');
act(() => void result.current.navigate('/admin?tab=services'));
await act(async () => {
await result.current.navigate('/admin?tab=services');
});
expect(result.current.admin.activeTab).toBe('services');
act(() => void result.current.navigate('/admin?tab=settings'));
await act(async () => {
await result.current.navigate('/admin?tab=settings');
});
expect(result.current.admin.activeTab).toBe('security');
act(() => result.current.admin.setActiveTab('audit'));
expect(result.current.admin.activeTab).toBe('audit');
@@ -49,8 +49,12 @@ async function writeEditedStop(
tripId: PlannerBase['tripId'],
assignments: TripStoreState['assignments'],
{ placeId, assignmentId, dwellMinutes: before }: { placeId: number; assignmentId?: number; dwellMinutes?: number },
{ stopType, dwellMinutes }: { stopType: RoadtripStopType | null; dwellMinutes: number },
{ mayEditVisit, refused }: { mayEditVisit: boolean; refused: string },
{
stopType,
dwellMinutes,
mayEditVisit,
refused,
}: { stopType: RoadtripStopType | null; dwellMinutes: number; mayEditVisit: boolean; refused: string },
): Promise<void> {
const visitDayId = savedVisitDayOf(assignments, assignmentId)
if (assignmentId == null || visitDayId === null) {
@@ -101,7 +105,9 @@ export function useRoadtripStopEdits(options: RoadtripStopEditsOptions) {
}
try {
if (stopDraft.editing) {
await writeEditedStop(tripActions, tripId, assignments, stopDraft.editing, { stopType, dwellMinutes }, {
await writeEditedStop(tripActions, tripId, assignments, stopDraft.editing, {
stopType,
dwellMinutes,
mayEditVisit: can('day_edit', trip),
refused: t('trip.journal.errorForbidden'),
})
+5 -1
View File
@@ -70,7 +70,11 @@ export const useTripAddonsStore = create<TripAddonsState>((set, get) => ({
// A push that landed meanwhile is newer than this answer and stays, in the
// store and in the device's copy the answer was written over.
if (current && current.rev !== rev) {
if (addons && current.addons) void tripAddonsRepo.remember(tripId, current.addons).catch(() => {});
if (addons && current.addons)
void tripAddonsRepo.remember(tripId, current.addons).catch(() => {
// The device copy stays one answer behind until the next read of this trip writes it.
return undefined;
});
return current.addons;
}
const entry: TripAddonsEntry = addons