fix(ci): the second round of gates after the places changes

- index.css stays at its size: the map canvas colour moves to its own
  stylesheet.
- The rating badge on map markers takes its amber and white from a class in
  ratingBadge.css instead of inline literals; the theme entry drops with it.
- Strict mode: the identity a link joins is resolved without a widened union,
  the description of an entry's origins is string or undefined, and the map
  search rows are typed.
- knip: PLACE_NAME_ATTR is module private, the linked-by enum names the values
  the service writes, and the unlink contract is its own described schema
  rather than a second name for the use schema.
- The duplicates hook test reads toasts through a module mock instead of the
  window hook; react-hooks/refs is lowered to the count the run measured.
- Tests follow the rename to Places and the list icon on an edit.
This commit is contained in:
Maurice
2026-11-29 16:38:53 +01:00
parent bacc6a29a7
commit f99c7f5421
17 changed files with 51 additions and 37 deletions
@@ -23,6 +23,6 @@ export function originPairs(data: PlacesLibraryDetailResponse | null): {
return {
trips: pairs.filter((p): p is TripPair => p.origin.kind === 'trip' && p.detail.kind === 'trip'),
lists: pairs.filter((p): p is ListPair => p.origin.kind === 'list' && p.detail.kind === 'list'),
description: pairs.map((p) => p.detail.info.description).find((d) => d?.trim()),
description: pairs.map((p) => p.detail.info.description).find((d) => d?.trim()) ?? undefined,
};
}
@@ -1,13 +1,20 @@
// FE-COMP-PLACEDUPES-001 to FE-COMP-PLACEDUPES-019: the logic behind the duplicates dialog and sheet.
import { act, renderHook, waitFor } from '@testing-library/react';
import type { PlacesLibraryDuplicate } from '@trek/shared';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { duplicatePair, duplicateSide } from '../../../tests/helpers/placesLibrary';
import { OnlineOnlyError } from '../../repo/onlineOnly';
import { placeIdentitiesRepo } from '../../repo/placeIdentitiesRepo';
import { pairKey, usePlaceDuplicates } from './usePlaceDuplicates';
// The toasts the hook shows, read through a module mock rather than the window hook.
const toastError = vi.hoisted(() => vi.fn());
vi.mock('../shared/Toast', () => {
const toast = { error: toastError, success: vi.fn(), warning: vi.fn(), info: vi.fn() };
return { useToast: () => toast };
});
vi.mock('../../repo/placeIdentitiesRepo', () => ({
placeIdentitiesRepo: {
duplicates: vi.fn(),
@@ -31,8 +38,6 @@ const OTHER_PAIR = duplicatePair({
b: duplicateSide({ key: 'trip:8', name: 'Pantheon Rome' }),
});
let addToast: ReturnType<typeof vi.fn>;
function page(pairs: PlacesLibraryDuplicate[], next_cursor: string | null = null) {
return { duplicates: pairs, next_cursor };
}
@@ -55,12 +60,6 @@ async function loaded(pairs: PlacesLibraryDuplicate[] = [PAIR, OTHER_PAIR], next
beforeEach(() => {
vi.clearAllMocks();
addToast = vi.fn();
window.__addToast = addToast as unknown as typeof window.__addToast;
});
afterEach(() => {
delete window.__addToast;
});
describe('pairKey', () => {
@@ -111,7 +110,7 @@ describe('usePlaceDuplicates', () => {
const { result } = setup();
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.pairs).toEqual([]);
expect(addToast).not.toHaveBeenCalled();
expect(toastError).not.toHaveBeenCalled();
});
it('FE-COMP-PLACEDUPES-007: any other load failure empties the list and says so', async () => {
@@ -119,14 +118,14 @@ describe('usePlaceDuplicates', () => {
const { result } = setup();
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.pairs).toEqual([]);
expect(addToast).toHaveBeenCalledWith('common.error', 'error', undefined);
expect(toastError).toHaveBeenCalledWith('common.error');
});
it('FE-COMP-PLACEDUPES-008: the server message is shown when the load is refused with one', async () => {
duplicates.mockRejectedValue({ response: { data: { error: 'Not allowed' } } });
const { result } = setup();
await waitFor(() => expect(result.current.loading).toBe(false));
expect(addToast).toHaveBeenCalledWith('Not allowed', 'error', undefined);
expect(toastError).toHaveBeenCalledWith('Not allowed');
});
it('FE-COMP-PLACEDUPES-009: keeping side a merges a into b, drops the pair and reports the change', async () => {
@@ -162,7 +161,7 @@ describe('usePlaceDuplicates', () => {
expect(result.current.lastMerge).toBeNull();
expect(result.current.busy).toBeNull();
expect(onChanged).not.toHaveBeenCalled();
expect(addToast).toHaveBeenCalledWith('common.error', 'error', undefined);
expect(toastError).toHaveBeenCalledWith('common.error');
});
it('FE-COMP-PLACEDUPES-012: marks the pair busy while it merges and ignores a second click', async () => {
@@ -210,7 +209,7 @@ describe('usePlaceDuplicates', () => {
});
expect(result.current.pairs).toEqual([PAIR, OTHER_PAIR]);
expect(onChanged).not.toHaveBeenCalled();
expect(addToast).toHaveBeenCalledWith('Gone', 'error', undefined);
expect(toastError).toHaveBeenCalledWith('Gone');
});
it('FE-COMP-PLACEDUPES-015: undo takes the last merge back, clears it and reloads the pairs', async () => {
@@ -256,7 +255,7 @@ describe('usePlaceDuplicates', () => {
expect(result.current.busy).toBeNull();
expect(onChanged).toHaveBeenCalledTimes(1);
expect(duplicates).toHaveBeenCalledTimes(1);
expect(addToast).toHaveBeenCalledWith('common.error', 'error', undefined);
expect(toastError).toHaveBeenCalledWith('common.error');
});
it('FE-COMP-PLACEDUPES-018: reload asks the server for the pairs again', async () => {
+1 -1
View File
@@ -11,7 +11,7 @@ import './placeNames.css';
* A place folded into a cluster has no element, so it has no label either.
*/
export const PLACE_NAME_ATTR = 'data-place-name';
const PLACE_NAME_ATTR = 'data-place-name';
const PRIORITY_ATTR = 'data-place-name-priority';
const LABEL_CLASS = 'trek-place-name';
const HIDDEN_ATTR = 'data-hidden';
@@ -0,0 +1,6 @@
/* The rating on a map marker's corner: amber with a white figure, like the list's badge. */
.trek-rating-badge {
background: #f59e0b;
color: #fff;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
}
@@ -27,11 +27,11 @@ describe('cornerBadgeHtml', () => {
const html = cornerBadgeHtml([2, 5], 4.5, true, -4);
expect(html).toContain('2 · 5');
expect(html).toContain('bottom:-4px;inset-inline-end:-4px');
expect(html).not.toContain('#fbbf24');
expect(html).not.toContain('trek-rating-badge');
});
it('FE-MAP-RATINGBADGE-102: without numbers the rating shows when asked for, else nothing', () => {
expect(cornerBadgeHtml(null, 4, true, -2)).toContain('#fbbf24');
expect(cornerBadgeHtml(null, 4, true, -2)).toContain('trek-rating-badge');
expect(cornerBadgeHtml([], 4, false, -2)).toBe('');
expect(cornerBadgeHtml([3], null, true, -2)).toContain('height:18px');
});
+5 -3
View File
@@ -1,3 +1,5 @@
import './ratingBadge.css';
/**
* The rating a place carries, as a disc on the corner of its marker.
*
@@ -12,15 +14,15 @@
export function ratingBadgeHtml(rating: number | null | undefined): string {
if (typeof rating !== 'number' || !(rating > 0)) return '';
const label = Number.isInteger(rating) ? String(rating) : rating.toFixed(1);
return `<span style="
// Its amber and white live in ratingBadge.css, beside the list's badge of the same look.
return `<span class="trek-rating-badge" style="
position:absolute;bottom:-4px;right:-4px;
min-width:18px;height:18px;border-radius:9px;
padding:0 4px;
background:#f59e0b;
border:1.5px solid rgba(255,255,255,0.92);
box-shadow:0 1px 4px rgba(0,0,0,0.25);
display:flex;align-items:center;justify-content:center;
font-size:9px;font-weight:800;color:#fff;text-shadow:0 1px 1px rgba(0,0,0,.45);
font-size:9px;font-weight:800;
font-family:var(--font-system);line-height:1;
box-sizing:border-box;white-space:nowrap;
">${label}</span>`;
-3
View File
@@ -1171,9 +1171,6 @@ body {
/* ── Leaflet z-index ───────────────────────────── */
.leaflet-container {
z-index: 0;
/* Leaflet's own grey showed as a bright band past the edge of the world when a map
framed places on several continents, and while tiles were still loading. */
background: var(--bg-secondary);
}
.leaflet-pane {
z-index: 0 !important;
+1
View File
@@ -25,6 +25,7 @@ import '@fontsource/geist-sans/600.css'
// several .leaflet-* styles.
import 'leaflet/dist/leaflet.css'
import './index.css'
import './styles/leafletCanvas.css'
import './native/nativeApp.css'
import './styles/rtl.css'
import './styles/pageTransition.css'
+2 -1
View File
@@ -61,5 +61,6 @@ export async function searchMapSpots(query: string, lang?: string): Promise<MapM
const q = query.trim();
if (!q || isEffectivelyOffline()) return [];
const res = lang ? await mapsApi.search(q, lang) : await mapsApi.search(q);
return (res?.places ?? []).map((row) => toMatch(row, q)).filter((m): m is MapMatch => m !== null);
const rows: readonly unknown[] = res?.places ?? [];
return rows.map((row: unknown) => toMatch(row, q)).filter((m: MapMatch | null): m is MapMatch => m !== null);
}
+5
View File
@@ -0,0 +1,5 @@
/* Leaflet's own grey showed as a bright band past the edge of the world when a map
framed places on several continents, and while tiles were still loading. */
.leaflet-container {
background: var(--bg-secondary);
}