mirror of
https://github.com/l5yth/potato-mesh.git
synced 2026-05-08 06:14:46 +02:00
2269d9b4ba
* app: add persistance * app: address review comments * app: do not fail on http error or timeout * app: only load instances if none are cached
92 lines
2.7 KiB
Dart
92 lines
2.7 KiB
Dart
// This is a basic Flutter widget test.
|
|
//
|
|
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
// utility in the flutter_test package. For example, you can send tap and scroll
|
|
// gestures. You can also use WidgetTester to find child widgets in the widget
|
|
// tree, read text, and verify that the values of widget properties are correct.
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:potato_mesh_reader/main.dart';
|
|
|
|
void main() {
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
NodeShortNameCache.instance.clear();
|
|
});
|
|
|
|
testWidgets('renders messages from fetcher and refreshes list',
|
|
(WidgetTester tester) async {
|
|
final sampleMessages = <MeshMessage>[
|
|
MeshMessage(
|
|
id: 1,
|
|
rxTime: null,
|
|
rxIso: '2025-01-01T00:00:00Z',
|
|
fromId: '!nodeA',
|
|
toId: '^all',
|
|
channel: 1,
|
|
channelName: 'TEST',
|
|
portnum: 'TEXT_MESSAGE_APP',
|
|
text: 'hello world',
|
|
rssi: -100,
|
|
snr: -5.0,
|
|
hopLimit: 3,
|
|
),
|
|
MeshMessage(
|
|
id: 2,
|
|
rxTime: null,
|
|
rxIso: '2025-01-01T01:00:00Z',
|
|
fromId: '!nodeB',
|
|
toId: '^all',
|
|
channel: 1,
|
|
channelName: 'TEST',
|
|
portnum: 'TEXT_MESSAGE_APP',
|
|
text: 'second message',
|
|
rssi: -90,
|
|
snr: -4.0,
|
|
hopLimit: 3,
|
|
),
|
|
];
|
|
|
|
var fetchCount = 0;
|
|
Future<List<MeshMessage>> mockFetcher({
|
|
http.Client? client,
|
|
String domain = 'potatomesh.net',
|
|
}) async {
|
|
final idx = fetchCount >= sampleMessages.length
|
|
? sampleMessages.length - 1
|
|
: fetchCount;
|
|
fetchCount += 1;
|
|
return [sampleMessages[idx]];
|
|
}
|
|
|
|
Future<BootstrapResult> bootstrapper({ProgressCallback? onProgress}) async {
|
|
onProgress?.call(const BootstrapProgress(stage: 'loading instances'));
|
|
return BootstrapResult(
|
|
instances: const [],
|
|
nodes: const [],
|
|
messages: sampleMessages,
|
|
selectedDomain: 'potatomesh.net',
|
|
);
|
|
}
|
|
|
|
await tester.pumpWidget(
|
|
PotatoMeshReaderApp(
|
|
fetcher: mockFetcher,
|
|
bootstrapper: bootstrapper,
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.textContaining('PotatoMesh Reader'), findsOneWidget);
|
|
expect(find.textContaining('[--:--]'), findsWidgets);
|
|
expect(find.byType(ChatLine), findsNWidgets(2));
|
|
expect(find.textContaining('hello world'), findsOneWidget);
|
|
expect(find.textContaining('#TEST'), findsWidgets);
|
|
expect(find.textContaining('<!nodeB>'), findsOneWidget);
|
|
expect(find.textContaining('second message'), findsOneWidget);
|
|
});
|
|
}
|