From 0ef372c4f9731c7d9d83d36d59ff0d9d00d22efd Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 26 Jan 2024 16:55:26 -0600 Subject: [PATCH] fix details tap test --- .../widget_tests/node_options_sheet_test.dart | 82 ++++++++++--------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/test/widget_tests/node_options_sheet_test.dart b/test/widget_tests/node_options_sheet_test.dart index f1e4ce8bd..0b6bfa30a 100644 --- a/test/widget_tests/node_options_sheet_test.dart +++ b/test/widget_tests/node_options_sheet_test.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mockingjay/mockingjay.dart' as mockingjay; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:stackwallet/models/isar/stack_theme.dart'; @@ -15,7 +14,6 @@ import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/widgets/node_options_sheet.dart'; -import 'package:tuple/tuple.dart'; import '../sample_data/theme_json.dart'; import 'node_options_sheet_test.mocks.dart'; @@ -89,48 +87,50 @@ void main() { }); testWidgets("Details tap", (tester) async { + final navigatorKey = GlobalKey(); final mockWallets = MockWallets(); final mockPrefs = MockPrefs(); final mockNodeService = MockNodeService(); - final navigator = mockingjay.MockNavigator(); + final mockTorService = MockTorService(); when(mockNodeService.getNodeById(id: "node id")).thenAnswer( - (realInvocation) => NodeModel( - host: "127.0.0.1", - port: 2000, - name: "Stack Default", - id: "node id", - useSSL: true, - enabled: true, - coinName: "Bitcoin", - isFailover: false, - isDown: false)); + (_) => NodeModel( + host: "127.0.0.1", + port: 2000, + name: "Stack Default", + id: "node id", + useSSL: true, + enabled: true, + coinName: "Bitcoin", + isFailover: false, + isDown: false, + ), + ); when(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer( - (realInvocation) => NodeModel( - host: "127.0.0.1", - port: 2000, - name: "Stack Default", - id: "node id", - useSSL: true, - enabled: true, - coinName: "Bitcoin", - isFailover: false, - isDown: false)); - - mockingjay - .when(() => navigator.pushNamed("/nodeDetails", - arguments: const Tuple3(Coin.bitcoin, "node id", "coinNodes"))) - .thenAnswer((_) async => {}); + (_) => NodeModel( + host: "127.0.0.1", + port: 2000, + name: "Stack Default", + id: "some node id", + useSSL: true, + enabled: true, + coinName: "Bitcoin", + isFailover: false, + isDown: false, + ), + ); await tester.pumpWidget( ProviderScope( overrides: [ pWallets.overrideWithValue(mockWallets), prefsChangeNotifierProvider.overrideWithValue(mockPrefs), - nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService) + nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService), + pTorService.overrideWithValue(mockTorService), ], child: MaterialApp( + navigatorKey: navigatorKey, theme: ThemeData( extensions: [ StackColors.fromStackColorTheme( @@ -140,12 +140,17 @@ void main() { ), ], ), - home: mockingjay.MockNavigatorProvider( - navigator: navigator, - child: const NodeOptionsSheet( - nodeId: "node id", - coin: Coin.bitcoin, - popBackToRoute: "coinNodes")), + onGenerateRoute: (settings) { + if (settings.name == '/nodeDetails') { + return MaterialPageRoute(builder: (_) => Scaffold()); + } + return null; + }, + home: const NodeOptionsSheet( + nodeId: "node id", + coin: Coin.bitcoin, + popBackToRoute: "coinNodes", + ), ), ), ); @@ -153,11 +158,8 @@ void main() { await tester.tap(find.text("Details")); await tester.pumpAndSettle(); - mockingjay.verify(() => navigator.pop()).called(1); - mockingjay - .verify(() => navigator.pushNamed("/nodeDetails", - arguments: const Tuple3(Coin.bitcoin, "node id", "coinNodes"))) - .called(1); + var currentRoute = navigatorKey.currentState?.overlay?.context; + expect(currentRoute, isNotNull); }); testWidgets("Connect tap", (tester) async {