/** * Mock GATT Server, Services, and Characteristics * * Stateful mocks that simulate real BLE behavior: * - Characteristic reads return configured values * - Writes store values * - Notifications can be pumped programmatically */ interface MockCharacteristicConfig { /** Characteristic UUID */ uuid: string; /** Characteristic properties (all default to false except read) */ properties?: { broadcast?: boolean; read?: boolean; write?: boolean; writeWithoutResponse?: boolean; notify?: boolean; indicate?: boolean; authenticatedSignedWrites?: boolean; reliableWrite?: boolean; writableAuxiliaries?: boolean; }; /** Initial value (DataView or Uint8Array) */ value?: ArrayBuffer | Uint8Array; /** Descriptors for this characteristic */ descriptors?: MockDescriptorConfig[]; } interface MockServiceConfig { /** Service UUID */ uuid: string; /** Whether this is a primary service (default: true) */ isPrimary?: boolean; /** Characteristics in this service */ characteristics?: MockCharacteristicConfig[]; } interface MockDescriptorConfig { /** Descriptor UUID */ uuid: string; /** Initial value */ value?: ArrayBuffer | Uint8Array; } declare class MockGATTServer { private _connected; private _device; private _services; constructor(device: MockBleDevice, configs: MockServiceConfig[]); get connected(): boolean; connect(): Promise; disconnect(): void; getPrimaryService(uuid: string): Promise; getPrimaryServices(uuid?: string): Promise; /** Get a mock service for test control */ getService(uuid: string): MockService | undefined; asBluetoothRemoteGATTServer(deviceProxy?: BluetoothDevice): BluetoothRemoteGATTServer; private _assertConnected; } declare class MockService { readonly uuid: string; readonly isPrimary: boolean; private _characteristics; constructor(_device: MockBleDevice, config: MockServiceConfig); getCharacteristic(uuid: string): Promise; getCharacteristics(uuid?: string): Promise; /** Get a mock characteristic for test control */ getChar(uuid: string): MockCharacteristic | undefined; stopAllNotifications(): void; asBluetoothRemoteGATTService(deviceProxy?: BluetoothDevice): BluetoothRemoteGATTService; } declare class MockCharacteristic { readonly uuid: string; private _properties; private _value; private _notifying; private _listeners; private _descriptors; constructor(config: MockCharacteristicConfig); /** Set the characteristic value (for test setup) */ setValue(data: ArrayBuffer | Uint8Array): void; /** Pump a notification to all listeners */ emitNotification(data: ArrayBuffer | Uint8Array): void; stopNotifications(): void; get isNotifying(): boolean; /** Get a mock descriptor for test control */ getDesc(uuid: string): MockDescriptor | undefined; asBluetoothRemoteGATTCharacteristic(service: BluetoothRemoteGATTService): BluetoothRemoteGATTCharacteristic; private _writeValue; } declare class MockDescriptor { readonly uuid: string; private _value; constructor(config: MockDescriptorConfig); /** Set the descriptor value (for test setup) */ setValue(data: ArrayBuffer | Uint8Array): void; /** Get the current value */ get value(): DataView; asBluetoothRemoteGATTDescriptor(characteristic: BluetoothRemoteGATTCharacteristic): BluetoothRemoteGATTDescriptor; } /** * Mock BLE Device — stateful device with GATT server, services, characteristics */ interface MockDeviceOptions { /** Device ID (auto-generated if not provided) */ id?: string; /** Device name */ name?: string; /** Advertised service UUIDs */ serviceUUIDs?: string[]; /** GATT service configurations */ services?: MockServiceConfig[]; /** Initial RSSI value */ rssi?: number; /** Fail the first N connect() attempts with a NetworkError. */ failConnectAttempts?: number; /** Optional platform-reported write limits for MTU-aware write tests. */ writeLimits?: { withResponse?: number | null; withoutResponse?: number | null; mtu?: number | null; }; } interface MockAdvertisementOptions { /** Override RSSI for this advertisement */ rssi?: number; /** Optional TX power value */ txPower?: number; /** Override advertised UUIDs for this advertisement */ uuids?: string[]; /** Optional manufacturer data payloads */ manufacturerData?: Map; /** Optional service data payloads */ serviceData?: Map; } declare class MockBleDevice { readonly id: string; readonly name: string | undefined; private _serviceUUIDs; private _gatt; private _listeners; private _rssi; private _watchingAdvertisements; private _advertisementSink?; private _remainingConnectFailures; private _writeLimits; constructor(options?: MockDeviceOptions); /** Check if this device matches a scan filter */ matchesFilter(filter: BluetoothLEScanFilter): boolean; /** Return a Web Bluetooth-compatible BluetoothDevice object */ asBluetoothDevice(): BluetoothDevice; shouldFailConnect(): boolean; /** Simulate a disconnect event */ simulateDisconnect(): void; /** Get the mock GATT server for direct test control */ get gatt(): MockGATTServer; get serviceUUIDs(): readonly string[]; get rssi(): number; /** Emit an advertisement for requestLEScan()/watchAdvertisements() tests */ emitAdvertisement(options?: MockAdvertisementOptions): void; /** Update RSSI between advertisements */ setRSSI(rssi: number): void; /** Internal hook used by MockBluetooth to receive advertisement pumps */ setAdvertisementSink(sink: ((device: MockBleDevice, options: MockAdvertisementOptions) => void) | undefined): void; /** Internal bridge for watchAdvertisements() listeners */ dispatchAdvertisementEvent(options?: MockAdvertisementOptions): void; /** Build a Web Bluetooth-style advertisementreceived event */ createAdvertisementEvent(deviceProxy: BluetoothDevice, options?: MockAdvertisementOptions): Event; private _addListener; private _removeListener; private _emit; } /** * Mock Bluetooth API — drop-in replacement for navigator.bluetooth * * Provides a stateful mock that tracks devices, manages connections, * and can be configured for various test scenarios. */ interface MockBluetoothOptions { /** Whether Bluetooth is available (default: true) */ available?: boolean; /** Pre-registered devices that will appear in scans */ devices?: MockDeviceOptions[]; } declare class MockBluetooth { private _available; private _devices; private _listeners; private _scanActive; private _installedNavigatorBluetooth?; private _lastScanOptions?; readonly backgroundSync: { requestPermission: () => Promise; requestBackgroundConnection: () => Promise; registerCharacteristicNotifications: () => Promise; registerBeaconScanning: () => Promise; getRegistrations: () => Promise; unregister: () => Promise; update: () => Promise; connect: () => Promise; subscribe: () => Promise; scan: () => Promise; list: () => Promise; destroy: () => void; }; readonly peripheral: { advertising: boolean; advertise: () => Promise; stopAdvertising: () => Promise; send: () => Promise; destroy: () => void; addEventListener: () => void; removeEventListener: () => void; onwriterequest: null; onsubscriptionchange: null; onconnectionstatechange: null; onadvertisingstatechange: null; }; constructor(options?: MockBluetoothOptions); getAvailability(): Promise; requestDevice(options?: RequestDeviceOptions): Promise; getDevices(): Promise; requestLEScan(options?: BluetoothLEScanOptions): Promise; addEventListener(type: string, listener: EventListener): void; removeEventListener(type: string, listener: EventListener): void; /** Add a device to the mock registry */ addDevice(options: MockDeviceOptions): MockBleDevice; /** Remove a device from the registry */ removeDevice(id: string): void; /** Get a mock device by ID for test assertions */ getDevice(id: string): MockBleDevice | undefined; /** Set Bluetooth availability */ setAvailable(available: boolean): void; /** Install this mock instance onto navigator.bluetooth */ install(): this; /** Restore the previous navigator.bluetooth value */ uninstall(): void; /** Emit a Bluetooth-level advertisementreceived event */ emitAdvertisement(deviceId: string, options?: MockAdvertisementOptions): void; /** Reset all state */ reset(): void; private _findMatchingDevices; private readonly _handleAdvertisement; private _matchesScan; } /** * Install mock Bluetooth API on the global navigator object. * Returns a MockBluetooth instance for test control. */ declare function createMockBluetooth(options?: MockBluetoothOptions): MockBluetooth; /** * Install mock Bluetooth on navigator.bluetooth. * Returns the mock instance for control. */ declare function installMockBluetooth(options?: MockBluetoothOptions): MockBluetooth; /** Common Bluetooth SIG UUIDs for test convenience */ declare const BLE_UUIDS: { readonly services: { readonly HEART_RATE: "0000180d-0000-1000-8000-00805f9b34fb"; readonly BATTERY: "0000180f-0000-1000-8000-00805f9b34fb"; readonly DEVICE_INFO: "0000180a-0000-1000-8000-00805f9b34fb"; readonly ENVIRONMENTAL_SENSING: "0000181a-0000-1000-8000-00805f9b34fb"; }; readonly characteristics: { readonly HEART_RATE_MEASUREMENT: "00002a37-0000-1000-8000-00805f9b34fb"; readonly BODY_SENSOR_LOCATION: "00002a38-0000-1000-8000-00805f9b34fb"; readonly BATTERY_LEVEL: "00002a19-0000-1000-8000-00805f9b34fb"; readonly MANUFACTURER_NAME: "00002a29-0000-1000-8000-00805f9b34fb"; readonly MODEL_NUMBER: "00002a24-0000-1000-8000-00805f9b34fb"; readonly TEMPERATURE: "00002a6e-0000-1000-8000-00805f9b34fb"; }; readonly descriptors: { /** Client Characteristic Configuration Descriptor */ readonly CCCD: "00002902-0000-1000-8000-00805f9b34fb"; /** Characteristic User Description */ readonly USER_DESCRIPTION: "00002901-0000-1000-8000-00805f9b34fb"; /** Characteristic Presentation Format */ readonly PRESENTATION_FORMAT: "00002904-0000-1000-8000-00805f9b34fb"; }; }; /** Pre-configured device factories for common test scenarios */ declare const devices: { /** Heart rate sensor with notification support */ heartRate(name?: string): MockDeviceOptions; /** Battery service device */ battery(name?: string): MockDeviceOptions; /** Device with multiple services */ full(name?: string): MockDeviceOptions; }; export { BLE_UUIDS, type MockAdvertisementOptions, MockBleDevice, MockBluetooth, type MockBluetoothOptions, MockCharacteristic, type MockCharacteristicConfig, MockDescriptor, type MockDescriptorConfig, type MockDeviceOptions, MockGATTServer, MockService, type MockServiceConfig, createMockBluetooth, devices, installMockBluetooth };