62 lines
2.1 KiB
Dart
62 lines
2.1 KiB
Dart
import 'package:cutdex/features/projects/project_switch_region.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
Widget region(String? pending) => Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: ProjectSwitchRegion(
|
|
pendingProjectId: pending,
|
|
builder: (context, showDefaults) =>
|
|
Text(showDefaults ? 'defaults' : 'content'),
|
|
),
|
|
);
|
|
|
|
testWidgets(
|
|
'fast completion never displays defaults or waits for the timer',
|
|
(tester) async {
|
|
await tester.pumpWidget(region('A'));
|
|
expect(find.text('content'), findsOneWidget);
|
|
expect(
|
|
tester.widget<IgnorePointer>(find.byType(IgnorePointer)).ignoring,
|
|
isTrue,
|
|
);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
await tester.pumpWidget(region(null));
|
|
expect(find.text('defaults'), findsNothing);
|
|
expect(
|
|
tester.widget<IgnorePointer>(find.byType(IgnorePointer)).ignoring,
|
|
isFalse,
|
|
);
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
expect(find.text('defaults'), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'slow switches show defaults after 150ms and reset on a new target',
|
|
(tester) async {
|
|
await tester.pumpWidget(region('A'));
|
|
await tester.pump(const Duration(milliseconds: 149));
|
|
expect(find.text('defaults'), findsNothing);
|
|
await tester.pump(const Duration(milliseconds: 1));
|
|
expect(find.text('defaults'), findsOneWidget);
|
|
await tester.pumpWidget(region('B'));
|
|
expect(find.text('defaults'), findsNothing);
|
|
await tester.pump(const Duration(milliseconds: 150));
|
|
expect(find.text('defaults'), findsOneWidget);
|
|
await tester.pumpWidget(region(null));
|
|
expect(find.text('content'), findsOneWidget);
|
|
},
|
|
);
|
|
|
|
testWidgets('disposing during a switch cancels the pending timer', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(region('A'));
|
|
await tester.pumpWidget(const SizedBox());
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|