From ffc1b19495c5d019f7d113bbcc3233226d4dd7d0 Mon Sep 17 00:00:00 2001 From: Likho Date: Tue, 18 Oct 2022 17:49:09 +0200 Subject: [PATCH] Progress bar widget test and clean node_options test --- .../widget_tests/node_options_sheet_test.dart | 59 +++++++++++++++++++ test/widget_tests/progress_bar_test.dart | 33 +++++++++++ 2 files changed, 92 insertions(+) create mode 100644 test/widget_tests/progress_bar_test.dart diff --git a/test/widget_tests/node_options_sheet_test.dart b/test/widget_tests/node_options_sheet_test.dart index a63e7d0ea..78800fb8a 100644 --- a/test/widget_tests/node_options_sheet_test.dart +++ b/test/widget_tests/node_options_sheet_test.dart @@ -151,4 +151,63 @@ void main() { arguments: const Tuple3(Coin.bitcoin, "node id", "coinNodes"))) .called(1); }); + + testWidgets("Connect tap", (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, + 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: [ + walletsChangeNotifierProvider.overrideWithValue(mockWallets), + prefsChangeNotifierProvider.overrideWithValue(mockPrefs), + nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService) + ], + child: MaterialApp( + theme: ThemeData( + extensions: [ + StackColors.fromStackColorTheme( + LightColors(), + ), + ], + ), + home: const NodeOptionsSheet( + nodeId: "node id", coin: Coin.bitcoin, popBackToRoute: ""), + ), + ), + ); + + await tester.pumpAndSettle(); + expect(find.text("Node options"), findsOneWidget); + // expect(find.text("Stack Default"), findsOneWidget); + expect(find.text("Disconnected"), findsOneWidget); + + await tester.tap(find.text("Connect")); + await tester.pumpAndSettle(); + }); } diff --git a/test/widget_tests/progress_bar_test.dart b/test/widget_tests/progress_bar_test.dart new file mode 100644 index 000000000..ec4d45017 --- /dev/null +++ b/test/widget_tests/progress_bar_test.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:stackwallet/utilities/theme/light_colors.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/widgets/progress_bar.dart'; +// import 'package:stackwallet/widgets/animated_text.dart'; + +void main() { + testWidgets("Widget build", (widgetTester) async { + await widgetTester.pumpWidget( + MaterialApp( + theme: ThemeData( + extensions: [ + StackColors.fromStackColorTheme(LightColors()), + ], + ), + home: Material( + child: ProgressBar( + width: 20, + height: 10, + fillColor: + StackColors.fromStackColorTheme(LightColors()).accentColorRed, + backgroundColor: StackColors.fromStackColorTheme(LightColors()) + .accentColorYellow, + percent: 30), + ), + ), + ); + + // expect(find.text("Calculating"), findsOneWidget); + expect(find.byType(ProgressBar), findsOneWidget); + }); +}