mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
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:
@@ -0,0 +1,141 @@
|
||||
import { BADGE_CATEGORIES, computeBadges, crossesDateline, type BadgeInput } from './atlas-badges';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
// ATLAS2-REST-040 to 052: the badge rules atlas-badges.spec.ts leaves open.
|
||||
|
||||
const base: BadgeInput = {
|
||||
countries: [],
|
||||
continents: [],
|
||||
regions: [],
|
||||
flights: { count: 0, km: 0, longestKm: 0, crossesDateline: false },
|
||||
streak: 0,
|
||||
wishesReached: 0,
|
||||
};
|
||||
|
||||
const byId = (input: Partial<BadgeInput>) => new Map(computeBadges({ ...base, ...input }).map((b) => [b.id, b]));
|
||||
const codes = (...list: string[]) => list.map((code) => ({ code }));
|
||||
|
||||
describe('atlas badge rules', () => {
|
||||
it('ATLAS2-REST-040: the country steps run bronze, silver, gold, gold... and end on aurora', () => {
|
||||
const b = byId({});
|
||||
expect(
|
||||
['countries-5', 'countries-10', 'countries-25', 'countries-50', 'countries-150'].map((id) => b.get(id)?.tier),
|
||||
).toEqual(['bronze', 'silver', 'gold', 'gold', 'aurora']);
|
||||
// Three steps or fewer never reach aurora: their last step is gold.
|
||||
expect(b.get('regions-100')?.tier).toBe('gold');
|
||||
expect(b.get('flights-100')?.tier).toBe('aurora');
|
||||
expect(b.get('streak-10')?.tier).toBe('gold');
|
||||
expect(b.get('islands-10')?.tier).toBe('silver');
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-041: a step not reached has no year or country, and its progress stops at the target', () => {
|
||||
const countries = Array.from({ length: 7 }, (_, i) => ({ code: `C${i}`, year: 2000 + i }));
|
||||
const b = byId({ countries });
|
||||
expect(b.get('countries-10')).toMatchObject({ earned: false, current: 7, year: null, country: null });
|
||||
expect(b.get('countries-5')).toMatchObject({ earned: true, current: 5, target: 5, year: 2004, country: 'C4' });
|
||||
expect(b.get('countries-1')).toMatchObject({ current: 1, target: 1 });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-042: countries without a year count after the dated ones, in code order', () => {
|
||||
const b = byId({ countries: [{ code: 'ZA' }, { code: 'BE', year: null }, { code: 'NO', year: 2015 }] });
|
||||
expect(b.get('countries-1')).toMatchObject({ year: 2015, country: 'NO' });
|
||||
const undated = byId({ countries: [{ code: 'ZA' }, { code: 'BE' }] });
|
||||
expect(undated.get('countries-1')).toMatchObject({ year: null, country: 'BE' });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-043: no country at all leaves the first badge without a year or a country', () => {
|
||||
expect(byId({}).get('countries-1')).toMatchObject({ earned: false, current: 0, year: null, country: null });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-044: Antarctica counts for all seven but not as an inhabited continent', () => {
|
||||
const b = byId({ continents: ['Europe', 'Antarctica', 'Europe'] });
|
||||
expect(b.get('continents-2')).toMatchObject({ earned: false, current: 1 });
|
||||
expect(b.get('continents-7')).toMatchObject({ current: 2 });
|
||||
const two = byId({ continents: ['Europe', 'Asia'] });
|
||||
expect(two.get('continents-2')?.earned).toBe(true);
|
||||
expect(two.get('continents-3')?.earned).toBe(false);
|
||||
});
|
||||
|
||||
it("ATLAS2-REST-045: under half of a country's regions earns nothing yet, the closest country is the next goal", () => {
|
||||
const b = byId({
|
||||
regions: [
|
||||
{ country: 'DE', visited: 2, total: 16 },
|
||||
{ country: 'FR', visited: 6, total: 13 },
|
||||
{ country: 'IT', visited: 20, total: 20 },
|
||||
],
|
||||
});
|
||||
expect(b.get('regions-half-DE')).toBeUndefined();
|
||||
expect(b.get('regions-all-DE')).toBeUndefined();
|
||||
// FR is closer to all its regions than DE, and IT is done already.
|
||||
expect(b.get('regions-next-FR')).toMatchObject({ earned: false, current: 6, target: 13, tier: 'aurora' });
|
||||
expect(b.get('regions-next-DE')).toBeUndefined();
|
||||
expect(b.get('regions-next-IT')).toBeUndefined();
|
||||
expect(b.get('regions-all-IT')).toMatchObject({ earned: true, country: 'IT', params: { country: 'IT' } });
|
||||
// The totals count every visited region.
|
||||
expect(b.get('regions-10')).toMatchObject({ earned: true, current: 10 });
|
||||
expect(b.get('regions-50')).toMatchObject({ earned: false, current: 28 });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-046: with every country done there is no next region goal', () => {
|
||||
const b = byId({ regions: [{ country: 'AT', visited: 9, total: 9 }] });
|
||||
expect([...b.keys()].some((id) => id.startsWith('regions-next-'))).toBe(false);
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-047: the long-haul, ultra and airport badges read their own numbers', () => {
|
||||
const b = byId({ flights: { count: 3, km: 41000.4, longestKm: 13000.2, crossesDateline: false, airports: 12 } });
|
||||
expect(b.get('flights-ultra')?.earned).toBe(true);
|
||||
expect(b.get('flights-earth')).toMatchObject({ earned: true, current: 40075 });
|
||||
expect(b.get('flights-earth-5')).toMatchObject({ earned: false, current: 41000 });
|
||||
expect(b.get('airports-10')?.earned).toBe(true);
|
||||
expect(b.get('airports-25')).toMatchObject({ earned: false, current: 12 });
|
||||
expect(b.get('flights-dateline')?.earned).toBe(false);
|
||||
// No airport count given is none.
|
||||
expect(byId({}).get('airports-10')).toMatchObject({ current: 0 });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-048: both hemispheres need a country west of Greenwich and one east of it', () => {
|
||||
expect(byId({ countries: codes('US') }).get('hemispheres')?.earned).toBe(false);
|
||||
expect(byId({ countries: codes('DE') }).get('hemispheres')?.earned).toBe(false);
|
||||
expect(byId({ countries: codes('US', 'DE') }).get('hemispheres')?.earned).toBe(true);
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-049: the tropics, the polar north and the islands count their countries', () => {
|
||||
const b = byId({ countries: codes('TH', 'IS', 'JP', 'MT', 'CY', 'GB', 'IE') });
|
||||
expect(b.get('tropics')?.earned).toBe(true);
|
||||
expect(b.get('polar')?.earned).toBe(true);
|
||||
expect(b.get('islands-5')).toMatchObject({ earned: true, current: 5 });
|
||||
expect(b.get('islands-10')).toMatchObject({ earned: false, current: 6 });
|
||||
const none = byId({ countries: codes('DE') });
|
||||
expect(none.get('tropics')?.earned).toBe(false);
|
||||
expect(none.get('polar')?.earned).toBe(false);
|
||||
expect(none.get('equator')?.earned).toBe(false);
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-050: the busiest year wins the burst, the earlier one on a tie, and undated countries never count', () => {
|
||||
const tie = [2018, 2018, 2018, 2016, 2016, 2016].map((year, i) => ({ code: `T${i}`, year }));
|
||||
const b = byId({ countries: [...tie, { code: 'U1' }, { code: 'U2', year: null }] });
|
||||
expect(b.get('burst-3')).toMatchObject({ earned: true, current: 3, year: 2016 });
|
||||
expect(b.get('burst-5')).toMatchObject({ earned: false, current: 3, year: null });
|
||||
const undated = byId({ countries: codes('A1', 'A2', 'A3') });
|
||||
expect(undated.get('burst-3')).toMatchObject({ earned: false, current: 0, year: null });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-051: streaks and wishes climb their steps', () => {
|
||||
const b = byId({ streak: 5, wishesReached: 10 });
|
||||
expect(b.get('streak-3')?.earned).toBe(true);
|
||||
expect(b.get('streak-5')?.earned).toBe(true);
|
||||
expect(b.get('streak-10')).toMatchObject({ earned: false, current: 5 });
|
||||
expect(['wishes-1', 'wishes-5', 'wishes-10'].every((id) => b.get(id)?.earned)).toBe(true);
|
||||
expect(b.get('wishes-10')?.category).toBe('collector');
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-052: every badge sits in one of the listed categories, ids are unique, and the date line needs more than 180 degrees', () => {
|
||||
const all = computeBadges({ ...base, regions: [{ country: 'US', visited: 30, total: 50 }] });
|
||||
expect(new Set(all.map((b) => b.id)).size).toBe(all.length);
|
||||
expect(all.every((b) => BADGE_CATEGORIES.includes(b.category))).toBe(true);
|
||||
expect(new Set(all.map((b) => b.category))).toEqual(new Set(BADGE_CATEGORIES));
|
||||
expect(crossesDateline(0, 180)).toBe(false);
|
||||
expect(crossesDateline(-179, 179)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user