mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
25351c3628
The day swipe only rubber-banded the current day, then cut to the next one after a fixed slide and a synchronous re-render of the whole planner. The previous, current and next day now sit side by side in a horizontal scroll-snap strip, so the finger drags the neighbour in, and momentum, edge bounce and axis locking are the browser's own. The day changes once the strip comes to rest, with a light haptic tick in the app. The pager is one building block, MDayPager, used by the plan timeline and the road trip stages alike. Each page renders its own day through the timeline and stage hooks, which now take the day as a parameter, and keeps its state when it slides into the middle.
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { Haptics, ImpactStyle, NotificationType } from '@capacitor/haptics';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { tickHaptic, toastHaptic } from './haptics';
|
|
import { isNativeApp } from './platform';
|
|
|
|
vi.mock('@capacitor/haptics', () => ({
|
|
Haptics: { notification: vi.fn(), impact: vi.fn() },
|
|
ImpactStyle: { Light: 'LIGHT' },
|
|
NotificationType: { Success: 'SUCCESS', Warning: 'WARNING', Error: 'ERROR' },
|
|
}));
|
|
vi.mock('./platform', () => ({ isNativeApp: vi.fn() }));
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(Haptics.notification).mockReset().mockResolvedValue();
|
|
vi.mocked(Haptics.impact).mockReset().mockResolvedValue();
|
|
vi.mocked(isNativeApp).mockReturnValue(true);
|
|
});
|
|
|
|
describe('toastHaptic', () => {
|
|
it('taps for success, warning and error toasts in the app', () => {
|
|
toastHaptic('success');
|
|
toastHaptic('warning');
|
|
toastHaptic('error');
|
|
expect(vi.mocked(Haptics.notification).mock.calls.map(([o]) => o?.type)).toEqual([
|
|
NotificationType.Success,
|
|
NotificationType.Warning,
|
|
NotificationType.Error,
|
|
]);
|
|
});
|
|
|
|
it('stays still for info toasts and in a browser', () => {
|
|
toastHaptic('info');
|
|
vi.mocked(isNativeApp).mockReturnValue(false);
|
|
toastHaptic('success');
|
|
expect(Haptics.notification).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('does not let a missing vibrator surface as an error', async () => {
|
|
const report = vi.fn();
|
|
vi.stubGlobal('reportError', report);
|
|
vi.mocked(Haptics.notification).mockRejectedValue(new Error('not available'));
|
|
toastHaptic('error');
|
|
await vi.waitFor(() => expect(report).toHaveBeenCalledWith(expect.any(Error)));
|
|
vi.unstubAllGlobals();
|
|
});
|
|
});
|
|
|
|
describe('tickHaptic', () => {
|
|
it('gives a light detent in the app', () => {
|
|
tickHaptic();
|
|
expect(Haptics.impact).toHaveBeenCalledWith({ style: ImpactStyle.Light });
|
|
});
|
|
|
|
it('stays still in a browser', () => {
|
|
vi.mocked(isNativeApp).mockReturnValue(false);
|
|
tickHaptic();
|
|
expect(Haptics.impact).not.toHaveBeenCalled();
|
|
});
|
|
});
|