Drop the DiceBear generated avatar (and dicebear_core/dicebear_styles/ flutter_svg): the default is again a Material coloured-initial disc from the pubkey. Picking a photo now goes through a square crop step (crop_your_image — pure Flutter, all platforms incl. desktop, Apache-2.0, only pulls the image package we already had) before the 24 KB thumbnail.
91 lines
3.1 KiB
Dart
91 lines
3.1 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('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 person icon 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);
|
|
});
|
|
|
|
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 initial 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.text('B'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('no cache → the coloured-initial disc', (tester) async {
|
|
await tester.pumpWidget(host(const CachedAvatar(pubkey: 'x', name: 'Bea')));
|
|
expect(find.text('B'), findsOneWidget);
|
|
});
|
|
});
|
|
}
|