mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
feat(native): the app's own location on iOS, and a status bar tap scrolls to top
WKWebView asks for the location per server origin, under the server's name, and again across launches. Binaries with the geolocation feature answer navigator.geolocation from CoreLocation instead: one When-In-Use prompt as the app, a stream that runs only while something listens, at the accuracy the most demanding caller asked for. Every caller keeps the browser API. A tap on the status bar now scrolls the list in the middle of the screen back to the top, as in every iOS app.
This commit is contained in:
@@ -6,7 +6,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { closeTopOverlay } from '../mobile/overlayStack';
|
||||
import { isEffectivelyOffline } from '../sync/networkMode';
|
||||
import { checkAppUpdate } from './capabilities';
|
||||
import { startNativeApp } from './nativeApp';
|
||||
import { installNativeGeolocation } from './geolocation';
|
||||
import { scrollToTop, startNativeApp } from './nativeApp';
|
||||
import { keepOfflineShellFresh } from './offlineShell';
|
||||
import { isNativeApp, isNativeIos } from './platform';
|
||||
|
||||
@@ -17,7 +18,11 @@ vi.mock('@capacitor/status-bar', () => ({ StatusBar: { setStyle: vi.fn() }, Styl
|
||||
vi.mock('./platform', () => ({ isNativeApp: vi.fn(), isNativeIos: vi.fn() }));
|
||||
vi.mock('./offlineShell', () => ({ keepOfflineShellFresh: vi.fn() }));
|
||||
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn() }));
|
||||
vi.mock('./capabilities', () => ({ checkAppUpdate: vi.fn(async () => false) }));
|
||||
vi.mock('./capabilities', () => ({
|
||||
checkAppUpdate: vi.fn(async () => false),
|
||||
loadNativeCapabilities: vi.fn(async () => ({})),
|
||||
}));
|
||||
vi.mock('./geolocation', () => ({ installNativeGeolocation: vi.fn() }));
|
||||
vi.mock('../mobile/overlayStack', () => ({ closeTopOverlay: vi.fn(() => false) }));
|
||||
|
||||
function backButtonHandler(): (event: { canGoBack: boolean }) => void {
|
||||
@@ -59,6 +64,24 @@ describe('startNativeApp', () => {
|
||||
back.mockRestore();
|
||||
});
|
||||
|
||||
it('puts the app location under navigator.geolocation once the binary has answered', async () => {
|
||||
vi.useRealTimers();
|
||||
startNativeApp();
|
||||
await vi.waitFor(() => expect(installNativeGeolocation).toHaveBeenCalled());
|
||||
});
|
||||
|
||||
it('a status bar tap scrolls the list in the middle of the screen back to the top', () => {
|
||||
const list = document.createElement('div');
|
||||
list.style.overflowY = 'auto';
|
||||
Object.defineProperty(list, 'scrollTop', { configurable: true, value: 300 });
|
||||
list.scrollTo = vi.fn();
|
||||
document.body.appendChild(list);
|
||||
document.elementFromPoint = vi.fn(() => list);
|
||||
scrollToTop();
|
||||
expect(list.scrollTo).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' });
|
||||
list.remove();
|
||||
});
|
||||
|
||||
it('asks the binary what it can do and the server which binary it needs', () => {
|
||||
startNativeApp();
|
||||
expect(checkAppUpdate).toHaveBeenCalledWith(expect.any(Function));
|
||||
|
||||
Reference in New Issue
Block a user