Files
TREK/client/src/components/AtlasGlobe/globeTheme.test.ts
T
Maurice 9018ee8980 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.
2026-11-29 10:21:28 +01:00

76 lines
2.8 KiB
TypeScript

// FE-ATLAS2-RENDER-100 to FE-ATLAS2-RENDER-109: the globe's paint, light and dark, and the accent it reads.
import { afterEach, describe, expect, it, vi } from 'vitest';
import { globeTheme, hexToRgb, rgbToBytes } from './globeTheme';
/** What the live stylesheet answers for --accent. */
function accentToken(value: string): void {
const read = vi.fn((name: string) => (name === '--accent' ? value : ''));
vi.stubGlobal('getComputedStyle', () => ({ getPropertyValue: read }) as unknown as CSSStyleDeclaration);
}
afterEach(() => {
vi.unstubAllGlobals();
});
describe('hexToRgb', () => {
it('FE-ATLAS2-RENDER-100: reads a six-digit hex colour into 0..1 channels', () => {
expect(hexToRgb('#ff8000')).toEqual([1, 128 / 255, 0]);
});
it('FE-ATLAS2-RENDER-101: expands the three-digit short form', () => {
expect(hexToRgb('#0f8')).toEqual([0, 1, 136 / 255]);
});
it('FE-ATLAS2-RENDER-102: ignores an alpha channel and surrounding space', () => {
expect(hexToRgb(' #11223380 ')).toEqual([0x11 / 255, 0x22 / 255, 0x33 / 255]);
});
it('FE-ATLAS2-RENDER-103: falls back to mid grey for something that is no hex colour', () => {
expect(hexToRgb('#zzzzzz')).toEqual([0.5, 0.5, 0.5]);
});
});
describe('rgbToBytes', () => {
it('FE-ATLAS2-RENDER-104: rounds channels to bytes', () => {
expect(rgbToBytes([1, 0.5, 0])).toEqual([255, 128, 0]);
expect(rgbToBytes(hexToRgb('#123456'))).toEqual([0x12, 0x34, 0x56]);
});
});
describe('globeTheme', () => {
it('FE-ATLAS2-RENDER-105: dark mode is a dark globe with white selection and arcs', () => {
const th = globeTheme(true);
expect(th.dark).toBe(true);
expect(th.selection).toEqual([1, 1, 1, 0.95]);
expect(th.arc).toEqual([0.95, 0.95, 0.95, 0.95]);
expect(Math.max(...th.land)).toBeLessThan(0.3);
expect(Math.max(...th.space0)).toBeLessThan(0.05);
});
it('FE-ATLAS2-RENDER-106: dark mode does not take the accent for the selection', () => {
accentToken('#ff0000');
expect(globeTheme(true).selection).toEqual([1, 1, 1, 0.95]);
});
it('FE-ATLAS2-RENDER-107: light mode is a bright globe whose selection is the default accent', () => {
const th = globeTheme(false);
expect(th.dark).toBe(false);
expect(Math.min(...th.land)).toBeGreaterThan(0.9);
const [r, g, b] = hexToRgb('#111827');
expect(th.selection).toEqual([r, g, b, 0.95]);
});
it('FE-ATLAS2-RENDER-108: light mode follows the live --accent token', () => {
accentToken('#4f46e5');
const [r, g, b] = hexToRgb('#4f46e5');
expect(globeTheme(false).selection).toEqual([r, g, b, 0.95]);
});
it('FE-ATLAS2-RENDER-109: an accent token that is no hex colour keeps the default', () => {
accentToken('rgb(1 2 3)');
const [r, g, b] = hexToRgb('#111827');
expect(globeTheme(false).selection).toEqual([r, g, b, 0.95]);
});
});