Profiles had only a coloured-initial disc. Now each person can set an avatar — a real photo OR one of our own seed illustrations (so pseudonymity stays the default; no photo required). - ui/avatar.dart: the one-string value scheme carried in the kind:0 'picture' — a 'data:' photo thumbnail, a 'tane:seed:<glyph>' token, or empty. The Nostr ProfileTransport already published 'picture'. - Photos ride inline as a tiny thumbnail (reuses offerThumbnailDataUri, 24 KB cap) — no media server, like offer photos. - avatar_edit.dart: pick/take a photo, choose a seed illustration, or remove; ProfileStore stores it; ProfileScreen shows a big editable avatar and publishes it. - PeerAvatar renders photo / illustration / initial fallback. - ProfileCache gains picture/setPicture; the inbox caches peers' avatars alongside their names. - i18n avatar block (en/es/pt/ast). Tests: value scheme + PeerAvatar render modes, store + cache round-trips. Follow-up: render peers' avatars in chat/market/your-people (thread the cached picture into PeerAvatar at each call site).
59 lines
1.9 KiB
Dart
59 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tane/ui/avatar.dart';
|
|
import 'package:tane/ui/peer_avatar.dart';
|
|
import 'package:tane/ui/seed_glyph.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
|
|
});
|
|
});
|
|
}
|