@@ -7,9 +7,13 @@ import {
77 bleDidDisconnectPybricks ,
88 bleDisconnectPybricks ,
99} from '../ble/actions' ;
10- import { bleDIServiceDidReceiveSoftwareRevision } from '../ble-device-info-service/actions' ;
11- import { PnpId } from '../ble-device-info-service/protocol' ;
12- import { HubType } from '../ble-lwp3-service/protocol' ;
10+ import {
11+ bleDIServiceDidReceiveFirmwareRevision ,
12+ bleDIServiceDidReceivePnPId ,
13+ bleDIServiceDidReceiveSoftwareRevision ,
14+ } from '../ble-device-info-service/actions' ;
15+ import { PnpId , PnpIdVendorIdSource } from '../ble-device-info-service/protocol' ;
16+ import { HubType , LegoCompanyId } from '../ble-lwp3-service/protocol' ;
1317import {
1418 blePybricksServiceDidNotReceiveHubCapabilities ,
1519 blePybricksServiceDidReceiveHubCapabilities ,
@@ -40,6 +44,11 @@ type State = ReturnType<typeof reducers>;
4044test ( 'initial state' , ( ) => {
4145 expect ( reducers ( undefined , { } as AnyAction ) ) . toMatchInlineSnapshot ( `
4246 {
47+ "deviceBatteryCharging": false,
48+ "deviceFirmwareVersion": "",
49+ "deviceLowBatteryWarning": false,
50+ "deviceName": "",
51+ "deviceType": "",
4352 "downloadProgress": null,
4453 "hasRepl": false,
4554 "maxBleWriteSize": 0,
@@ -298,6 +307,90 @@ describe('runtime', () => {
298307 } ) ;
299308} ) ;
300309
310+ test ( 'deviceName' , ( ) => {
311+ const testId = 'test-id' ;
312+ const testName = 'Test Name' ;
313+
314+ expect (
315+ reducers ( { deviceName : '' } as State , bleDidConnectPybricks ( testId , testName ) )
316+ . deviceName ,
317+ ) . toBe ( testName ) ;
318+
319+ expect (
320+ reducers ( { deviceName : testName } as State , bleDidDisconnectPybricks ( ) )
321+ . deviceName ,
322+ ) . toBe ( '' ) ;
323+ } ) ;
324+
325+ test ( 'deviceType' , ( ) => {
326+ expect (
327+ reducers (
328+ { deviceType : '' } as State ,
329+ bleDIServiceDidReceivePnPId ( {
330+ vendorIdSource : PnpIdVendorIdSource . BluetoothSig ,
331+ vendorId : LegoCompanyId ,
332+ productId : HubType . MoveHub ,
333+ productVersion : 0 ,
334+ } ) ,
335+ ) . deviceType ,
336+ ) . toBe ( 'Move hub' ) ;
337+
338+ expect (
339+ reducers ( { deviceType : 'Move hub' } as State , bleDidDisconnectPybricks ( ) )
340+ . deviceType ,
341+ ) . toBe ( '' ) ;
342+ } ) ;
343+
344+ test ( 'deviceFirmwareVersion' , ( ) => {
345+ const testVersion = '3.0.0' ;
346+
347+ expect (
348+ reducers (
349+ { deviceFirmwareVersion : '' } as State ,
350+ bleDIServiceDidReceiveFirmwareRevision ( testVersion ) ,
351+ ) . deviceFirmwareVersion ,
352+ ) . toBe ( testVersion ) ;
353+
354+ expect (
355+ reducers (
356+ { deviceFirmwareVersion : testVersion } as State ,
357+ bleDidDisconnectPybricks ( ) ,
358+ ) . deviceFirmwareVersion ,
359+ ) . toBe ( '' ) ;
360+ } ) ;
361+
362+ test ( 'deviceLowBatteryWarning' , ( ) => {
363+ expect (
364+ reducers (
365+ { deviceLowBatteryWarning : false } as State ,
366+ didReceiveStatusReport ( statusToFlag ( Status . BatteryLowVoltageWarning ) , 0 , 0 ) ,
367+ ) . deviceLowBatteryWarning ,
368+ ) . toBeTruthy ( ) ;
369+
370+ expect (
371+ reducers (
372+ { deviceLowBatteryWarning : true } as State ,
373+ didReceiveStatusReport (
374+ ~ statusToFlag ( Status . BatteryLowVoltageWarning ) ,
375+ 0 ,
376+ 0 ,
377+ ) ,
378+ ) . deviceLowBatteryWarning ,
379+ ) . toBeFalsy ( ) ;
380+
381+ expect (
382+ reducers ( { deviceLowBatteryWarning : true } as State , bleDidDisconnectPybricks ( ) )
383+ . deviceLowBatteryWarning ,
384+ ) . toBeFalsy ( ) ;
385+ } ) ;
386+
387+ test ( 'deviceBatteryCharging' , ( ) => {
388+ expect (
389+ reducers ( { deviceBatteryCharging : true } as State , bleDidDisconnectPybricks ( ) )
390+ . deviceBatteryCharging ,
391+ ) . toBeFalsy ( ) ;
392+ } ) ;
393+
301394describe ( 'maxBleWriteSize' , ( ) => {
302395 test . each ( [ 100 , 1000 ] ) ( 'Pybricks Profile >= v1.2.0: %s' , ( size ) => {
303396 expect (
0 commit comments