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/prefs.dart';
|
2024-05-15 21:39:43 +00:00
|
|
|
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
2022-10-18 14:19:18 +00:00
|
|
|
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();
|
|
|
|
|
2024-11-26 00:29:58 +00:00
|
|
|
when(mockNodeService.getNodeById(id: "node id"))
|
|
|
|
.thenAnswer((realInvocation) => NodeModel(
|
|
|
|
host: "127.0.0.1",
|
|
|
|
port: 2000,
|
|
|
|
name: "Some other name",
|
|
|
|
id: "node id",
|
|
|
|
useSSL: true,
|
|
|
|
enabled: true,
|
|
|
|
coinName: "Bitcoin",
|
|
|
|
isFailover: false,
|
|
|
|
isDown: false,
|
|
|
|
torEnabled: true,
|
|
|
|
plainEnabled: true,
|
|
|
|
));
|
2022-10-18 14:19:18 +00:00
|
|
|
|
2024-05-15 21:39:43 +00:00
|
|
|
when(mockNodeService.getPrimaryNodeFor(
|
|
|
|
currency: Bitcoin(CryptoCurrencyNetwork.main)))
|
|
|
|
.thenAnswer((realInvocation) => NodeModel(
|
2022-10-18 14:19:18 +00:00
|
|
|
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,
|
2024-11-26 00:29:58 +00:00
|
|
|
torEnabled: true,
|
|
|
|
plainEnabled: true,
|
2022-10-18 14:19:18 +00:00
|
|
|
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
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-05-15 21:39:43 +00:00
|
|
|
home: NodeOptionsSheet(
|
|
|
|
nodeId: "node id",
|
|
|
|
coin: Bitcoin(CryptoCurrencyNetwork.main),
|
|
|
|
popBackToRoute: ""),
|
2022-10-18 14:19:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-05-15 21:39:43 +00:00
|
|
|
verify(mockNodeService.getPrimaryNodeFor(
|
|
|
|
currency: Bitcoin(CryptoCurrencyNetwork.main)))
|
|
|
|
.called(1);
|
2022-10-18 14:19:18 +00:00
|
|
|
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,
|
2024-11-26 00:29:58 +00:00
|
|
|
torEnabled: true,
|
|
|
|
plainEnabled: true,
|
2024-01-26 22:55:26 +00:00
|
|
|
),
|
|
|
|
);
|
2022-10-18 14:19:18 +00:00
|
|
|
|
2024-05-15 21:39:43 +00:00
|
|
|
when(mockNodeService.getPrimaryNodeFor(
|
|
|
|
currency: Bitcoin(CryptoCurrencyNetwork.main)))
|
|
|
|
.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,
|
2024-11-26 00:29:58 +00:00
|
|
|
torEnabled: true,
|
|
|
|
plainEnabled: true,
|
2024-01-26 22:55:26 +00:00
|
|
|
),
|
|
|
|
);
|
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;
|
|
|
|
},
|
2024-05-15 21:39:43 +00:00
|
|
|
home: NodeOptionsSheet(
|
2024-01-26 22:55:26 +00:00
|
|
|
nodeId: "node id",
|
2024-05-15 21:39:43 +00:00
|
|
|
coin: Bitcoin(CryptoCurrencyNetwork.main),
|
2024-01-26 22:55:26 +00:00
|
|
|
popBackToRoute: "coinNodes",
|
|
|
|
),
|
2022-10-18 14:19:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.tap(find.text("Details"));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
2024-05-27 23:56:22 +00:00
|
|
|
final currentRoute = navigatorKey.currentState?.overlay?.context;
|
2024-01-26 22:55:26 +00:00
|
|
|
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(
|
2024-01-26 22:57:16 +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,
|
2024-11-26 00:29:58 +00:00
|
|
|
torEnabled: true,
|
|
|
|
plainEnabled: true,
|
2024-01-26 22:57:16 +00:00
|
|
|
),
|
|
|
|
);
|
2022-10-18 15:49:09 +00:00
|
|
|
|
2024-05-15 21:39:43 +00:00
|
|
|
when(mockNodeService.getPrimaryNodeFor(
|
|
|
|
currency: Bitcoin(CryptoCurrencyNetwork.main)))
|
|
|
|
.thenAnswer(
|
2024-01-26 22:57:16 +00:00
|
|
|
(_) => 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,
|
2024-11-26 00:29:58 +00:00
|
|
|
torEnabled: true,
|
|
|
|
plainEnabled: true,
|
2024-01-26 22:57:16 +00:00
|
|
|
),
|
|
|
|
);
|
2022-10-18 15:49:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-05-15 21:39:43 +00:00
|
|
|
home: NodeOptionsSheet(
|
2024-01-26 22:57:16 +00:00
|
|
|
nodeId: "node id",
|
2024-05-15 21:39:43 +00:00
|
|
|
coin: Bitcoin(CryptoCurrencyNetwork.main),
|
2024-01-26 22:57:16 +00:00
|
|
|
popBackToRoute: "",
|
|
|
|
),
|
2022-10-18 15:49:09 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
}
|