Files
TREK/client/src/components/Map/offlineBasemap.test.ts
T
Maurice b07b38b5b7 feat(map): never leave an offline map grey, whatever the basemap
Offline, a Mapbox map, another OpenFreeMap style or a raster template the
device cannot serve now switches to the stored OpenFreeMap basemap, light or
dark with the colour scheme, keeping every marker, route and track, with a
small Offline map pill. It switches back once the connection returns.

"Prepare for offline" stores that basemap's region for every trip, whatever
the provider, and both styles' sprites and glyphs, including the scripts a
trip in East or South Asia labels its places in. The vector prefetch keeps to
OpenFreeMap's download rules (four requests at a time, 50 MB per run), raster
tiles are no longer prefetched from OpenStreetMap's own servers, which their
policy forbids, nor inside the iOS app, which has no service worker to serve
them.
2026-11-06 15:02:48 +01:00

34 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { OFM_DARK, OFM_POSITRON } from '../../constants/mapDefaults';
import { glWorksOffline, isOfflineForbiddenTemplate, leafletWorksOffline, offlineStyleFor } from './offlineBasemap';
describe('offlineBasemap', () => {
it('picks the stored style for the colour scheme', () => {
expect(offlineStyleFor(false)).toBe(OFM_POSITRON);
expect(offlineStyleFor(true)).toBe(OFM_DARK);
});
it('knows OpenStreetMap standard tiles may not be stored, sharded or not', () => {
expect(isOfflineForbiddenTemplate('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')).toBe(true);
expect(isOfflineForbiddenTemplate('https://tile.openstreetmap.org/{z}/{x}/{y}.png')).toBe(true);
expect(isOfflineForbiddenTemplate('https://tile.openstreetmap.de/{z}/{x}/{y}.png')).toBe(false);
expect(isOfflineForbiddenTemplate('not a url')).toBe(false);
});
it('lets only MapLibre on a stored style draw offline as configured', () => {
expect(glWorksOffline('maplibre-gl', OFM_POSITRON)).toBe(true);
expect(glWorksOffline('maplibre-gl', OFM_DARK)).toBe(true);
// The default MapLibre style is Liberty, whose sprite and glyphs are not stored.
expect(glWorksOffline('maplibre-gl', '')).toBe(false);
expect(glWorksOffline('mapbox-gl', OFM_POSITRON)).toBe(false);
});
it('keeps a stored raster template on the web, never in the iOS app or for OSM', () => {
expect(leafletWorksOffline(OFM_POSITRON, true)).toBe(true);
expect(leafletWorksOffline('https://tiles.openfreemap.org/styles/liberty', false)).toBe(false);
expect(leafletWorksOffline('https://tiles.example.com/{z}/{x}/{y}.png', false)).toBe(true);
expect(leafletWorksOffline('https://tiles.example.com/{z}/{x}/{y}.png', true)).toBe(false);
expect(leafletWorksOffline('https://tile.openstreetmap.org/{z}/{x}/{y}.png', false)).toBe(false);
});
});