fix details tap test

This commit is contained in:
sneurlax 2024-01-26 16:55:26 -06:00
parent fe819b7f92
commit 0ef372c4f9

View file

@ -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<NavigatorState>();
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 {