The picker now offers only a photo; with none, the generated DiceBear avatar is used. Removes the seedks-ttf illustration row (and the now-dead avatarGlyphNames/avatarGlyphToken). tane:seed:<glyph> values set before this still render (avatarGlyphChar kept) for backward compatibility.
93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tane/services/profile_cache.dart';
|
|
import 'package:tane/ui/avatar.dart';
|
|
import 'package:tane/ui/peer_avatar.dart';
|
|
import 'package:tane/ui/seed_glyph.dart';
|
|
|
|
import '../support/test_support.dart';
|
|
|
|
void main() {
|
|
group('avatar value scheme', () {
|
|
test('legacy seed-illustration names still map to a glyph; unknown → null',
|
|
() {
|
|
expect(avatarGlyphChar('jars'), isNotNull);
|
|
expect(avatarGlyphChar('sack'), isNotNull);
|
|
expect(avatarGlyphChar('nope'), isNull);
|
|
});
|
|
});
|
|
|
|
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('falls back to a generated avatar keyed by pubkey', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(host(PeerAvatar(pubkey: 'aa', name: 'rosa')));
|
|
final generated =
|
|
tester.widget<GeneratedAvatar>(find.byType(GeneratedAvatar));
|
|
expect(generated.pubkey, 'aa'); // pubkey, not name → stable across renames
|
|
expect(find.byType(Text), findsNothing);
|
|
});
|
|
|
|
testWidgets('generates it even when the name is unknown', (tester) async {
|
|
await tester.pumpWidget(host(const PeerAvatar(pubkey: 'aa')));
|
|
expect(find.byType(GeneratedAvatar), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('renders a seed illustration when the avatar is a token', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(host(const PeerAvatar(
|
|
pubkey: 'aa', name: 'rosa', picture: 'tane:seed:jars')));
|
|
expect(find.byType(SeedGlyph), findsOneWidget);
|
|
expect(find.text('R'), findsNothing); // the initial isn't used
|
|
});
|
|
});
|
|
|
|
group('CachedAvatar', () {
|
|
Widget host(Widget child) => MaterialApp(
|
|
home: Scaffold(body: Center(child: child)),
|
|
);
|
|
|
|
testWidgets('paints the cached illustration for the peer', (tester) async {
|
|
final cache = ProfileCache(InMemorySecretStore());
|
|
await cache.setPicture('peer1', 'tane:seed:sack');
|
|
await tester.pumpWidget(host(
|
|
CachedAvatar(pubkey: 'peer1', name: 'Bea', cache: cache)));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(SeedGlyph), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('falls back to the generated avatar when nothing is cached', (
|
|
tester,
|
|
) async {
|
|
final cache = ProfileCache(InMemorySecretStore());
|
|
await tester.pumpWidget(host(
|
|
CachedAvatar(pubkey: 'peer2', name: 'Bea', cache: cache)));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(GeneratedAvatar), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('no cache → the generated avatar', (tester) async {
|
|
await tester.pumpWidget(host(const CachedAvatar(pubkey: 'x', name: 'Bea')));
|
|
expect(find.byType(GeneratedAvatar), findsOneWidget);
|
|
});
|
|
});
|
|
}
|