2022-10-18 14:19:18 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-08 17:59:00 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-10-18 14:19:18 +00:00
|
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:mockito/annotations.dart';
|
|
|
|
import 'package:mockito/mockito.dart';
|
2023-05-12 20:02:04 +00:00
|
|
|
import 'package:stackwallet/models/isar/stack_theme.dart';
|
2022-10-18 14:19:18 +00:00
|
|
|
import 'package:stackwallet/models/node_model.dart';
|
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
2023-05-08 17:59:00 +00:00
|
|
|
import 'package:stackwallet/services/node_service.dart';
|
2023-09-08 16:04:56 +00:00
|
|
|
import 'package:stackwallet/services/tor_service.dart';
|
2022-10-18 14:19:18 +00:00
|
|
|
import 'package:stackwallet/services/wallets.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2022-10-18 14:19:18 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
|
|
|
import 'package:stackwallet/widgets/node_options_sheet.dart';
|
|
|
|
|
2023-05-12 20:02:04 +00:00
|
|
|
import '../sample_data/theme_json.dart';
|
2022-10-18 14:19:18 +00:00
|
|
|
import 'node_options_sheet_test.mocks.dart';
|
|
|
|
|
2023-09-08 16:04:56 +00:00
|
|
|
@GenerateMocks([Wallets, Prefs, NodeService, TorService])
|
2022-10-18 14:19:18 +00:00
|
|
|
void main() {
|
|
|
|
testWidgets("Load Node Options widget", (tester) async {
|
|
|
|
final mockWallets = MockWallets();
|
|
|
|
final mockPrefs = MockPrefs();
|
|
|
|
final mockNodeService = MockNodeService();
|
|
|
|
|
|
|
|
when(mockNodeService.getNodeById(id: "node id")).thenAnswer(
|
|
|
|
(realInvocation) => NodeModel(
|
|
|
|
host: "127.0.0.1",
|
|
|
|
port: 2000,
|
2022-10-19 13:18:05 +00:00
|
|
|
name: "Some other name",
|
2022-10-18 14:19:18 +00:00
|
|
|
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,
|
2022-10-19 13:18:05 +00:00
|
|
|
name: "Some other name",
|
2022-10-18 14:19:18 +00:00
|
|
|
id: "node id",
|
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
|
|
|
coinName: "Bitcoin",
|
|
|
|
isFailover: false,
|
|
|
|
isDown: false));
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [
|
2023-10-31 17:15:59 +00:00
|
|
|
pWallets.overrideWithValue(mockWallets),
|
2022-10-18 14:19:18 +00:00
|
|
|
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
|
|
|
|
nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService)
|
|
|
|
],
|
|
|
|
child: MaterialApp(
|
|
|
|
theme: ThemeData(
|
|
|
|
extensions: [
|
|
|
|
StackColors.fromStackColorTheme(
|
2023-05-08 17:59:00 +00:00
|
|
|
StackTheme.fromJson(
|
2023-05-12 20:02:04 +00:00
|
|
|
json: lightThemeJsonMap,
|
2023-05-08 17:59:00 +00:00
|
|
|
),
|
2022-10-18 14:19:18 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
home: const NodeOptionsSheet(
|
|
|
|
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text("Node options"), findsOneWidget);
|
2022-10-19 13:18:05 +00:00
|
|
|
expect(find.text("Some other name"), findsOneWidget);
|
2022-10-18 14:19:18 +00:00
|
|
|
expect(find.text("Connected"), findsOneWidget);
|
|
|
|
expect(find.byType(SvgPicture), findsNWidgets(2));
|
|
|
|
expect(find.text("Details"), findsOneWidget);
|
|
|
|
expect(find.text("Connect"), findsOneWidget);
|
|
|
|
|
|
|
|
verify(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).called(1);
|
|
|
|
verify(mockNodeService.getNodeById(id: "node id")).called(1);
|
|
|
|
verify(mockNodeService.addListener(any)).called(1);
|
|
|
|
verifyNoMoreInteractions(mockNodeService);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets("Details tap", (tester) async {
|
2024-01-26 22:55:26 +00:00
|
|
|
final navigatorKey = GlobalKey<NavigatorState>();
|
2022-10-18 14:19:18 +00:00
|
|
|
final mockWallets = MockWallets();
|
|
|
|
final mockPrefs = MockPrefs();
|
|
|
|
final mockNodeService = MockNodeService();
|
2024-01-26 22:55:26 +00:00
|
|
|
final mockTorService = MockTorService();
|
2022-10-18 14:19:18 +00:00
|
|
|
|
|
|
|
when(mockNodeService.getNodeById(id: "node id")).thenAnswer(
|
2024-01-26 22:55:26 +00:00
|
|
|
(_) => NodeModel(
|
|
|
|
host: "127.0.0.1",
|
|
|
|
port: 2000,
|
|
|
|
name: "Stack Default",
|
|
|
|
id: "node id",
|
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
|
|
|
coinName: "Bitcoin",
|
|
|
|
isFailover: false,
|
|
|
|
isDown: false,
|
|
|
|
),
|
|
|
|
);
|
2022-10-18 14:19:18 +00:00
|
|
|
|
|
|
|
when(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer(
|
2024-01-26 22:55:26 +00:00
|
|
|
(_) => 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,
|
|
|
|
),
|
|
|
|
);
|
2022-10-18 14:19:18 +00:00
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [
|
2023-10-31 17:15:59 +00:00
|
|
|
pWallets.overrideWithValue(mockWallets),
|
2022-10-18 14:19:18 +00:00
|
|
|
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
|
2024-01-26 22:55:26 +00:00
|
|
|
nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService),
|
|
|
|
pTorService.overrideWithValue(mockTorService),
|
2022-10-18 14:19:18 +00:00
|
|
|
],
|
|
|
|
child: MaterialApp(
|
2024-01-26 22:55:26 +00:00
|
|
|
navigatorKey: navigatorKey,
|
2022-10-18 14:19:18 +00:00
|
|
|
theme: ThemeData(
|
|
|
|
extensions: [
|
2023-05-08 17:59:00 +00:00
|
|
|
StackColors.fromStackColorTheme(
|
|
|
|
StackTheme.fromJson(
|
2023-05-12 20:02:04 +00:00
|
|
|
json: lightThemeJsonMap,
|
2023-05-08 17:59:00 +00:00
|
|
|
),
|
|
|
|
),
|
2022-10-18 14:19:18 +00:00
|
|
|
],
|
|
|
|
),
|
2024-01-26 22:55:26 +00:00
|
|
|
onGenerateRoute: (settings) {
|
|
|
|
if (settings.name == '/nodeDetails') {
|
|
|
|
return MaterialPageRoute(builder: (_) => Scaffold());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
home: const NodeOptionsSheet(
|
|
|
|
nodeId: "node id",
|
|
|
|
coin: Coin.bitcoin,
|
|
|
|
popBackToRoute: "coinNodes",
|
|
|
|
),
|
2022-10-18 14:19:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.tap(find.text("Details"));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
2024-01-26 22:55:26 +00:00
|
|
|
var currentRoute = navigatorKey.currentState?.overlay?.context;
|
|
|
|
expect(currentRoute, isNotNull);
|
2022-10-18 14:19:18 +00:00
|
|
|
});
|
2022-10-18 15:49:09 +00:00
|
|
|
|
|
|
|
testWidgets("Connect tap", (tester) async {
|
|
|
|
final mockWallets = MockWallets();
|
|
|
|
final mockPrefs = MockPrefs();
|
|
|
|
final mockNodeService = MockNodeService();
|
2023-09-08 16:04:56 +00:00
|
|
|
final mockTorService = MockTorService();
|
2022-10-18 15:49:09 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
when(mockNodeService.getPrimaryNodeFor(coin: Coin.bitcoin)).thenAnswer(
|
|
|
|
(realInvocation) => NodeModel(
|
|
|
|
host: "127.0.0.1",
|
|
|
|
port: 2000,
|
|
|
|
name: "Some other node name",
|
|
|
|
id: "some node id",
|
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
|
|
|
coinName: "Bitcoin",
|
|
|
|
isFailover: false,
|
|
|
|
isDown: false));
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [
|
2023-10-31 17:15:59 +00:00
|
|
|
pWallets.overrideWithValue(mockWallets),
|
2022-10-18 15:49:09 +00:00
|
|
|
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
|
2023-09-08 16:04:56 +00:00
|
|
|
nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService),
|
|
|
|
pTorService.overrideWithValue(mockTorService),
|
2022-10-18 15:49:09 +00:00
|
|
|
],
|
|
|
|
child: MaterialApp(
|
|
|
|
theme: ThemeData(
|
|
|
|
extensions: [
|
|
|
|
StackColors.fromStackColorTheme(
|
2023-05-08 17:59:00 +00:00
|
|
|
StackTheme.fromJson(
|
2023-05-12 20:02:04 +00:00
|
|
|
json: lightThemeJsonMap,
|
2023-05-08 17:59:00 +00:00
|
|
|
),
|
2022-10-18 15:49:09 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
home: const NodeOptionsSheet(
|
|
|
|
nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text("Node options"), findsOneWidget);
|
|
|
|
expect(find.text("Disconnected"), findsOneWidget);
|
|
|
|
|
|
|
|
await tester.tap(find.text("Connect"));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
});
|
2022-10-18 14:19:18 +00:00
|
|
|
}
|