these too

This commit is contained in:
Andras Schmelczer 2026-05-04 16:19:15 +01:00
parent d4dde21ad2
commit 90c47afe17
11 changed files with 1045 additions and 0 deletions

View file

@ -0,0 +1,93 @@
import { describe, expect, it } from 'vitest';
import { DENSITY_GRADIENT, ENUM_PALETTE, FEATURE_GRADIENT } from './consts';
import {
emojiToTwemojiUrl,
enumIndexToColor,
getBoundsFromViewState,
getFeatureFillColor,
zoomToResolution,
} from './map-utils';
describe('map utilities', () => {
it('maps zoom levels to H3 resolutions at configured thresholds', () => {
expect(zoomToResolution(6.9)).toBe(5);
expect(zoomToResolution(7)).toBe(6);
expect(zoomToResolution(10.6)).toBe(8);
expect(zoomToResolution(14)).toBe(9);
});
it('computes buffered bounds around a view state', () => {
const bounds = getBoundsFromViewState(
{ latitude: 51.5, longitude: -0.1, zoom: 12, pitch: 0 },
1200,
800
);
expect(bounds.south).toBeLessThan(51.5);
expect(bounds.north).toBeGreaterThan(51.5);
expect(bounds.west).toBeLessThan(-0.1);
expect(bounds.east).toBeGreaterThan(-0.1);
});
it('builds twemoji URLs and wraps enum colors', () => {
expect(emojiToTwemojiUrl('🛒')).toBe('/assets/twemoji/1f6d2.png');
expect(emojiToTwemojiUrl('')).toBe('/assets/twemoji/1f4cd.png');
expect(enumIndexToColor(ENUM_PALETTE.length)).toEqual(ENUM_PALETTE[0]);
});
it('returns fallback, filtered, enum, feature, and density colors', () => {
expect(
getFeatureFillColor(
null,
undefined,
undefined,
[0, 100],
null,
0,
DENSITY_GRADIENT,
false,
180
)
).toEqual([128, 128, 128, 80]);
expect(
getFeatureFillColor(50, 50, 60, [0, 100], [70, 90], 0, DENSITY_GRADIENT, true, 180)
).toEqual([60, 55, 50, 60]);
expect(
getFeatureFillColor(1, 1, 1, [0, 2], null, 0, DENSITY_GRADIENT, false, 180, 3, ENUM_PALETTE)
).toEqual([...ENUM_PALETTE[1], 180]);
expect(
getFeatureFillColor(
0,
0,
100,
[0, 100],
null,
0,
DENSITY_GRADIENT,
false,
200,
0,
undefined,
FEATURE_GRADIENT
)
).toEqual([...FEATURE_GRADIENT[0].color, 200]);
expect(
getFeatureFillColor(
undefined,
undefined,
undefined,
null,
null,
0,
DENSITY_GRADIENT,
false,
150
)
).toEqual([...DENSITY_GRADIENT[0].color, 150]);
});
});