import 'package:flutter_test/flutter_test.dart';

import 'package:badnote/diagnostics/badnote_log.dart';
import 'package:badnote/diagnostics/pen_event_ring.dart';
import 'package:badnote/diagnostics/frame_sampler.dart';

void main() {
  test('PenEventRing retains recent events', () {
    final ring = PenEventRing.instance;
    ring.clear();
    ring.recordArbiter(
      activeCount: 1,
      deviceKind: 'stylus',
      draw: true,
      fingerDrawing: false,
    );
    expect(ring.recent(), isNotEmpty);
    expect(ring.toJsonList().first['decision'], 'draw');
  });

  test('FrameSampler flags over-budget frames', () {
    FrameSampler.instance.reset();
    FrameSampler.instance.record('test', 8);
    FrameSampler.instance.record('slow', 30);
    expect(FrameSampler.instance.overBudget, 1);
    expect(FrameSampler.instance.summary()['total'], 2);
  });

  test('BadNoteLog ring accepts entries without start', () {
    BadNoteLog.instance.info(LogSubsystem.diag, 'unit_test_ping');
    expect(
      BadNoteLog.instance.snapshotRing().any((e) => e['msg'] == 'unit_test_ping'),
      isTrue,
    );
  });
}
