fix(tours): the repository test names the bike profile, and the add menu reads its list outside render

This commit is contained in:
Maurice
2026-10-19 21:44:19 +02:00
parent 73237ffedb
commit e429b49ef6
3 changed files with 12 additions and 9 deletions
@@ -39,6 +39,7 @@ export function TourAddMenu({
}) {
const { t } = useTranslation();
const list = usePopoverList(0, { estimatedHeight: 140 });
const { open, toggle, close, triggerRef } = list;
const library = useTourLibrary({
tripId: Number(planner.tripId),
onTakenOver: async (tour) => {
@@ -77,21 +78,21 @@ export function TourAddMenu({
// Run inside the click that picked it: the file picker opens only from a user's own tap.
const pick = (entry: AddEntry) => {
list.close();
close();
entry.run();
};
return (
<>
<BarButton
ref={list.triggerRef}
ref={triggerRef}
label={t('tours.planner.addTour')}
tooltip={t('tours.planner.addTourHint')}
testId="tour-rail-add"
disabled={disabled || importing}
onClick={list.toggle}
ariaExpanded={list.open}
active={list.open}
onClick={toggle}
ariaExpanded={open}
active={open}
className="focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent"
>
{importing ? (
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { act, fireEvent, render, screen } from '../../../tests/helpers/render';
import { fireEvent, render, screen } from '../../../tests/helpers/render';
import { PopoverListPanel } from './dialogParts';
import { usePopoverList } from './usePopoverList';
@@ -7,9 +7,10 @@ import { usePopoverList } from './usePopoverList';
function Picker({ current = 1, onPick = vi.fn() }: { current?: number; onPick?: (index: number) => void }) {
const list = usePopoverList(current);
const { open, toggle, close, triggerRef } = list;
return (
<>
<button type="button" ref={list.triggerRef} onClick={list.toggle} aria-expanded={list.open}>
<button type="button" ref={triggerRef} onClick={toggle} aria-expanded={open}>
trigger
</button>
<PopoverListPanel list={list} label="choices">
@@ -19,7 +20,7 @@ function Picker({ current = 1, onPick = vi.fn() }: { current?: number; onPick?:
type="button"
onClick={() => {
onPick(index);
list.close();
close();
}}
>
{name}
@@ -99,7 +100,7 @@ describe('usePopoverList', () => {
return { left, right: left + 240, top: 10, bottom: 40, width: 240, height: 30, x: left, y: 10 } as DOMRect;
});
render(<Picker />);
act(() => fireEvent.click(trigger()));
fireEvent.click(trigger());
// 240 wide from 100 short of the edge: 140 past it, and the 8 kept clear of it.
expect(screen.getByRole('group').style.translate).toBe('-148px 0');
});
@@ -226,6 +226,7 @@ describe('ToursRepository writes', () => {
// A route edit always writes the type's own fields; a hike's are empty.
const HIKE_UPDATE = {
...METRICS,
bike_profile: null,
boat_type: null,
water_context: null,
paddle_speed_kmh: null,