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, child: const Text('content'), ), ); testWidgets('slow and superseded switches retain mounted content', ( tester, ) async { await tester.pumpWidget(region(null)); final content = tester.element(find.text('content')); for (final target in ['A', 'B', null]) { await tester.pumpWidget(region(target)); await tester.pump(const Duration(seconds: 5)); expect(tester.element(find.text('content')), same(content)); expect( tester.widget(find.byType(IgnorePointer)).ignoring, target != null, ); expect( tester.widget(find.byType(ExcludeFocus)).excluding, target != null, ); expect(tester.takeException(), isNull); } }); testWidgets('disposing during preparation leaves no pending work', ( tester, ) async { await tester.pumpWidget(region('A')); await tester.pumpWidget(const SizedBox()); await tester.pump(const Duration(seconds: 5)); expect(tester.takeException(), isNull); }); }