mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
6f3c051c7c
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.
45 lines
1.5 KiB
TypeScript
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();
|
|
});
|
|
});
|