mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: save all pending work
ref:
This commit is contained in:
26
test/utils/avatar_label_helper_test.dart
Normal file
26
test/utils/avatar_label_helper_test.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_sar_app/utils/avatar_label_helper.dart';
|
||||
|
||||
void main() {
|
||||
group('AvatarLabelHelper.buildLabel', () {
|
||||
test('returns two initials for multi-word names', () {
|
||||
expect(AvatarLabelHelper.buildLabel('John Smith'), 'JS');
|
||||
});
|
||||
|
||||
test('returns first two characters for single-word names', () {
|
||||
expect(AvatarLabelHelper.buildLabel('Alpha'), 'AL');
|
||||
});
|
||||
|
||||
test('allows three compact characters for hash-prefixed names', () {
|
||||
expect(AvatarLabelHelper.buildLabel('#ops'), '#OP');
|
||||
});
|
||||
|
||||
test('removes spacing after hash-prefixed names', () {
|
||||
expect(AvatarLabelHelper.buildLabel('# foo alpha'), '#FO');
|
||||
});
|
||||
|
||||
test('keeps non-hash labels at two characters', () {
|
||||
expect(AvatarLabelHelper.buildLabel('abc'), 'AB');
|
||||
});
|
||||
});
|
||||
}
|
||||
106
test/widgets/contact_avatar_test.dart
Normal file
106
test/widgets/contact_avatar_test.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_sar_app/models/contact.dart';
|
||||
import 'package:meshcore_sar_app/widgets/common/contact_avatar.dart';
|
||||
|
||||
void main() {
|
||||
Contact buildContact({
|
||||
required String name,
|
||||
required ContactType type,
|
||||
int secondByte = 0,
|
||||
}) {
|
||||
final publicKey = Uint8List(32);
|
||||
publicKey[1] = secondByte;
|
||||
|
||||
return Contact(
|
||||
publicKey: publicKey,
|
||||
type: type,
|
||||
flags: 0,
|
||||
outPathLen: 0,
|
||||
outPath: Uint8List(0),
|
||||
advName: name,
|
||||
lastAdvert: 0,
|
||||
advLat: 0,
|
||||
advLon: 0,
|
||||
lastMod: 0,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pumpAvatar(WidgetTester tester, Contact contact) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(body: Center(child: ContactAvatar(contact: contact))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders label avatar for rooms', (tester) async {
|
||||
await pumpAvatar(
|
||||
tester,
|
||||
buildContact(name: 'Operations Room', type: ContactType.room),
|
||||
);
|
||||
|
||||
expect(find.text('OR'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsNothing);
|
||||
expect(find.byIcon(Icons.meeting_room), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders hash label avatar for rooms', (tester) async {
|
||||
await pumpAvatar(
|
||||
tester,
|
||||
buildContact(name: '#ops-room', type: ContactType.room),
|
||||
);
|
||||
|
||||
expect(find.text('#OP'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsNothing);
|
||||
expect(find.byIcon(Icons.meeting_room), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders compact hash label avatar when name includes spacing', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpAvatar(
|
||||
tester,
|
||||
buildContact(name: '# foo alpha', type: ContactType.room),
|
||||
);
|
||||
|
||||
expect(find.text('#FO'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsNothing);
|
||||
expect(find.byIcon(Icons.meeting_room), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders label avatar for channels', (tester) async {
|
||||
await pumpAvatar(
|
||||
tester,
|
||||
buildContact(name: '#ops', type: ContactType.channel, secondByte: 3),
|
||||
);
|
||||
|
||||
expect(find.text('#OP'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsNothing);
|
||||
expect(find.byIcon(Icons.public), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders non-hash label avatar for channels', (tester) async {
|
||||
await pumpAvatar(
|
||||
tester,
|
||||
buildContact(name: 'Command Net', type: ContactType.channel, secondByte: 3),
|
||||
);
|
||||
|
||||
expect(find.text('CN'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsNothing);
|
||||
expect(find.byIcon(Icons.public), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders round avatar for chat contacts', (tester) async {
|
||||
await pumpAvatar(
|
||||
tester,
|
||||
buildContact(name: 'John Smith', type: ContactType.chat),
|
||||
);
|
||||
|
||||
expect(find.text('JS'), findsOneWidget);
|
||||
expect(find.byType(CircleAvatar), findsOneWidget);
|
||||
expect(find.byIcon(Icons.person), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user