test(atlas): cover the new Atlas from engine to hub views

SonarCloud measured 16.9% coverage on this PR's new code. Tests now cover the WebGL globe engine (boot, caching, input, camera, regions, prefetch) and renderer (against a fake WebGL2 context that reads the real shaders), the paint, labels, sky and pins, the central useAtlasGlobe hook and the hub hooks, the snapshot, account queue and Atlas repos, every desktop and phone hub view, the server's people, flights and mesh routes, the shared badge rules, and the new view transition, warm bags and kept planner maps.
This commit is contained in:
Maurice
2026-11-29 10:21:28 +01:00
parent 10ad92574d
commit 9018ee8980
69 changed files with 14979 additions and 0 deletions
@@ -0,0 +1,94 @@
import { act, renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { packingApi } from '../../api/client';
import { _resetNetworkMode } from '../../sync/networkMode';
import type { PackingBag } from '../../types';
import { BAG_COLORS } from './packingListPanel.constants';
import { usePackingBags, warmPackingBags } from './usePackingBags';
vi.mock('./useBagTotalsPing', () => ({ useBagTotalsPing: vi.fn() }));
// FE-ATLAS2-REST-020 to 024: bags read ahead per trip (warmPackingBags), taken once by the list.
// Each test uses its own trip id, since a warm read waits in the module until a list takes it.
const t = (key: string) => key;
const bag = (over: Partial<PackingBag>): PackingBag => ({
id: 1,
trip_id: 1,
name: 'Backpack',
color: BAG_COLORS[0],
sort_order: 0,
...over,
});
function setup(tripId: number, bagTrackingEnabled = true) {
const toast = { error: vi.fn() };
return renderHook(() => usePackingBags({ tripId, bagTrackingEnabled, t, toast }));
}
beforeEach(() => {
_resetNetworkMode();
});
afterEach(() => {
vi.restoreAllMocks();
});
describe('kept packing bags', () => {
it('FE-ATLAS2-REST-020: a list opened after warmPackingBags starts with the bags read ahead', async () => {
const warm = bag({ id: 11, trip_id: 101, name: 'Ahead' });
const list = vi.spyOn(packingApi, 'listBags').mockResolvedValue({ bags: [warm], unassigned_weight_grams: 300 });
await warmPackingBags(101);
expect(list).toHaveBeenCalledWith(101);
// The read that follows the mount never answers here: what shows comes from the warm read alone.
list.mockReturnValue(new Promise(() => {}));
const { result } = setup(101);
expect(result.current.bags).toEqual([warm]);
expect(result.current.unassignedWeightGrams).toBe(300);
});
it('FE-ATLAS2-REST-021: a warm read without bags or server sum keeps an empty list and an unknown sum', async () => {
vi.spyOn(packingApi, 'listBags').mockResolvedValue({} as Awaited<ReturnType<typeof packingApi.listBags>>);
await warmPackingBags(102);
const { result } = setup(102, false);
expect(result.current.bags).toEqual([]);
expect(result.current.unassignedWeightGrams).toBeNull();
});
it('FE-ATLAS2-REST-022: a failed warm read rejects and leaves nothing kept for the trip', async () => {
vi.spyOn(packingApi, 'listBags').mockRejectedValue(new Error('offline'));
await expect(warmPackingBags(103)).rejects.toThrow('offline');
const { result } = setup(103, false);
expect(result.current.bags).toEqual([]);
expect(result.current.unassignedWeightGrams).toBeNull();
});
it('FE-ATLAS2-REST-023: a warm read is taken once; the next list on the trip starts empty and reads afresh', async () => {
const ahead = bag({ id: 21, trip_id: 104, name: 'Duffel' });
const list = vi.spyOn(packingApi, 'listBags').mockResolvedValue({ bags: [ahead], unassigned_weight_grams: 1200 });
await warmPackingBags(104);
list.mockReturnValue(new Promise(() => {}));
const one = setup(104);
expect(one.result.current.bags).toEqual([ahead]);
one.unmount();
const again = setup(104, false);
await act(async () => {});
expect(again.result.current.bags).toEqual([]);
expect(again.result.current.unassignedWeightGrams).toBeNull();
});
it('FE-ATLAS2-REST-024: the kept bags belong to their trip and never show on another one', async () => {
const mine = bag({ id: 31, trip_id: 105 });
vi.spyOn(packingApi, 'listBags').mockResolvedValue({ bags: [mine], unassigned_weight_grams: 5 });
await warmPackingBags(105);
const other = setup(106, false);
// And a list with bag tracking off does not take them either.
const off = setup(105, false);
expect(off.result.current.bags).toEqual([]);
expect(other.result.current.bags).toEqual([]);
expect(other.result.current.unassignedWeightGrams).toBeNull();
});
});