From efc5582fb23521df199f2f647007359f58a6e718 Mon Sep 17 00:00:00 2001 From: Likho Date: Fri, 7 Oct 2022 10:34:30 +0200 Subject: [PATCH] WIP: Widget testing --- lib/route_generator.dart | 10 +- .../bitcoincash_wallet_test.mocks.dart | 444 +++++++++--------- test/widget_tests/address_book_card_test.dart | 54 +++ .../address_book_card_test.mocks.dart | 87 ++++ test/widget_tests/wallet_info_row_test.dart | 57 +++ .../wallet_info_row_test.mocks.dart | 393 ++++++++++++++++ 6 files changed, 820 insertions(+), 225 deletions(-) create mode 100644 test/widget_tests/address_book_card_test.dart create mode 100644 test/widget_tests/address_book_card_test.mocks.dart create mode 100644 test/widget_tests/wallet_info_row_test.dart create mode 100644 test/widget_tests/wallet_info_row_test.mocks.dart diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 121aca797..643b8cecf 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -929,11 +929,11 @@ class RouteGenerator { builder: (_) => const DesktopHomeView(), settings: RouteSettings(name: settings.name)); - case DesktopSettingsView.routeName: - return getRoute( - shouldUseMaterialRoute: useMaterialPageRoute, - builder: (_) => const DesktopSettingsView(), - settings: RouteSettings(name: settings.name)); + // case DesktopSettingsView.routeName: + // return getRoute( + // shouldUseMaterialRoute: useMaterialPageRoute, + // builder: (_) => const DesktopSettingsView(), + // settings: RouteSettings(name: settings.name)); case MyStackView.routeName: return getRoute( diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart index fa38e1f9e..f24f8be4c 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart @@ -2,18 +2,18 @@ // in stackwallet/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart. // Do not manually edit this file. -import 'dart:async' as _i7; +import 'dart:async' as _i6; -import 'package:decimal/decimal.dart' as _i4; -import 'package:http/http.dart' as _i3; +import 'package:decimal/decimal.dart' as _i2; +import 'package:http/http.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart' as _i5; -import 'package:stackwallet/electrumx_rpc/electrumx.dart' as _i6; +import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart' as _i7; +import 'package:stackwallet/electrumx_rpc/electrumx.dart' as _i5; import 'package:stackwallet/services/price.dart' as _i9; import 'package:stackwallet/services/transaction_notification_tracker.dart' as _i11; import 'package:stackwallet/utilities/enums/coin_enum.dart' as _i8; -import 'package:stackwallet/utilities/prefs.dart' as _i2; +import 'package:stackwallet/utilities/prefs.dart' as _i3; import 'package:tuple/tuple.dart' as _i10; // ignore_for_file: type=lint @@ -26,16 +26,208 @@ import 'package:tuple/tuple.dart' as _i10; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types -class _FakePrefs_0 extends _i1.Fake implements _i2.Prefs {} +class _FakeDecimal_0 extends _i1.Fake implements _i2.Decimal {} -class _FakeClient_1 extends _i1.Fake implements _i3.Client {} +class _FakePrefs_1 extends _i1.Fake implements _i3.Prefs {} -class _FakeDecimal_2 extends _i1.Fake implements _i4.Decimal {} +class _FakeClient_2 extends _i1.Fake implements _i4.Client {} + +/// A class which mocks [ElectrumX]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockElectrumX extends _i1.Mock implements _i5.ElectrumX { + MockElectrumX() { + _i1.throwOnMissingStub(this); + } + + @override + set failovers(List<_i5.ElectrumXNode>? _failovers) => + super.noSuchMethod(Invocation.setter(#failovers, _failovers), + returnValueForMissingStub: null); + @override + int get currentFailoverIndex => + (super.noSuchMethod(Invocation.getter(#currentFailoverIndex), + returnValue: 0) as int); + @override + set currentFailoverIndex(int? _currentFailoverIndex) => super.noSuchMethod( + Invocation.setter(#currentFailoverIndex, _currentFailoverIndex), + returnValueForMissingStub: null); + @override + String get host => + (super.noSuchMethod(Invocation.getter(#host), returnValue: '') as String); + @override + int get port => + (super.noSuchMethod(Invocation.getter(#port), returnValue: 0) as int); + @override + bool get useSSL => + (super.noSuchMethod(Invocation.getter(#useSSL), returnValue: false) + as bool); + @override + _i6.Future request( + {String? command, + List? args = const [], + Duration? connectionTimeout = const Duration(seconds: 60), + String? requestID, + int? retries = 2}) => + (super.noSuchMethod( + Invocation.method(#request, [], { + #command: command, + #args: args, + #connectionTimeout: connectionTimeout, + #requestID: requestID, + #retries: retries + }), + returnValue: Future.value()) as _i6.Future); + @override + _i6.Future>> batchRequest( + {String? command, + Map>? args, + Duration? connectionTimeout = const Duration(seconds: 60), + int? retries = 2}) => + (super.noSuchMethod( + Invocation.method(#batchRequest, [], { + #command: command, + #args: args, + #connectionTimeout: connectionTimeout, + #retries: retries + }), + returnValue: Future>>.value( + >[])) + as _i6.Future>>); + @override + _i6.Future ping({String? requestID, int? retryCount = 1}) => + (super.noSuchMethod( + Invocation.method( + #ping, [], {#requestID: requestID, #retryCount: retryCount}), + returnValue: Future.value(false)) as _i6.Future); + @override + _i6.Future> getBlockHeadTip({String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getBlockHeadTip, [], {#requestID: requestID}), + returnValue: + Future>.value({})) + as _i6.Future>); + @override + _i6.Future> getServerFeatures({String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getServerFeatures, [], {#requestID: requestID}), + returnValue: + Future>.value({})) as _i6 + .Future>); + @override + _i6.Future broadcastTransaction({String? rawTx, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#broadcastTransaction, [], + {#rawTx: rawTx, #requestID: requestID}), + returnValue: Future.value('')) as _i6.Future); + @override + _i6.Future> getBalance( + {String? scripthash, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getBalance, [], + {#scripthash: scripthash, #requestID: requestID}), + returnValue: + Future>.value({})) + as _i6.Future>); + @override + _i6.Future>> getHistory( + {String? scripthash, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getHistory, [], + {#scripthash: scripthash, #requestID: requestID}), + returnValue: Future>>.value( + >[])) + as _i6.Future>>); + @override + _i6.Future>>> getBatchHistory( + {Map>? args}) => + (super.noSuchMethod( + Invocation.method(#getBatchHistory, [], {#args: args}), + returnValue: Future>>>.value( + >>{})) as _i6 + .Future>>>); + @override + _i6.Future>> getUTXOs( + {String? scripthash, String? requestID}) => + (super.noSuchMethod( + Invocation.method( + #getUTXOs, [], {#scripthash: scripthash, #requestID: requestID}), + returnValue: Future>>.value( + >[])) as _i6 + .Future>>); + @override + _i6.Future>>> getBatchUTXOs( + {Map>? args}) => + (super.noSuchMethod(Invocation.method(#getBatchUTXOs, [], {#args: args}), + returnValue: Future>>>.value( + >>{})) as _i6 + .Future>>>); + @override + _i6.Future> getTransaction( + {String? txHash, bool? verbose = true, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getTransaction, [], + {#txHash: txHash, #verbose: verbose, #requestID: requestID}), + returnValue: + Future>.value({})) + as _i6.Future>); + @override + _i6.Future> getAnonymitySet( + {String? groupId = r'1', + String? blockhash = r'', + String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getAnonymitySet, [], { + #groupId: groupId, + #blockhash: blockhash, + #requestID: requestID + }), + returnValue: + Future>.value({})) + as _i6.Future>); + @override + _i6.Future getMintData({dynamic mints, String? requestID}) => + (super.noSuchMethod( + Invocation.method( + #getMintData, [], {#mints: mints, #requestID: requestID}), + returnValue: Future.value()) as _i6.Future); + @override + _i6.Future> getUsedCoinSerials( + {String? requestID, int? startNumber}) => + (super.noSuchMethod( + Invocation.method(#getUsedCoinSerials, [], + {#requestID: requestID, #startNumber: startNumber}), + returnValue: + Future>.value({})) + as _i6.Future>); + @override + _i6.Future getLatestCoinId({String? requestID}) => (super.noSuchMethod( + Invocation.method(#getLatestCoinId, [], {#requestID: requestID}), + returnValue: Future.value(0)) as _i6.Future); + @override + _i6.Future> getFeeRate({String? requestID}) => (super + .noSuchMethod(Invocation.method(#getFeeRate, [], {#requestID: requestID}), + returnValue: + Future>.value({})) as _i6 + .Future>); + @override + _i6.Future<_i2.Decimal> estimateFee({String? requestID, int? blocks}) => + (super.noSuchMethod( + Invocation.method( + #estimateFee, [], {#requestID: requestID, #blocks: blocks}), + returnValue: Future<_i2.Decimal>.value(_FakeDecimal_0())) + as _i6.Future<_i2.Decimal>); + @override + _i6.Future<_i2.Decimal> relayFee({String? requestID}) => (super.noSuchMethod( + Invocation.method(#relayFee, [], {#requestID: requestID}), + returnValue: Future<_i2.Decimal>.value(_FakeDecimal_0())) + as _i6.Future<_i2.Decimal>); +} /// A class which mocks [CachedElectrumX]. /// /// See the documentation for Mockito's code generation for more information. -class MockCachedElectrumX extends _i1.Mock implements _i5.CachedElectrumX { +class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX { MockCachedElectrumX() { _i1.throwOnMissingStub(this); } @@ -52,44 +244,44 @@ class MockCachedElectrumX extends _i1.Mock implements _i5.CachedElectrumX { (super.noSuchMethod(Invocation.getter(#useSSL), returnValue: false) as bool); @override - _i2.Prefs get prefs => (super.noSuchMethod(Invocation.getter(#prefs), - returnValue: _FakePrefs_0()) as _i2.Prefs); + _i3.Prefs get prefs => (super.noSuchMethod(Invocation.getter(#prefs), + returnValue: _FakePrefs_1()) as _i3.Prefs); @override - List<_i6.ElectrumXNode> get failovers => + List<_i5.ElectrumXNode> get failovers => (super.noSuchMethod(Invocation.getter(#failovers), - returnValue: <_i6.ElectrumXNode>[]) as List<_i6.ElectrumXNode>); + returnValue: <_i5.ElectrumXNode>[]) as List<_i5.ElectrumXNode>); @override - _i7.Future> getAnonymitySet( + _i6.Future> getAnonymitySet( {String? groupId, String? blockhash = r'', _i8.Coin? coin}) => (super.noSuchMethod( Invocation.method(#getAnonymitySet, [], {#groupId: groupId, #blockhash: blockhash, #coin: coin}), returnValue: Future>.value({})) - as _i7.Future>); + as _i6.Future>); @override - _i7.Future> getTransaction( + _i6.Future> getTransaction( {String? txHash, _i8.Coin? coin, bool? verbose = true}) => (super.noSuchMethod( Invocation.method(#getTransaction, [], {#txHash: txHash, #coin: coin, #verbose: verbose}), returnValue: Future>.value({})) - as _i7.Future>); + as _i6.Future>); @override - _i7.Future> getUsedCoinSerials( + _i6.Future> getUsedCoinSerials( {_i8.Coin? coin, int? startNumber = 0}) => (super.noSuchMethod( Invocation.method(#getUsedCoinSerials, [], {#coin: coin, #startNumber: startNumber}), returnValue: Future>.value([])) - as _i7.Future>); + as _i6.Future>); @override - _i7.Future clearSharedTransactionCache({_i8.Coin? coin}) => + _i6.Future clearSharedTransactionCache({_i8.Coin? coin}) => (super.noSuchMethod( Invocation.method(#clearSharedTransactionCache, [], {#coin: coin}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i7.Future); + returnValueForMissingStub: Future.value()) as _i6.Future); } /// A class which mocks [PriceAPI]. @@ -101,21 +293,21 @@ class MockPriceAPI extends _i1.Mock implements _i9.PriceAPI { } @override - _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), - returnValue: _FakeClient_1()) as _i3.Client); + _i4.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_2()) as _i4.Client); @override void resetLastCalledToForceNextCallToUpdateCache() => super.noSuchMethod( Invocation.method(#resetLastCalledToForceNextCallToUpdateCache, []), returnValueForMissingStub: null); @override - _i7.Future>> + _i6.Future>> getPricesAnd24hChange({String? baseCurrency}) => (super.noSuchMethod( Invocation.method( #getPricesAnd24hChange, [], {#baseCurrency: baseCurrency}), returnValue: - Future>>.value( - <_i8.Coin, _i10.Tuple2<_i4.Decimal, double>>{})) - as _i7.Future>>); + Future>>.value( + <_i8.Coin, _i10.Tuple2<_i2.Decimal, double>>{})) + as _i6.Future>>); } /// A class which mocks [TransactionNotificationTracker]. @@ -144,205 +336,17 @@ class MockTransactionNotificationTracker extends _i1.Mock (super.noSuchMethod(Invocation.method(#wasNotifiedPending, [txid]), returnValue: false) as bool); @override - _i7.Future addNotifiedPending(String? txid) => + _i6.Future addNotifiedPending(String? txid) => (super.noSuchMethod(Invocation.method(#addNotifiedPending, [txid]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i7.Future); + returnValueForMissingStub: Future.value()) as _i6.Future); @override bool wasNotifiedConfirmed(String? txid) => (super.noSuchMethod(Invocation.method(#wasNotifiedConfirmed, [txid]), returnValue: false) as bool); @override - _i7.Future addNotifiedConfirmed(String? txid) => + _i6.Future addNotifiedConfirmed(String? txid) => (super.noSuchMethod(Invocation.method(#addNotifiedConfirmed, [txid]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i7.Future); -} - -/// A class which mocks [ElectrumX]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockElectrumX extends _i1.Mock implements _i6.ElectrumX { - @override - set failovers(List<_i6.ElectrumXNode>? _failovers) => - super.noSuchMethod(Invocation.setter(#failovers, _failovers), - returnValueForMissingStub: null); - @override - int get currentFailoverIndex => - (super.noSuchMethod(Invocation.getter(#currentFailoverIndex), - returnValue: 0) as int); - @override - set currentFailoverIndex(int? _currentFailoverIndex) => super.noSuchMethod( - Invocation.setter(#currentFailoverIndex, _currentFailoverIndex), - returnValueForMissingStub: null); - @override - String get host => - (super.noSuchMethod(Invocation.getter(#host), returnValue: '') as String); - @override - int get port => - (super.noSuchMethod(Invocation.getter(#port), returnValue: 0) as int); - @override - bool get useSSL => - (super.noSuchMethod(Invocation.getter(#useSSL), returnValue: false) - as bool); - @override - _i7.Future request( - {String? command, - List? args = const [], - Duration? connectionTimeout = const Duration(seconds: 60), - String? requestID, - int? retries = 2}) => - (super.noSuchMethod( - Invocation.method(#request, [], { - #command: command, - #args: args, - #connectionTimeout: connectionTimeout, - #requestID: requestID, - #retries: retries - }), - returnValue: Future.value()) as _i7.Future); - @override - _i7.Future>> batchRequest( - {String? command, - Map>? args, - Duration? connectionTimeout = const Duration(seconds: 60), - int? retries = 2}) => - (super.noSuchMethod( - Invocation.method(#batchRequest, [], { - #command: command, - #args: args, - #connectionTimeout: connectionTimeout, - #retries: retries - }), - returnValue: Future>>.value( - >[])) - as _i7.Future>>); - @override - _i7.Future ping({String? requestID, int? retryCount = 1}) => - (super.noSuchMethod( - Invocation.method( - #ping, [], {#requestID: requestID, #retryCount: retryCount}), - returnValue: Future.value(false)) as _i7.Future); - @override - _i7.Future> getBlockHeadTip({String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getBlockHeadTip, [], {#requestID: requestID}), - returnValue: - Future>.value({})) - as _i7.Future>); - @override - _i7.Future> getServerFeatures({String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getServerFeatures, [], {#requestID: requestID}), - returnValue: - Future>.value({})) as _i7 - .Future>); - @override - _i7.Future broadcastTransaction({String? rawTx, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#broadcastTransaction, [], - {#rawTx: rawTx, #requestID: requestID}), - returnValue: Future.value('')) as _i7.Future); - @override - _i7.Future> getBalance( - {String? scripthash, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getBalance, [], - {#scripthash: scripthash, #requestID: requestID}), - returnValue: - Future>.value({})) - as _i7.Future>); - @override - _i7.Future>> getHistory( - {String? scripthash, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getHistory, [], - {#scripthash: scripthash, #requestID: requestID}), - returnValue: Future>>.value( - >[])) - as _i7.Future>>); - @override - _i7.Future>>> getBatchHistory( - {Map>? args}) => - (super.noSuchMethod( - Invocation.method(#getBatchHistory, [], {#args: args}), - returnValue: Future>>>.value( - >>{})) as _i7 - .Future>>>); - @override - _i7.Future>> getUTXOs( - {String? scripthash, String? requestID}) => - (super.noSuchMethod( - Invocation.method( - #getUTXOs, [], {#scripthash: scripthash, #requestID: requestID}), - returnValue: Future>>.value( - >[])) as _i7 - .Future>>); - @override - _i7.Future>>> getBatchUTXOs( - {Map>? args}) => - (super.noSuchMethod(Invocation.method(#getBatchUTXOs, [], {#args: args}), - returnValue: Future>>>.value( - >>{})) as _i7 - .Future>>>); - @override - _i7.Future> getTransaction( - {String? txHash, bool? verbose = true, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getTransaction, [], - {#txHash: txHash, #verbose: verbose, #requestID: requestID}), - returnValue: - Future>.value({})) - as _i7.Future>); - @override - _i7.Future> getAnonymitySet( - {String? groupId = r'1', - String? blockhash = r'', - String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getAnonymitySet, [], { - #groupId: groupId, - #blockhash: blockhash, - #requestID: requestID - }), - returnValue: - Future>.value({})) - as _i7.Future>); - @override - _i7.Future getMintData({dynamic mints, String? requestID}) => - (super.noSuchMethod( - Invocation.method( - #getMintData, [], {#mints: mints, #requestID: requestID}), - returnValue: Future.value()) as _i7.Future); - @override - _i7.Future> getUsedCoinSerials( - {String? requestID, int? startNumber}) => - (super.noSuchMethod( - Invocation.method(#getUsedCoinSerials, [], - {#requestID: requestID, #startNumber: startNumber}), - returnValue: - Future>.value({})) - as _i7.Future>); - @override - _i7.Future getLatestCoinId({String? requestID}) => (super.noSuchMethod( - Invocation.method(#getLatestCoinId, [], {#requestID: requestID}), - returnValue: Future.value(0)) as _i7.Future); - @override - _i7.Future> getFeeRate({String? requestID}) => (super - .noSuchMethod(Invocation.method(#getFeeRate, [], {#requestID: requestID}), - returnValue: - Future>.value({})) as _i7 - .Future>); - @override - _i7.Future<_i4.Decimal> estimateFee({String? requestID, int? blocks}) => - (super.noSuchMethod( - Invocation.method( - #estimateFee, [], {#requestID: requestID, #blocks: blocks}), - returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) - as _i7.Future<_i4.Decimal>); - @override - _i7.Future<_i4.Decimal> relayFee({String? requestID}) => (super.noSuchMethod( - Invocation.method(#relayFee, [], {#requestID: requestID}), - returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) - as _i7.Future<_i4.Decimal>); + returnValueForMissingStub: Future.value()) as _i6.Future); } diff --git a/test/widget_tests/address_book_card_test.dart b/test/widget_tests/address_book_card_test.dart new file mode 100644 index 000000000..d429f130c --- /dev/null +++ b/test/widget_tests/address_book_card_test.dart @@ -0,0 +1,54 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:stackwallet/models/contact.dart'; +import 'package:stackwallet/models/contact_address_entry.dart'; +import 'package:stackwallet/providers/global/address_book_service_provider.dart'; +import 'package:stackwallet/services/address_book_service.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/theme/light_colors.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/widgets/address_book_card.dart'; + +import 'address_book_card_test.mocks.dart'; + +@GenerateMocks([AddressBookService]) +void main() { + testWidgets('test returns Contact Address Entry', (widgetTester) async { + final service = MockAddressBookService(); + when(service.getContactById("some id")) + .thenAnswer((realInvocation) => Contact( + name: "John Doe", + addresses: [ + const ContactAddressEntry( + coin: Coin.bitcoincash, + address: "some bch address", + label: "Bills") + ], + isFavorite: true)); + + await widgetTester.pumpWidget( + ProviderScope( + overrides: [ + addressBookServiceProvider.overrideWithValue( + service, + ), + ], + child: MaterialApp( + theme: ThemeData( + extensions: [ + StackColors.fromStackColorTheme( + LightColors(), + ), + ], + ), + home: const AddressBookCard( + contactId: "some id", + ), + ), + ), + ); + }); +} diff --git a/test/widget_tests/address_book_card_test.mocks.dart b/test/widget_tests/address_book_card_test.mocks.dart new file mode 100644 index 000000000..bff27d7d1 --- /dev/null +++ b/test/widget_tests/address_book_card_test.mocks.dart @@ -0,0 +1,87 @@ +// Mocks generated by Mockito 5.2.0 from annotations +// in stackwallet/test/widget_tests/address_book_card_test.dart. +// Do not manually edit this file. + +import 'dart:async' as _i4; +import 'dart:ui' as _i5; + +import 'package:mockito/mockito.dart' as _i1; +import 'package:stackwallet/models/contact.dart' as _i2; +import 'package:stackwallet/services/address_book_service.dart' as _i3; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types + +class _FakeContact_0 extends _i1.Fake implements _i2.Contact {} + +/// A class which mocks [AddressBookService]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockAddressBookService extends _i1.Mock + implements _i3.AddressBookService { + MockAddressBookService() { + _i1.throwOnMissingStub(this); + } + + @override + List<_i2.Contact> get contacts => + (super.noSuchMethod(Invocation.getter(#contacts), + returnValue: <_i2.Contact>[]) as List<_i2.Contact>); + @override + _i4.Future> get addressBookEntries => + (super.noSuchMethod(Invocation.getter(#addressBookEntries), + returnValue: Future>.value(<_i2.Contact>[])) + as _i4.Future>); + @override + bool get hasListeners => + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); + @override + _i2.Contact getContactById(String? id) => + (super.noSuchMethod(Invocation.method(#getContactById, [id]), + returnValue: _FakeContact_0()) as _i2.Contact); + @override + _i4.Future> search(String? text) => + (super.noSuchMethod(Invocation.method(#search, [text]), + returnValue: Future>.value(<_i2.Contact>[])) + as _i4.Future>); + @override + bool matches(String? term, _i2.Contact? contact) => + (super.noSuchMethod(Invocation.method(#matches, [term, contact]), + returnValue: false) as bool); + @override + _i4.Future addContact(_i2.Contact? contact) => + (super.noSuchMethod(Invocation.method(#addContact, [contact]), + returnValue: Future.value(false)) as _i4.Future); + @override + _i4.Future editContact(_i2.Contact? editedContact) => + (super.noSuchMethod(Invocation.method(#editContact, [editedContact]), + returnValue: Future.value(false)) as _i4.Future); + @override + _i4.Future removeContact(String? id) => + (super.noSuchMethod(Invocation.method(#removeContact, [id]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i4.Future); + @override + void addListener(_i5.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); + @override + void removeListener(_i5.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#removeListener, [listener]), + returnValueForMissingStub: null); + @override + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); + @override + void notifyListeners() => + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); +} diff --git a/test/widget_tests/wallet_info_row_test.dart b/test/widget_tests/wallet_info_row_test.dart new file mode 100644 index 000000000..d9537f6c0 --- /dev/null +++ b/test/widget_tests/wallet_info_row_test.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:stackwallet/providers/providers.dart'; +import 'package:stackwallet/services/coins/manager.dart'; +import 'package:stackwallet/services/wallets.dart'; +import 'package:stackwallet/services/wallets_service.dart'; +import 'package:stackwallet/widgets/wallet_info_row/sub_widgets/wallet_info_row_balance_future.dart'; +import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/theme/light_colors.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; + +// import '../screen_tests/lockscreen_view_screen_test.mocks.dart'; +import 'wallet_info_row_test.mocks.dart'; + +@GenerateMocks([WalletsService], + customMocks: [MockSpec(returnNullOnMissingStub: true)]) +void main() { + testWidgets("returns wallet info for given wallet id", (widgetTester) async { + final service = MockWalletsService(); + // final mockManager = MockManager(); + + // String? walletId = await service.addNewWallet( + // name: "Test", coin: Coin.bitcoin, shouldNotifyListeners: false); + // final managerProvider = ChangeNotifierProvider((ref) => { + // return service.get; + // }); + + when(service.addNewWallet( + name: "Test", coin: Coin.bitcoin, shouldNotifyListeners: false)) + .thenAnswer((_) => Future(() => "some wallet id")); + + // when(service.getWalletId(walletName)) + await widgetTester.pumpWidget( + ProviderScope( + overrides: [ + walletsServiceChangeNotifierProvider.overrideWithValue(service), + ], + child: MaterialApp( + theme: ThemeData( + extensions: [ + StackColors.fromStackColorTheme( + LightColors(), + ), + ], + ), + home: const WalletInfoRowBalanceFuture( + walletId: "some wallet id", + ), + ), + ), + ); + }); +} diff --git a/test/widget_tests/wallet_info_row_test.mocks.dart b/test/widget_tests/wallet_info_row_test.mocks.dart new file mode 100644 index 000000000..cca9a6ca5 --- /dev/null +++ b/test/widget_tests/wallet_info_row_test.mocks.dart @@ -0,0 +1,393 @@ +// Mocks generated by Mockito 5.2.0 from annotations +// in stackwallet/test/widget_tests/wallet_info_row_test.dart. +// Do not manually edit this file. + +import 'dart:async' as _i6; +import 'dart:ui' as _i8; + +import 'package:decimal/decimal.dart' as _i4; +import 'package:mockito/mockito.dart' as _i1; +import 'package:stackwallet/models/models.dart' as _i3; +import 'package:stackwallet/services/coins/coin_service.dart' as _i2; +import 'package:stackwallet/services/coins/manager.dart' as _i9; +import 'package:stackwallet/services/wallets_service.dart' as _i5; +import 'package:stackwallet/utilities/enums/coin_enum.dart' as _i7; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types + +class _FakeCoinServiceAPI_0 extends _i1.Fake implements _i2.CoinServiceAPI {} + +class _FakeFeeObject_1 extends _i1.Fake implements _i3.FeeObject {} + +class _FakeDecimal_2 extends _i1.Fake implements _i4.Decimal {} + +class _FakeTransactionData_3 extends _i1.Fake implements _i3.TransactionData {} + +/// A class which mocks [WalletsService]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWalletsService extends _i1.Mock implements _i5.WalletsService { + MockWalletsService() { + _i1.throwOnMissingStub(this); + } + + @override + _i6.Future> get walletNames => + (super.noSuchMethod(Invocation.getter(#walletNames), + returnValue: Future>.value( + {})) + as _i6.Future>); + @override + bool get hasListeners => + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); + @override + _i6.Future renameWallet( + {String? from, String? to, bool? shouldNotifyListeners}) => + (super.noSuchMethod( + Invocation.method(#renameWallet, [], { + #from: from, + #to: to, + #shouldNotifyListeners: shouldNotifyListeners + }), + returnValue: Future.value(false)) as _i6.Future); + @override + _i6.Future addExistingStackWallet( + {String? name, + String? walletId, + _i7.Coin? coin, + bool? shouldNotifyListeners}) => + (super.noSuchMethod( + Invocation.method(#addExistingStackWallet, [], { + #name: name, + #walletId: walletId, + #coin: coin, + #shouldNotifyListeners: shouldNotifyListeners + }), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future addNewWallet( + {String? name, _i7.Coin? coin, bool? shouldNotifyListeners}) => + (super.noSuchMethod( + Invocation.method(#addNewWallet, [], { + #name: name, + #coin: coin, + #shouldNotifyListeners: shouldNotifyListeners + }), + returnValue: Future.value()) as _i6.Future); + @override + _i6.Future> getFavoriteWalletIds() => + (super.noSuchMethod(Invocation.method(#getFavoriteWalletIds, []), + returnValue: Future>.value([])) + as _i6.Future>); + @override + _i6.Future saveFavoriteWalletIds(List? walletIds) => (super + .noSuchMethod(Invocation.method(#saveFavoriteWalletIds, [walletIds]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future addFavorite(String? walletId) => + (super.noSuchMethod(Invocation.method(#addFavorite, [walletId]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future removeFavorite(String? walletId) => + (super.noSuchMethod(Invocation.method(#removeFavorite, [walletId]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future moveFavorite({int? fromIndex, int? toIndex}) => + (super.noSuchMethod( + Invocation.method( + #moveFavorite, [], {#fromIndex: fromIndex, #toIndex: toIndex}), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future checkForDuplicate(String? name) => + (super.noSuchMethod(Invocation.method(#checkForDuplicate, [name]), + returnValue: Future.value(false)) as _i6.Future); + @override + _i6.Future getWalletId(String? walletName) => + (super.noSuchMethod(Invocation.method(#getWalletId, [walletName]), + returnValue: Future.value()) as _i6.Future); + @override + _i6.Future isMnemonicVerified({String? walletId}) => + (super.noSuchMethod( + Invocation.method(#isMnemonicVerified, [], {#walletId: walletId}), + returnValue: Future.value(false)) as _i6.Future); + @override + _i6.Future setMnemonicVerified({String? walletId}) => + (super.noSuchMethod( + Invocation.method(#setMnemonicVerified, [], {#walletId: walletId}), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future deleteWallet(String? name, bool? shouldNotifyListeners) => + (super.noSuchMethod( + Invocation.method(#deleteWallet, [name, shouldNotifyListeners]), + returnValue: Future.value(0)) as _i6.Future); + @override + _i6.Future refreshWallets(bool? shouldNotifyListeners) => (super + .noSuchMethod(Invocation.method(#refreshWallets, [shouldNotifyListeners]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + void addListener(_i8.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); + @override + void removeListener(_i8.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#removeListener, [listener]), + returnValueForMissingStub: null); + @override + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); + @override + void notifyListeners() => + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); +} + +/// A class which mocks [Manager]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockManager extends _i1.Mock implements _i9.Manager { + @override + bool get isActiveWallet => (super + .noSuchMethod(Invocation.getter(#isActiveWallet), returnValue: false) + as bool); + @override + set isActiveWallet(bool? isActive) => + super.noSuchMethod(Invocation.setter(#isActiveWallet, isActive), + returnValueForMissingStub: null); + @override + _i2.CoinServiceAPI get wallet => + (super.noSuchMethod(Invocation.getter(#wallet), + returnValue: _FakeCoinServiceAPI_0()) as _i2.CoinServiceAPI); + @override + bool get hasBackgroundRefreshListener => + (super.noSuchMethod(Invocation.getter(#hasBackgroundRefreshListener), + returnValue: false) as bool); + @override + _i7.Coin get coin => (super.noSuchMethod(Invocation.getter(#coin), + returnValue: _i7.Coin.bitcoin) as _i7.Coin); + @override + bool get isRefreshing => + (super.noSuchMethod(Invocation.getter(#isRefreshing), returnValue: false) + as bool); + @override + bool get shouldAutoSync => (super + .noSuchMethod(Invocation.getter(#shouldAutoSync), returnValue: false) + as bool); + @override + set shouldAutoSync(bool? shouldAutoSync) => + super.noSuchMethod(Invocation.setter(#shouldAutoSync, shouldAutoSync), + returnValueForMissingStub: null); + @override + bool get isFavorite => + (super.noSuchMethod(Invocation.getter(#isFavorite), returnValue: false) + as bool); + @override + set isFavorite(bool? markFavorite) => + super.noSuchMethod(Invocation.setter(#isFavorite, markFavorite), + returnValueForMissingStub: null); + @override + _i6.Future<_i3.FeeObject> get fees => + (super.noSuchMethod(Invocation.getter(#fees), + returnValue: Future<_i3.FeeObject>.value(_FakeFeeObject_1())) + as _i6.Future<_i3.FeeObject>); + @override + _i6.Future get maxFee => (super.noSuchMethod(Invocation.getter(#maxFee), + returnValue: Future.value(0)) as _i6.Future); + @override + _i6.Future get currentReceivingAddress => + (super.noSuchMethod(Invocation.getter(#currentReceivingAddress), + returnValue: Future.value('')) as _i6.Future); + @override + _i6.Future<_i4.Decimal> get availableBalance => + (super.noSuchMethod(Invocation.getter(#availableBalance), + returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) + as _i6.Future<_i4.Decimal>); + @override + _i4.Decimal get cachedAvailableBalance => + (super.noSuchMethod(Invocation.getter(#cachedAvailableBalance), + returnValue: _FakeDecimal_2()) as _i4.Decimal); + @override + _i6.Future<_i4.Decimal> get pendingBalance => + (super.noSuchMethod(Invocation.getter(#pendingBalance), + returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) + as _i6.Future<_i4.Decimal>); + @override + _i6.Future<_i4.Decimal> get balanceMinusMaxFee => + (super.noSuchMethod(Invocation.getter(#balanceMinusMaxFee), + returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) + as _i6.Future<_i4.Decimal>); + @override + _i6.Future<_i4.Decimal> get totalBalance => + (super.noSuchMethod(Invocation.getter(#totalBalance), + returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) + as _i6.Future<_i4.Decimal>); + @override + _i4.Decimal get cachedTotalBalance => + (super.noSuchMethod(Invocation.getter(#cachedTotalBalance), + returnValue: _FakeDecimal_2()) as _i4.Decimal); + @override + _i6.Future> get allOwnAddresses => + (super.noSuchMethod(Invocation.getter(#allOwnAddresses), + returnValue: Future>.value([])) + as _i6.Future>); + @override + _i6.Future<_i3.TransactionData> get transactionData => + (super.noSuchMethod(Invocation.getter(#transactionData), + returnValue: + Future<_i3.TransactionData>.value(_FakeTransactionData_3())) + as _i6.Future<_i3.TransactionData>); + @override + _i6.Future> get unspentOutputs => (super.noSuchMethod( + Invocation.getter(#unspentOutputs), + returnValue: Future>.value(<_i3.UtxoObject>[])) + as _i6.Future>); + @override + set walletName(String? newName) => + super.noSuchMethod(Invocation.setter(#walletName, newName), + returnValueForMissingStub: null); + @override + String get walletName => + (super.noSuchMethod(Invocation.getter(#walletName), returnValue: '') + as String); + @override + String get walletId => + (super.noSuchMethod(Invocation.getter(#walletId), returnValue: '') + as String); + @override + _i6.Future> get mnemonic => + (super.noSuchMethod(Invocation.getter(#mnemonic), + returnValue: Future>.value([])) + as _i6.Future>); + @override + bool get isConnected => + (super.noSuchMethod(Invocation.getter(#isConnected), returnValue: false) + as bool); + @override + bool get hasListeners => + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); + @override + _i6.Future updateNode(bool? shouldRefresh) => + (super.noSuchMethod(Invocation.method(#updateNode, [shouldRefresh]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); + @override + _i6.Future> prepareSend( + {String? address, int? satoshiAmount, Map? args}) => + (super.noSuchMethod( + Invocation.method(#prepareSend, [], { + #address: address, + #satoshiAmount: satoshiAmount, + #args: args + }), + returnValue: + Future>.value({})) + as _i6.Future>); + @override + _i6.Future confirmSend({Map? txData}) => (super + .noSuchMethod(Invocation.method(#confirmSend, [], {#txData: txData}), + returnValue: Future.value('')) as _i6.Future); + @override + _i6.Future send( + {String? toAddress, + int? amount, + Map? args = const {}}) => + (super.noSuchMethod( + Invocation.method( + #send, [], {#toAddress: toAddress, #amount: amount, #args: args}), + returnValue: Future.value('')) as _i6.Future); + @override + _i6.Future refresh() => + (super.noSuchMethod(Invocation.method(#refresh, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + bool validateAddress(String? address) => + (super.noSuchMethod(Invocation.method(#validateAddress, [address]), + returnValue: false) as bool); + @override + _i6.Future testNetworkConnection() => + (super.noSuchMethod(Invocation.method(#testNetworkConnection, []), + returnValue: Future.value(false)) as _i6.Future); + @override + _i6.Future initializeNew() => + (super.noSuchMethod(Invocation.method(#initializeNew, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future initializeExisting() => + (super.noSuchMethod(Invocation.method(#initializeExisting, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future recoverFromMnemonic( + {String? mnemonic, + int? maxUnusedAddressGap, + int? maxNumberOfIndexesToCheck, + int? height}) => + (super.noSuchMethod( + Invocation.method(#recoverFromMnemonic, [], { + #mnemonic: mnemonic, + #maxUnusedAddressGap: maxUnusedAddressGap, + #maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + #height: height + }), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future exitCurrentWallet() => + (super.noSuchMethod(Invocation.method(#exitCurrentWallet, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future fullRescan( + int? maxUnusedAddressGap, int? maxNumberOfIndexesToCheck) => + (super.noSuchMethod( + Invocation.method( + #fullRescan, [maxUnusedAddressGap, maxNumberOfIndexesToCheck]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i6.Future); + @override + _i6.Future isOwnAddress(String? address) => + (super.noSuchMethod(Invocation.method(#isOwnAddress, [address]), + returnValue: Future.value(false)) as _i6.Future); + @override + _i6.Future estimateFeeFor(int? satoshiAmount, int? feeRate) => + (super.noSuchMethod( + Invocation.method(#estimateFeeFor, [satoshiAmount, feeRate]), + returnValue: Future.value(0)) as _i6.Future); + @override + _i6.Future generateNewAddress() => + (super.noSuchMethod(Invocation.method(#generateNewAddress, []), + returnValue: Future.value(false)) as _i6.Future); + @override + void addListener(_i8.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); + @override + void removeListener(_i8.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#removeListener, [listener]), + returnValueForMissingStub: null); + @override + void notifyListeners() => + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); +}