84 lines
2.8 KiB
Dart
84 lines
2.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:crypto/crypto.dart' show sha256;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/testing.dart';
|
|
import 'package:observer/camera/model_catalog_section.dart';
|
|
import 'package:observer/models/model_manager.dart';
|
|
|
|
const _modelBytes = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
String _shaHex(List<int> bytes) => sha256.convert(bytes).toString();
|
|
|
|
Map<String, dynamic> _item() => {
|
|
'datasetId': 7,
|
|
'datasetName': '环颈雉鸡数据集',
|
|
'version': 'v1.0.0',
|
|
'labels': ['pheasant', 'suspect'],
|
|
'sizeBytes': _modelBytes.length,
|
|
'sha256': _shaHex(_modelBytes),
|
|
'downloadUrl': '/download/models/7/latest.tflite',
|
|
'coverUrl': '/api/v1/app/cover?namePrefix=RNPHE',
|
|
};
|
|
|
|
void main() {
|
|
late Directory root;
|
|
|
|
setUp(() async {
|
|
root = await Directory.systemTemp.createTemp('catalog-diag');
|
|
});
|
|
|
|
tearDown(() => root.delete(recursive: true));
|
|
|
|
ModelManager manager() => ModelManager(
|
|
baseUrl: 'http://test.local',
|
|
client: MockClient((req) async {
|
|
if (req.url.path == '/api/v1/app/update') {
|
|
return http.Response.bytes(
|
|
utf8.encode(jsonEncode({
|
|
'code': 0,
|
|
'message': 'ok',
|
|
'data': {'models': [_item()]}
|
|
})),
|
|
200);
|
|
}
|
|
if (req.url.path.startsWith('/download/models/')) {
|
|
return http.Response.bytes(_modelBytes, 200);
|
|
}
|
|
return http.Response('not found', 404);
|
|
}),
|
|
rootDir: () async => root,
|
|
);
|
|
|
|
testWidgets('diag step marker', (tester) async {
|
|
print('=== BEFORE manager()');
|
|
final m = manager();
|
|
print('=== BEFORE refresh()');
|
|
await m.refresh();
|
|
print('=== AFTER refresh() ready=${m.ready} catalog=${m.catalog.length}');
|
|
await tester.pumpWidget(MaterialApp(
|
|
home: Scaffold(body: ModelCatalogSection(manager: m))));
|
|
print('=== AFTER pumpWidget');
|
|
for (var i = 0; i < 15; i++) {
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
final spinners = find.byType(CircularProgressIndicator).evaluate().length;
|
|
final icons = find.byIcon(Icons.image_not_supported_outlined).evaluate().length;
|
|
print('pump $i scheduled=${tester.binding.hasScheduledFrame} '
|
|
'spinner=$spinners errIcon=$icons');
|
|
}
|
|
print('=== bounded pumpAndSettle attempt');
|
|
try {
|
|
await tester.pumpAndSettle(
|
|
const Duration(milliseconds: 100),
|
|
EnginePhase.sendSemanticsUpdate,
|
|
const Duration(seconds: 5));
|
|
print('=== pumpAndSettle OK');
|
|
} catch (e) {
|
|
print('=== pumpAndSettle TIMEOUT: $e');
|
|
}
|
|
print('=== DONE');
|
|
});
|
|
}
|