Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll committed Jul 14, 2023
1 parent 403cfd3 commit 373e6cc
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions packages/devtools_app/test/shared/initializer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:mockito/mockito.dart';

void main() {
group('Initializer', () {
late MaterialApp app;
const Key initializedKey = Key('initialized');
setUp(() {
final serviceManager = FakeServiceManager();
Expand All @@ -22,17 +21,20 @@ void main() {
setGlobal(ServiceConnectionManager, serviceManager);
setGlobal(FrameworkController, FrameworkController());
setGlobal(OfflineModeController, OfflineModeController());
setGlobal(IdeTheme, IdeTheme());
});

app = MaterialApp(
initialRoute: '/init',
routes: {
'/init': (_) => Initializer(
url: null,
builder: (_) => const SizedBox(key: initializedKey),
),
},
Future<void> pumpInitializer(WidgetTester tester) async {
await tester.pumpWidget(
wrap(
Initializer(
url: null,
builder: (_) => const SizedBox(key: initializedKey),
),
),
);
});
await tester.pumpAndSettle();
}

testWidgets(
'shows disconnected overlay if not connected',
Expand All @@ -43,8 +45,7 @@ void main() {
hasConnection: false,
),
);

await tester.pumpFrames(app, const Duration(milliseconds: 100));
await pumpInitializer(tester);
expect(find.text('Disconnected'), findsOneWidget);
},
);
Expand All @@ -56,15 +57,16 @@ void main() {
setGlobal(ServiceConnectionManager, serviceManager);

// Expect standard connected state.
await tester.pumpFrames(app, const Duration(milliseconds: 100));
serviceManager.changeState(true);
await pumpInitializer(tester);
expect(find.byKey(initializedKey), findsOneWidget);
expect(find.text('Disconnected'), findsNothing);

// Trigger a disconnect.
serviceManager.changeState(false);
await tester.pumpAndSettle(const Duration(microseconds: 1000));

// Expect Disconnected overlay.
await tester.pumpFrames(app, const Duration(milliseconds: 100));
expect(find.text('Disconnected'), findsOneWidget);
},
);
Expand All @@ -75,28 +77,23 @@ void main() {
final serviceManager = FakeServiceManager();
setGlobal(ServiceConnectionManager, serviceManager);

// Expect standard connected state.
serviceManager.changeState(true);
await pumpInitializer(tester);
expect(find.byKey(initializedKey), findsOneWidget);
expect(find.text('Disconnected'), findsNothing);

// Trigger a disconnect and ensure the overlay appears.
await tester.pumpFrames(app, const Duration(milliseconds: 100));
serviceManager.changeState(false);
await tester.pumpFrames(app, const Duration(milliseconds: 100));
await tester.pumpAndSettle();
expect(find.text('Disconnected'), findsOneWidget);

// Trigger a reconnect
serviceManager.changeState(true);
await tester.pumpAndSettle();

// Expect no overlay.
await tester.pumpFrames(app, const Duration(milliseconds: 100));
expect(find.text('Disconnected'), findsNothing);
},
);

testWidgets(
'builds contents when initialized',
(WidgetTester tester) async {
await tester.pumpWidget(app);
await tester.pumpAndSettle();
expect(find.text('Disconnected'), findsNothing);
expect(find.byKey(initializedKey), findsOneWidget);
},
);
});
Expand Down

0 comments on commit 373e6cc

Please sign in to comment.