Files
TREK/client/src/native/haptics.test.ts
T
Maurice 6f3c051c7c fix(native): Prettier on the native client files, rate-limit e2e requests in sequence
Formats the files the client formatting gate listed, and NATIVE-E2E-005 sends its twenty exchange attempts one after another: all at once they reset the test server's connections.
2026-10-25 17:41:32 +01:00

45 lines
1.5 KiB
TypeScript

import { Haptics, NotificationType } from '@capacitor/haptics';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { toastHaptic } from './haptics';
import { isNativeApp } from './platform';
vi.mock('@capacitor/haptics', () => ({
Haptics: { notification: vi.fn() },
NotificationType: { Success: 'SUCCESS', Warning: 'WARNING', Error: 'ERROR' },
}));
vi.mock('./platform', () => ({ isNativeApp: vi.fn() }));
beforeEach(() => {
vi.mocked(Haptics.notification).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();
});
});