import { describe, expect, it } from 'vitest'; import { buildRegionMap } from './map'; import { nationColor } from '../shared/protocol'; import type { GameState } from '../shared/types'; const state: GameState = { id: 'g', presetId: 'p', presetTitle: 'P', playerNationId: 'uk', turn: 1, date: '1939-09-01', nations: { uk: { id: 'uk', name: 'UK', type: 'major', stats: { military: 80, economy: 70, stability: 60, population: 50 }, territory: ['GBR', 'IRL'], relations: {}, }, de: { id: 'de', name: 'DE', type: 'major', stats: { military: 90, economy: 70, stability: 70, population: 90 }, territory: ['DEU'], relations: {}, }, }, events: [], }; describe('buildRegionMap', () => { it('maps each ISO_A3 region to its owner + that nation\'s stable color', () => { const m = buildRegionMap(state); expect(m.GBR).toEqual({ color: nationColor('uk'), owner: 'UK', ownerId: 'uk' }); expect(m.IRL).toEqual({ color: nationColor('uk'), owner: 'UK', ownerId: 'uk' }); expect(m.DEU).toEqual({ color: nationColor('de'), owner: 'DE', ownerId: 'de' }); // a region nobody owns is simply absent expect(m.FRA).toBeUndefined(); }); }); describe('nationColor', () => { it('is deterministic per id and distinct across different ids', () => { expect(nationColor('uk')).toBe(nationColor('uk')); expect(nationColor('uk')).not.toBe(nationColor('de')); // always a valid HSL string expect(nationColor('uk')).toMatch(/^hsl\(\d+ 58% 46%\)$/); }); });