}) => basis:{JSON.stringify(byBasis)}
,
+ UncountedBadges: (p: { upcoming: number; unassigned: number; undated: number }) => (
+
+ uncounted:{p.upcoming}:{p.unassigned}:{p.undated}
+
+ ),
+}));
+vi.mock('../../../../components/Atlas/tourActivity/TourActivityStatsDialog', () => ({
+ TourActivityStatsDialog: ({ open, onClose }: { open: boolean; onClose: () => void }) =>
+ open ? (
+
+
+
+ ) : null,
+}));
+
+function statsWith(over: Record = {}) {
+ tours.stats = {
+ status: 'ready',
+ data: { entries: [], uncounted: { unassigned: 0, undated: 0 } },
+ summary: null,
+ period: 'all',
+ setPeriod: vi.fn(),
+ periods: ['all', 'thisYear', 'last12', 'year:2023'],
+ type: 'all',
+ setType: vi.fn(),
+ types: ['all'],
+ ...over,
+ };
+ return tours.stats as Record>;
+}
+
+const TYPES = [
+ { type: 'hike', count: 3, distanceKm: { value: 30 } },
+ { type: 'bike', count: 2, distanceKm: { value: null } },
+];
+
+function summary(count: number, done: unknown[] = []) {
+ return {
+ totals: { count, byBasis: { plan: 2, track: 3 } },
+ types: TYPES,
+ done,
+ upcoming: 1,
+ };
+}
+
+beforeEach(() => {
+ tours.active = [];
+ tours.figures = {
+ hero: { value: '42', unit: 'km' },
+ ascent: { text: '1200 m' },
+ descent: null,
+ types: TYPES,
+ maxKm: 30,
+ uncounted: { unassigned: 2, undated: 4 },
+ };
+});
+
+describe('MHubTours', () => {
+ it('FE-ATLAS2-MOBILE-140: before the numbers are there it asks for them and shows where the read stands', () => {
+ statsWith({ status: 'loading' });
+ render();
+ expect(tours.active[0]).toBe(true);
+ expect(screen.getByText('status:loading')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-141: the periods are chips, the chosen one pressed, a tap picks another', () => {
+ const st = statsWith({ period: 'thisYear' });
+ render();
+ const periods = screen.getByRole('group', { name: 'tours.stats.period' });
+ expect(periods.textContent).toContain('2023');
+ expect(screen.getByRole('button', { name: 'tours.stats.period.thisYear' })).toHaveAttribute('aria-pressed', 'true');
+ fireEvent.click(screen.getByRole('button', { name: 'tours.stats.period.last12' }));
+ expect(st.setPeriod).toHaveBeenCalledWith('last12');
+ // One type only: no type chips.
+ expect(screen.queryByRole('group', { name: 'tours.filter.type' })).toBeNull();
+ });
+
+ it('FE-ATLAS2-MOBILE-142: more than one type adds a row of type chips', () => {
+ const st = statsWith({ types: ['all', 'hike'] });
+ render();
+ expect(screen.getByRole('button', { name: 'tours.stats.allTypes' })).toHaveAttribute('aria-pressed', 'true');
+ fireEvent.click(screen.getByRole('button', { name: 'tourTypes.hike' }));
+ expect(st.setType).toHaveBeenCalledWith('hike');
+ });
+
+ it('FE-ATLAS2-MOBILE-143: no tour in the period says none counts when there are tours at all', () => {
+ statsWith({ summary: summary(0), data: { entries: [{ place_id: 1 }], uncounted: { unassigned: 0, undated: 0 } } });
+ render();
+ expect(screen.getByText('tours.stats.none')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-144: no tour at all says there are none yet', () => {
+ statsWith({ summary: summary(0), data: null });
+ render();
+ expect(screen.getByText('tours.stats.empty')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-145: the distance is the headline, tours, climb and descent the tiles', () => {
+ statsWith({ summary: summary(5) });
+ render();
+ expect(screen.getByText('42')).toBeInTheDocument();
+ expect(screen.getByText('km')).toBeInTheDocument();
+ expect(screen.getByText('basis:{"plan":2,"track":3}')).toBeInTheDocument();
+ expect(screen.getByText('5')).toBeInTheDocument();
+ expect(screen.getByText('tours.mode.tours')).toBeInTheDocument();
+ expect(screen.getByText('1200 m')).toBeInTheDocument();
+ expect(screen.getByText('0')).toBeInTheDocument();
+ expect(screen.getByText('uncounted:1:2:4')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-146: every type is a row with its count and a bar scaled to the longest', () => {
+ statsWith({ summary: summary(5) });
+ render();
+ expect(screen.getByRole('heading', { name: 'atlas.globe.byType' })).toBeInTheDocument();
+ expect(screen.getByText('atlas.globe.tourCount:3')).toBeInTheDocument();
+ expect(screen.getByText('30 km')).toBeInTheDocument();
+ const bar = (label: string) =>
+ (screen.getByText(label).closest('.flex-col') as HTMLElement).querySelector('.bg-m-act') as HTMLElement;
+ expect(bar('tourTypes.hike').style.width).toBe('100%');
+ // A type without a known distance keeps a sliver.
+ expect(bar('tourTypes.bike').style.width).toBe('4%');
+ });
+
+ it('FE-ATLAS2-MOBILE-147: one type picked leaves the rows by type out, a headline without unit shows the figure alone', () => {
+ tours.figures = { ...tours.figures, hero: { value: '5', unit: '' } };
+ statsWith({ summary: summary(5), type: 'hike', types: ['all', 'hike'] });
+ render();
+ expect(screen.queryByRole('heading', { name: 'atlas.globe.byType' })).toBeNull();
+ expect(screen.queryByText('km')).toBeNull();
+ });
+
+ it('FE-ATLAS2-MOBILE-148: done tours open their list in a dialog, which closes again', () => {
+ statsWith({ summary: summary(5, [{ place_id: 1 }]) });
+ render();
+ expect(screen.queryByRole('dialog')).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'tours.stats.showTours' }));
+ expect(screen.getByRole('dialog', { name: 'tour list' })).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'close list' }));
+ expect(screen.queryByRole('dialog')).toBeNull();
+ });
+
+ it('FE-ATLAS2-MOBILE-149: without done tours there is no list to open', () => {
+ statsWith({ summary: summary(5) });
+ render();
+ expect(screen.queryByRole('button', { name: 'tours.stats.showTours' })).toBeNull();
+ });
+});
diff --git a/client/src/mobile/screens/atlas/hub/MHubTravellers.test.tsx b/client/src/mobile/screens/atlas/hub/MHubTravellers.test.tsx
new file mode 100644
index 000000000..0c6f92629
--- /dev/null
+++ b/client/src/mobile/screens/atlas/hub/MHubTravellers.test.tsx
@@ -0,0 +1,124 @@
+import { describe, expect, it } from 'vitest';
+import { buildGlobeState } from '../../../../../tests/helpers/atlasGlobeState';
+import { fireEvent, render, screen, within } from '../../../../../tests/helpers/render';
+import MHubTravellers from './MHubTravellers';
+
+function person(id: number, username: string, countries: number, over: Record = {}) {
+ return {
+ id,
+ username,
+ avatar_url: null,
+ countries,
+ continents: 2,
+ regions: 9,
+ flightKm: 0,
+ codes: [],
+ badges: [],
+ ...over,
+ };
+}
+
+const RANKING = [
+ person(2, 'ann', 20, { avatar_url: 'https://example.test/ann.png', continents: 4, regions: 31 }),
+ person(1, 'me', 12),
+ person(3, 'bob', 8),
+ person(4, 'cy', 3),
+];
+
+const rowOf = (name: string) => screen.getByText(name).closest('button') as HTMLElement;
+
+describe('MHubTravellers', () => {
+ it('FE-ATLAS2-MOBILE-120: loads the travellers and shows being visible as a switch that hides on a tap', () => {
+ const s = buildGlobeState();
+ render();
+ expect(s.loadPeople).toHaveBeenCalledOnce();
+ const visible = screen.getByRole('switch', { name: 'atlas.globe.visibleToOthers' });
+ expect(visible).toHaveAttribute('aria-checked', 'true');
+ fireEvent.click(visible);
+ expect(s.setHidden).toHaveBeenCalledWith(true);
+ // Nothing loaded yet: no list and no empty state.
+ expect(screen.queryByText('atlas.globe.noTravellers')).toBeNull();
+ expect(screen.queryByRole('list')).toBeNull();
+ });
+
+ it('FE-ATLAS2-MOBILE-121: a hidden traveller sees the switch off and turns it back on', () => {
+ const s = buildGlobeState({ hidden: true });
+ render();
+ const visible = screen.getByRole('switch', { name: 'atlas.globe.visibleToOthers' });
+ expect(visible).toHaveAttribute('aria-checked', 'false');
+ fireEvent.click(visible);
+ expect(s.setHidden).toHaveBeenCalledWith(false);
+ });
+
+ it('FE-ATLAS2-MOBILE-122: alone on the instance there is nobody to rank', () => {
+ render();
+ expect(screen.getByText('atlas.globe.noTravellers')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-123: the ranking numbers every traveller, marks the reader and opens the others', () => {
+ const s = buildGlobeState({ ranking: RANKING, me: { id: 1 } });
+ render();
+ const list = screen.getByRole('list');
+ expect(within(list).getAllByRole('listitem')).toHaveLength(4);
+ expect(screen.getByRole('heading', { name: 'atlas.globe.ranking' }).parentElement?.textContent).toContain('4');
+ expect(rowOf('me')).toBeDisabled();
+ expect(within(rowOf('me')).getByText('atlas.globe.you')).toBeInTheDocument();
+ expect(within(rowOf('bob')).queryByText('atlas.globe.you')).toBeNull();
+ fireEvent.click(rowOf('bob'));
+ expect(s.setProfileId).toHaveBeenCalledWith(3);
+ expect(within(rowOf('ann')).getByText('20')).toBeInTheDocument();
+ expect(within(rowOf('ann')).getByText('31')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-124: the first three wear the podium, the rest a plain number', () => {
+ render();
+ const place = (name: string) => rowOf(name).firstElementChild as HTMLElement;
+ expect(place('ann').textContent).toBe('1');
+ expect(place('ann').getAttribute('style')).toContain('box-shadow');
+ expect(place('bob').getAttribute('style')).toContain('box-shadow');
+ expect(place('cy').textContent).toBe('4');
+ expect(place('cy').getAttribute('style')).toBeNull();
+ });
+
+ it('FE-ATLAS2-MOBILE-125: a picture where there is one, otherwise the first letter', () => {
+ render();
+ expect(rowOf('ann').querySelector('img')?.getAttribute('src')).toBe('https://example.test/ann.png');
+ expect(within(rowOf('bob')).getByText('B')).toBeInTheDocument();
+ });
+
+ it('FE-ATLAS2-MOBILE-126: a profile shows the figures and the badges and starts the comparison', () => {
+ const profile = person(3, 'bob', 8, {
+ flightKm: 52400,
+ badges: [
+ {
+ id: 'x',
+ motif: 'countries',
+ tier: 'gold',
+ target: 10,
+ titleKey: 'badge.x',
+ params: { country: 'FR' },
+ },
+ { id: 'y', motif: 'earth', tier: 'bronze', target: 40075, titleKey: 'badge.y' },
+ ],
+ });
+ const s = buildGlobeState({ ranking: RANKING, profile, badges: [1, 2, 3, 4, 5] });
+ render();
+ const sheet = screen.getByRole('dialog', { name: 'bob' });
+ expect(within(sheet).getByText('atlas.globe.collected:2,5')).toBeInTheDocument();
+ expect(within(sheet).getByText('52k')).toBeInTheDocument();
+ expect(within(sheet).getByText('badge.x:name-FR')).toBeInTheDocument();
+ expect(within(sheet).getByText('badge.y:')).toBeInTheDocument();
+ fireEvent.click(within(sheet).getByRole('button', { name: 'atlas.globe.compareOnGlobe' }));
+ expect(s.setProfileId).toHaveBeenCalledWith(null);
+ expect(s.startCompare).toHaveBeenCalledWith(profile);
+ });
+
+ it('FE-ATLAS2-MOBILE-127: a profile without badges says so and its close button closes it', () => {
+ const s = buildGlobeState({ profile: person(3, 'bob', 8) });
+ render();
+ const sheet = screen.getByRole('dialog', { name: 'bob' });
+ expect(within(sheet).getByText('atlas.globe.noBadgesYet')).toBeInTheDocument();
+ fireEvent.click(within(sheet).getByRole('button', { name: 'common.close' }));
+ expect(s.setProfileId).toHaveBeenCalledWith(null);
+ });
+});
diff --git a/client/src/mobile/screens/atlas/hub/MHubWishlist.test.tsx b/client/src/mobile/screens/atlas/hub/MHubWishlist.test.tsx
new file mode 100644
index 000000000..8097e03a6
--- /dev/null
+++ b/client/src/mobile/screens/atlas/hub/MHubWishlist.test.tsx
@@ -0,0 +1,405 @@
+import { getIntlLanguage } from '@trek/shared';
+import React from 'react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { buildBucketItem } from '../../../../../tests/helpers/atlas';
+import { buildBucketState, buildGlobeState } from '../../../../../tests/helpers/atlasGlobeState';
+import { act, fireEvent, render, screen, within } from '../../../../../tests/helpers/render';
+import { visitedOn } from '../../../../pages/atlas/atlasHubModel';
+import type { BucketItem } from '../../../../pages/atlas/atlasModel';
+import type { GlobePlaceHit } from '../../../../pages/atlas/useGlobePlaceSearch';
+import MHubWishlist from './MHubWishlist';
+
+// The place search asks the server; here it answers what the test puts in.
+const search = vi.hoisted(() => ({
+ hits: [] as Array<{ name: string; address: string | null; lat: number; lng: number }>,
+ loading: false,
+ asked: [] as Array<[string, string]>,
+}));
+vi.mock('../../../../pages/atlas/useGlobePlaceSearch', () => ({
+ useGlobePlaceSearch: (query: string, lang: string) => {
+ search.asked.push([query, lang]);
+ return { placeHits: search.hits, placesLoading: search.loading };
+ },
+}));
+
+interface Form {
+ name: string;
+ notes: string;
+ lat: string;
+ lng: string;
+ target_date: string;
+ address?: string;
+}
+
+const EMPTY: Form = { name: '', notes: '', lat: '', lng: '', target_date: '' };
+
+function spies() {
+ return {
+ setShowBucketAdd: vi.fn(),
+ setBucketForm: vi.fn(),
+ setBucketPoiYear: vi.fn(),
+ setBucketPoiMonth: vi.fn(),
+ resetBucketAdd: vi.fn(),
+ handleSelectBucketPoi: vi.fn(),
+ handleAddBucketItem: vi.fn(async () => undefined),
+ handleDeleteBucketItem: vi.fn(async () => undefined),
+ handleClearBucketVisit: vi.fn(async () => undefined),
+ flyToPoint: vi.fn(),
+ openDawarich: vi.fn(),
+ };
+}
+type Spies = ReturnType;
+
+/** The wishlist over a bucket state that really changes, so the add sheet reacts as it does in the app. */
+function Harness({
+ items = [],
+ spy,
+ open = false,
+ form = {},
+ year: startYear = 0,
+ month: startMonth = 0,
+ dawarich = false,
+}: {
+ items?: BucketItem[];
+ spy: Spies;
+ open?: boolean;
+ form?: Partial