Follow-up to the avatar feature: peers' published photos/illustrations now actually render where people appear. - CachedAvatar: a PeerAvatar that resolves the person's picture from the ProfileCache (FutureBuilder), falling back to the coloured-initial disc. For list/row sites — one avatar each. - Chat bubbles: the peer's and my own avatar are resolved once into state (_peerPicture/_selfPicture — from the cache / ProfileStore, freshened from the peer's published profile) and threaded to each bubble, so many bubbles of two people don't each hit the cache. - Chat list + your-people rows: swapped the static person-icon disc for CachedAvatar, so photos/illustrations show there too. - Tests: CachedAvatar render modes (cached illustration / initial / no cache). analyze clean; chat + your-people suites green. Market offers show no author avatar today (would be a new element, not a swap) — left out of scope.
92 lines
3.1 KiB
Dart
92 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('every offered illustration maps to a glyph; unknown → null', () {
|
|
for (final name in avatarGlyphNames) {
|
|
expect(avatarGlyphChar(name), isNotNull, reason: name);
|
|
}
|
|
expect(avatarGlyphChar('nope'), isNull);
|
|
expect(avatarGlyphToken('jars'), 'tane:seed:jars');
|
|
});
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|
|
}
|