mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
49e306ea48
reportGlViewport says what a GL map shows, its bounds and its zoom on the raster tile scale, and has its own test for that scale. MapViewGL only wires it to moveend and idle, and its test checks that wiring. The GL map tests put the zoom back to its default before each test, as they do for every other value a test overrides, instead of each test restoring it.
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { reportGlViewport } from './glViewport';
|
|
|
|
/** A GL map showing the given box at the given zoom, or no box yet. */
|
|
function fakeMap(zoom: number, box: { south: number; west: number; north: number; east: number } | null) {
|
|
const bounds = box && {
|
|
getSouth: () => box.south,
|
|
getWest: () => box.west,
|
|
getNorth: () => box.north,
|
|
getEast: () => box.east,
|
|
};
|
|
return { getBounds: () => bounds, getZoom: () => zoom };
|
|
}
|
|
|
|
describe('reportGlViewport', () => {
|
|
it('reports the visible box with the zoom on the raster tile scale', () => {
|
|
const report = vi.fn();
|
|
reportGlViewport(fakeMap(10, { south: 47, west: 11, north: 48, east: 12 }), report);
|
|
// The GL engine counts on 512 px tiles; a raster tile's zoom is one step further in.
|
|
expect(report).toHaveBeenCalledWith({ south: 47, west: 11, north: 48, east: 12 }, 11);
|
|
});
|
|
|
|
it('says nothing while the map has no bounds yet', () => {
|
|
const report = vi.fn();
|
|
reportGlViewport(fakeMap(10, null), report);
|
|
expect(report).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('asks nothing of the map when no one listens', () => {
|
|
const map = fakeMap(10, { south: 47, west: 11, north: 48, east: 12 });
|
|
const getZoom = vi.spyOn(map, 'getZoom');
|
|
reportGlViewport(map, undefined);
|
|
expect(getZoom).not.toHaveBeenCalled();
|
|
});
|
|
});
|