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 () => {