import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/ui/peer_avatar.dart';

void main() {
  group('peerAvatarColor', () {
    test('is deterministic for the same pubkey', () {
      expect(peerAvatarColor('ab' * 32), peerAvatarColor('ab' * 32));
    });

    test('differs for different pubkeys', () {
      expect(peerAvatarColor('ab' * 32), isNot(peerAvatarColor('cd' * 32)));
    });

    test('is fully opaque (legible disc)', () {
      expect(peerAvatarColor('feed').a, 1.0);
    });
  });

  group('PeerAvatar', () {
    Widget host(Widget child) => MaterialApp(
      home: Scaffold(body: Center(child: child)),
    );

    testWidgets('shows the name initial when known', (tester) async {
      await tester.pumpWidget(host(PeerAvatar(pubkey: 'aa', name: 'rosa')));
      expect(find.text('R'), findsOneWidget); // uppercased first letter
    });

    testWidgets('falls back to a glyph when the name is unknown', (
      tester,
    ) async {
      await tester.pumpWidget(host(const PeerAvatar(pubkey: 'aa')));
      expect(find.byIcon(Icons.person_outline), findsOneWidget);
      expect(find.byType(Text), findsNothing);
    });
  });
}
