8000 chore(cbio): format the app-live session tests by shroominic · Pull Request #161 · shroominic/OpenGlucose · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions openhealth/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,9 @@ class _DashboardHeroCardState extends State<_DashboardHeroCard> {
? (cbioSnapshot
? 'Sensor raw value · index ${latest?.sensorMinute ?? '--'}'
: (latest?.isDisplayProvisional == true
? null
: libreConnectionDetailForSnapshot(snapshot)) ??
'Latest reading at ${readingTimeText(latest)}')
? null
: libreConnectionDetailForSnapshot(snapshot)) ??
'Latest reading at ${readingTimeText(latest)}')
: 'Latest reading at ${readingTimeText(latest)}';
stageLabel = stageLabelForSnapshot(snapshot);
}
Expand Down
34 changes: 18 additions & 16 deletions packages/cgm_cbio/test/cbio_driver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ final class _ScriptedScanTransport implements BleTransport {
}) async* {
serviceFilters.add(withServices);
timeouts.add(timeout);
final results =
(withServices == null || withServices.isEmpty)
? unfilteredResults
: filteredResults;
final results = (withServices == null || withServices.isEmpty)
? unfilteredResults
: filteredResults;
for (final result in results) {
yield result;
}
Expand Down Expand Up @@ -301,20 +300,23 @@ void main() {
},
);

test('scan does not retry unfiltered when the filter finds the sensor', () async {
final transport = _ScriptedScanTransport(
filteredResults: <BleScanResult>[_ff30Advertisement(rssi: -55)],
unfilteredResults: <BleScanResult>[_ff30Advertisement(rssi: -90)],
);
final driver = CbioSensorDriver(transport, discovery: discovery);
test(
'scan does not retry unfiltered when the filter finds the sensor',
() async {
final transport = _ScriptedScanTransport(
filteredResults: <BleScanResult>[_ff30Advertisement(rssi: -55)],
unfilteredResults: <BleScanResult>[_ff30Advertisement(rssi: -90)],
);
final driver = CbioSensorDriver(transport, discovery: discovery);

final results = await driver.scan().toList();
final results = await driver.scan().toList();

expect(results, hasLength(1));
expect(results.single.rssi, -55);
expect(transport.serviceFilters, hasLength(1));
expect(transport.serviceFilters.single, CbioDiscovery.scanServiceUuids);
});
expect(results, hasLength(1));
expect(results.single.rssi, -55);
expect(transport.serviceFilters, hasLength(1));
expect(transport.serviceFilters.single, CbioDiscovery.scanServiceUuids);
},
);

test('the unfiltered retry still drops non-FF30 advertisers', () async {
final transport = _ScriptedScanTransport(
Expand Down
103 changes: 54 additions & 49 deletions packages/cgm_cbio/test/cbio_glucose_session_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,12 @@ void main() {
.firstWhere((frame) => frame[1] == 0x01);
// With 2A25 empty the session falls back to the advertised identity,
// reversed, exactly as the vendor link setup does.
expect(
auth.sublist(3, 9),
<int>[0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa],
);
expect(auth.sublist(3, 9), <int>[0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa]);
await session.disconnect();
},
);

test('a rejected authentication stops before any read is sent', () async {
test('a rejected authentication stops before any read is sent', () async {
final connection = _FakeConnection();
final transport = _FakeTransport(connection);
await _defaultResponder(connection, authReply: _authRejected);
Expand Down Expand Up @@ -795,51 +792,59 @@ void main() {
});

group('CbioGlucoseSession provisional scale', () {
test('the app and the capture harness share one raw field and one scale', () {
// Replayed 08 batch: the sample the capture harness read out of the
// sensor was raw 47..53 at index 9940..9992. Those counters live in the
// same record field the session publishes as `rawValue`, so the app and
// the harness already agree byte for byte. Only the unit label differed:
// the app multiplied the unverified /10 scale by 18.0182 and called the
// result mg/dL, which no reference measurement supports.
final frame = _rawBatch(
startIndex: 9940,
baseEpochSeconds: 596400,
baseReindex: 9940,
currents: <int>[47, 50, 53],
);

final batch = parseCbioRawDataFrame(frame);
test(
'the app and the capture harness share one raw field and one scale',
() {
// Replayed 08 batch: the sample the capture harness read out of the
// sensor was raw 47..53 at index 9940..9992. Those counters live in the
// same record field the session publishes as `rawValue`, so the app and
// the harness already agree byte for byte. Only the unit label differed:
// the app multiplied the unverified /10 scale by 18.0182 and called the
// result mg/dL, which no reference measurement supports.
final frame = _rawBatch(
startIndex: 9940,
baseEpochSeconds: 596400,
baseReindex: 9940,
currents: <int>[47, 50, 53],
);

expect(
batch.records.map((record) => record.packed.index),
<int>[9940, 9941, 9942],
);
expect(batch.records.map((record) => record.rawCurrent), <int>[47, 50, 53]);
final archived = <CbioRawGlucoseRecord>[
for (final record in batch.records)
CbioRawGlucoseRecord(
index: record.packed.index,
rawTime: record.packed.rawTime,
reindex: record.packed.reindex,
rawTemperature: record.rawTemperature,
rawDump: record.rawDump,
rawCurrent: record.rawCurrent,
rawExtra: 0,
),
];
final batch = parseCbioRawDataFrame(frame);

expect(batch.records.map((record) => record.packed.index), <int>[
9940,
9941,
9942,
]);
expect(batch.records.map((record) => record.rawCurrent), <int>[
47,
50,
53,
]);
final archived = <CbioRawGlucoseRecord>[
for (final record in batch.records)
CbioRawGlucoseRecord(
index: record.packed.index,
rawTime: record.packed.rawTime,
reindex: record.packed.reindex,
rawTemperature: record.rawTemperature,
rawDump: record.rawDump,
rawCurrent: record.rawCurrent,
rawExtra: 0,
),
];

for (final record in archived) {
// The one scale both paths use, stated without a glucose unit.
expect(record.derivedMillimolesPerLitre, record.rawCurrent / 10);
expect(record.isUnitVerified, isFalse);
}
expect(archived.first.derivedMillimolesPerLitre, 4.7);
expect(archived.last.derivedMillimolesPerLitre, 5.3);
// The mg/dL derivation stays available for the chart's internal scale,
// but it is a conversion of an unverified unit, never a measurement.
expect(archived.first.derivedMilligramsPerDecilitre, 85);
expect(archived.last.derivedMilligramsPerDecilitre, 95);
});
for (final record in archived) {
// The one scale both paths use, stated without a glucose unit.
expect(record.derivedMillimolesPerLitre, record.rawCurrent / 10);
expect(record.isUnitVerified, isFalse);
}
expect(archived.first.derivedMillimolesPerLitre, 4.7);
expect(archived.last.derivedMillimolesPerLitre, 5.3);
// The mg/dL derivation stays available for the chart's internal scale,
// but it is a conversion of an unverified unit, never a measurement.
expect(archived.first.derivedMilligramsPerDecilitre, 85);
expect(archived.last.derivedMilligramsPerDecilitre, 95);
},
);
});
}
Loading
0