fix stack dialog test

This commit is contained in:
sneurlax 2024-01-26 17:42:07 -06:00
parent 6394295167
commit 9cd452fd74

View file

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mockingjay/mockingjay.dart' as mockingjay;
import 'package:stackwallet/models/isar/stack_theme.dart'; import 'package:stackwallet/models/isar/stack_theme.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/widgets/stack_dialog.dart'; import 'package:stackwallet/widgets/stack_dialog.dart';
@ -63,11 +62,13 @@ void main() {
}); });
testWidgets("Test StackDialogOk", (widgetTester) async { testWidgets("Test StackDialogOk", (widgetTester) async {
final navigator = mockingjay.MockNavigator(); final navigatorKey = GlobalKey<NavigatorState>();
await widgetTester.pumpWidget(ProviderScope( await widgetTester.pumpWidget(
ProviderScope(
overrides: [], overrides: [],
child: MaterialApp( child: MaterialApp(
navigatorKey: navigatorKey,
theme: ThemeData( theme: ThemeData(
extensions: [ extensions: [
StackColors.fromStackColorTheme( StackColors.fromStackColorTheme(
@ -77,23 +78,23 @@ void main() {
), ),
], ],
), ),
home: mockingjay.MockNavigatorProvider( home: StackOkDialog(
navigator: navigator, title: "Some random title",
child: const StackOkDialog( message: "Some message",
title: "Some random title", leftButton: TextButton(
message: "Some message", onPressed: () {},
leftButton: TextButton(onPressed: null, child: Text("I am left")), child: const Text("I am left"),
), ),
), ),
))); ),
),
);
final button = find.text('I am left');
await widgetTester.tap(button);
await widgetTester.pumpAndSettle(); await widgetTester.pumpAndSettle();
expect(find.byType(StackOkDialog), findsOneWidget); final navigatorState = navigatorKey.currentState;
expect(find.text("Some random title"), findsOneWidget); expect(navigatorState?.overlay, isNotNull);
expect(find.text("Some message"), findsOneWidget);
expect(find.byType(TextButton), findsNWidgets(2));
await widgetTester.tap(find.text("I am left"));
await widgetTester.pumpAndSettle();
}); });
} }