mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
fix: GL maps read the stored copy again while offline, and a switch that is on keeps a visible knob in the dark scheme
This commit is contained in:
@@ -1,29 +1,38 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { hasNativeFeature } from './capabilities';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { isEffectivelyOffline } from '../sync/networkMode';
|
||||
import { GL_MAPS_THROUGH_APP_SCHEMES } from './glSchemes';
|
||||
import { installOfflineProtocol, offlineStyle } from './offlineTiles';
|
||||
import { isNativeApp, isNativeIos } from './platform';
|
||||
import { glTileStoreActive, mapboxTileCacheRequest, tileCacheActive } from './tileCache';
|
||||
|
||||
vi.mock('./platform', () => ({ isNativeIos: vi.fn(() => true), isNativeApp: vi.fn(() => true) }));
|
||||
vi.mock('./capabilities', () => ({ hasNativeFeature: vi.fn(() => true) }));
|
||||
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn(() => false) }));
|
||||
|
||||
const STYLE = 'https://tiles.openfreemap.org/styles/positron';
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('caches', { open: vi.fn() });
|
||||
vi.mocked(isEffectivelyOffline).mockReturnValue(false);
|
||||
});
|
||||
|
||||
describe('GL maps and the app schemes', () => {
|
||||
it('FE-NATIVE-GLSCHEME-001: in the iOS app the GL maps load straight from their servers, the raster store stays', () => {
|
||||
expect(vi.mocked(isNativeIos)()).toBe(true);
|
||||
expect(vi.mocked(isNativeApp)()).toBe(true);
|
||||
expect(vi.mocked(hasNativeFeature)('tileCache')).toBe(true);
|
||||
it('FE-NATIVE-GLSCHEME-001: online in the iOS app the GL maps load straight from their servers, the raster store stays', () => {
|
||||
expect(GL_MAPS_THROUGH_APP_SCHEMES).toBe(false);
|
||||
|
||||
const style = 'https://tiles.openfreemap.org/styles/positron';
|
||||
expect(offlineStyle(style)).toBe(style);
|
||||
const addProtocol = vi.fn();
|
||||
installOfflineProtocol({ addProtocol });
|
||||
expect(addProtocol).not.toHaveBeenCalled();
|
||||
|
||||
expect(offlineStyle(STYLE)).toBe(STYLE);
|
||||
const tile = 'https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/1/1/1.vector.pbf';
|
||||
expect(mapboxTileCacheRequest(tile, 'Tile')).toEqual({ url: tile });
|
||||
expect(glTileStoreActive()).toBe(false);
|
||||
expect(tileCacheActive()).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-NATIVE-GLSCHEME-002: offline, or set to be, the MapLibre basemap reads the stored copy through the protocol', () => {
|
||||
const addProtocol = vi.fn();
|
||||
installOfflineProtocol({ addProtocol });
|
||||
expect(addProtocol).toHaveBeenCalledWith('trek-offline', expect.any(Function));
|
||||
|
||||
vi.mocked(isEffectivelyOffline).mockReturnValue(true);
|
||||
expect(offlineStyle(STYLE)).toBe('trek-offline://tiles.openfreemap.org/styles/positron');
|
||||
// Mapbox never goes through the store: offline it gives way to the stored MapLibre basemap.
|
||||
expect(glTileStoreActive()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user