import { describe, expect, it } from 'vitest'; import { isCameraCaptureAllowed, isMobileCapturePermissionGranted, isVoiceCaptureAllowed, shouldPreflightMobileCapturePermissions } from './mobile-media-permission.rules'; describe('mobile-media-permission.rules', () => { it('only preflights capture permissions on Capacitor shells', () => { expect(shouldPreflightMobileCapturePermissions('capacitor')).toBe(true); expect(shouldPreflightMobileCapturePermissions('browser')).toBe(false); expect(shouldPreflightMobileCapturePermissions('electron')).toBe(false); }); it('treats granted as the only successful native permission state', () => { expect(isMobileCapturePermissionGranted('granted')).toBe(true); expect(isMobileCapturePermissionGranted('prompt')).toBe(false); expect(isMobileCapturePermissionGranted('denied')).toBe(false); }); it('only blocks voice capture on an explicit native denial', () => { expect(isVoiceCaptureAllowed({ microphone: 'granted' })).toBe(true); expect(isVoiceCaptureAllowed({ microphone: 'denied' })).toBe(false); // Dismissed dialogs ('prompt') defer to the WebView getUserMedia permission flow. expect(isVoiceCaptureAllowed({ microphone: 'prompt' })).toBe(true); expect(isVoiceCaptureAllowed({ microphone: 'prompt-with-rationale' })).toBe(true); expect(isVoiceCaptureAllowed({})).toBe(true); }); it('only blocks camera capture on an explicit native denial', () => { expect(isCameraCaptureAllowed({ camera: 'granted' })).toBe(true); expect(isCameraCaptureAllowed({ camera: 'denied' })).toBe(false); expect(isCameraCaptureAllowed({ camera: 'prompt' })).toBe(true); expect(isCameraCaptureAllowed({})).toBe(true); }); });