mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
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:
@@ -8,7 +8,7 @@
|
||||
"trek/no-swallowed-catch": 124,
|
||||
"max-params": 31,
|
||||
"trek/store-without-selector": 65,
|
||||
"react-hooks/refs": 391,
|
||||
"react-hooks/refs": 389,
|
||||
"react-hooks/set-state-in-effect": 188,
|
||||
"@typescript-eslint/no-floating-promises": 162,
|
||||
"react-hooks/exhaustive-deps": 112,
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
"components/Map/locationMarkerMapbox.ts": 2,
|
||||
"components/Map/placePopup.ts": 6,
|
||||
"components/Map/poiCategories.ts": 7,
|
||||
"components/Map/ratingBadge.ts": 2,
|
||||
"components/Map/ratingBadge.ts": 1,
|
||||
"components/Map/reservationsMapbox.ts": 1,
|
||||
"components/Map/switcherRow.ts": 1,
|
||||
"components/Packing/PackingListPanelBagModal.tsx": 2,
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
@@ -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>`;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ describe('MNavRail', () => {
|
||||
seedAddons(['vacay', 'journey', 'atlas', 'collections']);
|
||||
render(<MNavRail />, { initialEntries: ['/dashboard'] });
|
||||
|
||||
for (const name of ['My Trips', 'Vacay', 'Journey', 'Atlas', 'Collections', 'Settings']) {
|
||||
for (const name of ['My Trips', 'Vacay', 'Journey', 'Atlas', 'Places', 'Settings']) {
|
||||
expect(within(rail()).getByRole('button', { name })).toBeInTheDocument();
|
||||
}
|
||||
expect(within(rail()).queryByRole('button', { name: 'More' })).not.toBeInTheDocument();
|
||||
|
||||
@@ -153,6 +153,7 @@ describe('MCollEditSheet', () => {
|
||||
name: 'Hamburg',
|
||||
color: '#38BDF8',
|
||||
description: null,
|
||||
icon: 'Bookmark',
|
||||
links: [{ label: 'Guide', url: 'https://hamburg.de' }],
|
||||
})
|
||||
// An edit must not re-navigate the way a create does.
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('MMobileNavCustomizer', () => {
|
||||
render(<MMobileNavCustomizer value={{ bar: [], more: [] }} onChange={vi.fn()} />);
|
||||
|
||||
expect(rowLabels('In the bar')).toEqual(['Vacay', 'Journey']);
|
||||
expect(rowLabels('Under “More”')).toEqual(['Atlas', 'Collections']);
|
||||
expect(rowLabels('Under “More”')).toEqual(['Atlas', 'Places']);
|
||||
});
|
||||
|
||||
it('FE-MOB-SETNAVC-002: Dashboard is listed pinned and has no reorder buttons', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UserPlaceLinks } from '../../db/entities/UserPlaceLinks.entity';
|
||||
import { UserPlaceLinks, UserPlaceLinksLinkedBy } from '../../db/entities/UserPlaceLinks.entity';
|
||||
import { UserPlaceMergeDismissals } from '../../db/entities/UserPlaceMergeDismissals.entity';
|
||||
import { UserPlaceMerges } from '../../db/entities/UserPlaceMerges.entity';
|
||||
import { UserPlaces } from '../../db/entities/UserPlaces.entity';
|
||||
@@ -93,11 +93,11 @@ export class PlaceIdentitiesService {
|
||||
}
|
||||
const first = uses[0];
|
||||
if (!first) throw placeNotFound();
|
||||
const target =
|
||||
request.identity_id === undefined ? { facts: await this.factsOfUse(reach, first) } : { id: request.identity_id };
|
||||
const joining = request.identity_id;
|
||||
const identityId = await this.uow.transactional(async () => {
|
||||
const id = 'id' in target ? target.id : await this.identities.createOwn(user.id, target.facts);
|
||||
await this.attach(user.id, id, uses, 'user');
|
||||
const id =
|
||||
joining !== undefined ? joining : await this.identities.createOwn(user.id, await this.factsOfUse(reach, first));
|
||||
await this.attach(user.id, id, uses, UserPlaceLinksLinkedBy.USER);
|
||||
await this.identities.touch(user.id, id);
|
||||
await this.prune(user.id);
|
||||
return id;
|
||||
@@ -288,7 +288,7 @@ export class PlaceIdentitiesService {
|
||||
google_ftid: first.google_ftid,
|
||||
osm_id: first.osm_id,
|
||||
});
|
||||
await this.attach(userId, id, usesOfRows(rows), 'merge');
|
||||
await this.attach(userId, id, usesOfRows(rows), UserPlaceLinksLinkedBy.MERGE);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,9 @@ export const placesLibraryLinkRequestSchema = z
|
||||
export type PlacesLibraryLinkRequest = z.infer<typeof placesLibraryLinkRequestSchema>;
|
||||
|
||||
/** Take one use out of the user's own place again. */
|
||||
export const placesLibraryUnlinkRequestSchema = placesLibraryUseSchema;
|
||||
export const placesLibraryUnlinkRequestSchema = placesLibraryUseSchema.describe(
|
||||
'The trip place or saved place to take out of the own place it belongs to',
|
||||
);
|
||||
export type PlacesLibraryUnlinkRequest = PlacesLibraryUse;
|
||||
|
||||
/** The entry a use belongs to after the change, null when it is out of reach by now. */
|
||||
|
||||
Reference in New Issue
Block a user