Fix duplicate launch screen and native splash exit flashing
This commit is contained in:
@@ -5,25 +5,62 @@ 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(
|
||||
'startup shows brand while initializing and immediately proceeds when ready',
|
||||
'initialization errors still show the recovery UI on first frame',
|
||||
(tester) async {
|
||||
final ready = Completer<void>();
|
||||
await tester.pumpWidget(
|
||||
TpStartup(
|
||||
ready: ready.future,
|
||||
child: const MaterialApp(home: Scaffold(body: Text('已准备好课表'))),
|
||||
),
|
||||
final startup = launchApplication(
|
||||
ready: ready.future,
|
||||
child: const MaterialApp(home: Text('恢复保存文件')),
|
||||
);
|
||||
ready.completeError(StateError('storage failed'));
|
||||
await startup;
|
||||
await tester.pump();
|
||||
expect(find.text('TPSchedule'), findsOneWidget);
|
||||
expect(find.text('已准备好课表'), findsNothing);
|
||||
ready.complete();
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('已准备好课表'), findsOneWidget);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('TPSchedule'), findsNothing);
|
||||
expect(find.text('恢复保存文件'), findsOneWidget);
|
||||
expect(tester.binding.sendFramesToEngine, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user