import 'package:flutter_test/flutter_test.dart'; import 'package:hvbt_dash/core/protocol/dtc_map.dart'; void main() { group('S300 DTC map', () { test('contains expected number of entries', () { expect(s300DtcMap.length, equals(32)); // 4 bytes × 8 bits }); test('P0130 maps to correct description for ERR00 bit0', () { expect(s300DtcMap['ERR00_bit0'], equals('P0130 — O2 Sensor (front)')); }); test('P0505 maps for ERR00 bit2', () { expect(s300DtcMap['ERR00_bit2'], equals('P0505 — Idle Air Control Valve')); }); test('P1607 maps for ERR03 bit7', () { expect(s300DtcMap['ERR03_bit7'], equals('P1607 — PCM Internal Circuit')); }); }); group('KPro DTC map', () { test('contains entries for 18 bytes (ERR00..ERR17)', () { // Every ERR byte has 8 bits = 144 entries total expect(kproDtcMap.length, equals(144)); }); test('P0130 maps for ERR00 bit0', () { expect(kproDtcMap['ERR00_bit0'], equals('P0130 — O2 Sensor (front)')); }); test('ERR17 entries present', () { expect(kproDtcMap.containsKey('ERR17_bit0'), isTrue); expect(kproDtcMap.containsKey('ERR17_bit7'), isTrue); }); }); group('decodeDtcs helper', () { test('returns empty list when no errors', () { final result = decodeDtcs([0, 0, 0, 0], s300DtcMap); expect(result, isEmpty); }); test('decodes ERR00 bit0 = P0130', () { final result = decodeDtcs([0x01, 0, 0, 0], s300DtcMap); expect(result, contains('P0130 — O2 Sensor (front)')); }); test('decodes multiple bits in one byte', () { // ERR00 bits 0 and 1 final result = decodeDtcs([0x03, 0, 0, 0], s300DtcMap); expect(result.length, equals(2)); }); test('decodes bits across multiple bytes', () { // ERR00 bit0 + ERR01 bit0 final result = decodeDtcs([0x01, 0x01, 0, 0], s300DtcMap); expect(result.length, equals(2)); }); test('skips bits not in map gracefully', () { // Use a small dtcMap with only one entry, but set all bits final result = decodeDtcs([0xFF, 0, 0, 0], {'ERR00_bit0': 'P0130 — test'}); // Only the one mapped bit should appear expect(result.length, equals(1)); }); }); }