Files
TPSchedule/mobile/test/widgets/tp_startup_test.dart
T

67 lines
2.3 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hepan_everyday/app/tp_startup.dart';
void main() {
testWidgets('waiting initialization does not replace the native launch', (
tester,
) async {
await tester.pumpWidget(const SizedBox());
final ready = Completer<void>();
var startupFinished = false;
final startup = launchApplication(
ready: ready.future,
child: const MaterialApp(home: Text('已准备好课表')),
).then((_) => startupFinished = true);
await tester.pump();
expect(startupFinished, isFalse);
expect(tester.binding.sendFramesToEngine, isTrue);
expect(find.text('TPSchedule'), findsNothing);
expect(find.text('已准备好课表'), findsNothing);
ready.complete();
await startup;
await tester.pump();
expect(find.text('已准备好课表'), findsOneWidget);
expect(find.text('TPSchedule'), findsNothing);
expect(tester.binding.sendFramesToEngine, isTrue);
});
testWidgets('cached startup and resume never insert an extra launch frame', (
tester,
) async {
final ready = Future<void>.value();
await ready;
await launchApplication(
ready: ready,
child: const MaterialApp(home: Text('保存的课表')),
);
await tester.pump();
expect(find.text('保存的课表'), findsOneWidget);
expect(find.text('TPSchedule'), findsNothing);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(find.text('保存的课表'), findsOneWidget);
expect(find.text('TPSchedule'), findsNothing);
});
testWidgets(
'initialization errors still show the recovery UI on first frame',
(tester) async {
final ready = Completer<void>();
final startup = launchApplication(
ready: ready.future,
child: const MaterialApp(home: Text('恢复保存文件')),
);
ready.completeError(StateError('storage failed'));
await startup;
await tester.pump();
expect(find.text('恢复保存文件'), findsOneWidget);
expect(tester.binding.sendFramesToEngine, isTrue);
expect(tester.takeException(), isNull);
},
);
}