fix previous failing widget tests

This commit is contained in:
julian 2022-11-02 08:49:19 -06:00
parent b4a92159a6
commit fc25ea2a24
3 changed files with 450 additions and 403 deletions

View file

@ -102,15 +102,13 @@ class _TransactionCardState extends ConsumerState<TransactionCard> {
.select((value) => value.getPrice(coin)))
.item1;
late final String prefix;
String prefix = "";
if (Util.isDesktop) {
if (_transaction.txType == "Sent") {
prefix = "-";
} else if (_transaction.txType == "Received") {
prefix = "+";
}
} else {
prefix = "";
}
return Material(

View file

@ -1,6 +1,22 @@
import 'dart:io';
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/pages/address_book_views/subviews/contact_popup.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/utilities/util.dart';
import 'package:stackwallet/widgets/address_book_card.dart';
import 'address_book_card_test.mocks.dart';
class MockedFunctions extends Mock {
void showDialog();
@ -8,46 +24,53 @@ class MockedFunctions extends Mock {
@GenerateMocks([AddressBookService])
void main() {
// testWidgets('test returns Contact Address Entry', (widgetTester) async {
// final service = MockAddressBookService();
//
// when(service.getContactById("default"))
// .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: "default",
// ),
// ),
// ),
// );
//
// expect(find.text("John Doe"), findsOneWidget);
// expect(find.text("BCH"), findsOneWidget);
// expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
//
// await widgetTester.tap(find.byType(RawMaterialButton));
// });
testWidgets('test returns Contact Address Entry', (widgetTester) async {
final service = MockAddressBookService();
when(service.getContactById("default")).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: "default",
),
),
),
);
expect(find.text("John Doe"), findsOneWidget);
expect(find.text("BCH"), findsOneWidget);
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
if (Platform.isIOS || Platform.isAndroid) {
await widgetTester.tap(find.byType(RawMaterialButton));
expect(find.byType(ContactPopUp), findsOneWidget);
} else if (Util.isDesktop) {
expect(find.byType(RawMaterialButton), findsNothing);
}
});
}

View file

@ -1,4 +1,14 @@
import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:flutter_riverpod/flutter_riverpod.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/models.dart';
import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/coins/coin_service.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/services/coins/manager.dart';
@ -6,7 +16,15 @@ import 'package:stackwallet/services/locale_service.dart';
import 'package:stackwallet/services/notes_service.dart';
import 'package:stackwallet/services/price_service.dart';
import 'package:stackwallet/services/wallets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/prefs.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/transaction_card.dart';
import 'package:tuple/tuple.dart';
import 'transaction_card_test.mocks.dart';
@GenerateMocks([
Wallets,
@ -19,362 +37,370 @@ import 'package:stackwallet/utilities/prefs.dart';
NotesService
], customMocks: [])
void main() {
// TestWidgetsFlutterBinding.ensureInitialized();
// testWidgets("Sent confirmed tx displays correctly", (tester) async {
// final mockManager = MockManager();
// final mockLocaleService = MockLocaleService();
// final wallets = MockWallets();
// final mockPrefs = MockPrefs();
// final mockPriceService = MockPriceService();
//
// final tx = Transaction(
// txid: "some txid",
// confirmedStatus: true,
// timestamp: 1648595998,
// txType: "Sent",
// amount: 100000000,
// aliens: [],
// worthNow: "0.01",
// worthAtBlockTimestamp: "0.01",
// fees: 3794,
// inputSize: 1,
// outputSize: 1,
// inputs: [],
// outputs: [],
// address: "",
// height: 450123,
// subType: "",
// confirmations: 10,
// isCancelled: false);
//
// final CoinServiceAPI wallet = MockFiroWallet();
//
// when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
// when(mockLocaleService.locale).thenAnswer((_) => "en_US");
// when(mockPrefs.currency).thenAnswer((_) => "USD");
// when(mockPrefs.externalCalls).thenAnswer((_) => true);
// when(mockPriceService.getPrice(Coin.firo))
// .thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
//
// when(wallet.coin).thenAnswer((_) => Coin.firo);
//
// when(wallets.getManager("wallet-id"))
// .thenAnswer((realInvocation) => Manager(wallet));
// //
// await tester.pumpWidget(
// ProviderScope(
// overrides: [
// walletsChangeNotifierProvider.overrideWithValue(wallets),
// localeServiceChangeNotifierProvider
// .overrideWithValue(mockLocaleService),
// prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
// priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
// ],
// child: MaterialApp(
// theme: ThemeData(
// extensions: [
// StackColors.fromStackColorTheme(
// LightColors(),
// ),
// ],
// ),
// home: TransactionCard(transaction: tx, walletId: "wallet-id"),
// ),
// ),
// );
//
// //
// final title = find.text("Sent");
// // final price1 = find.text("0.00 USD");
// final amount = find.text("1.00000000 FIRO");
//
// final icon = find.byIcon(FeatherIcons.arrowUp);
//
// expect(title, findsOneWidget);
// // expect(price1, findsOneWidget);
// expect(amount, findsOneWidget);
// // expect(icon, findsOneWidget);
// //
// await tester.pumpAndSettle(Duration(seconds: 2));
// //
// // final price2 = find.text("\$10.00");
// // expect(price2, findsOneWidget);
// //
// // verify(mockManager.addListener(any)).called(1);
// verify(mockLocaleService.addListener(any)).called(1);
//
// verify(mockPrefs.currency).called(1);
// verify(mockPriceService.getPrice(Coin.firo)).called(1);
// verify(wallet.coin.ticker).called(1);
//
// verify(mockLocaleService.locale).called(1);
//
// verifyNoMoreInteractions(mockManager);
// verifyNoMoreInteractions(mockLocaleService);
// });
//
// testWidgets("Anonymized confirmed tx displays correctly", (tester) async {
// final mockManager = MockManager();
// final mockLocaleService = MockLocaleService();
// final wallets = MockWallets();
// final mockPrefs = MockPrefs();
// final mockPriceService = MockPriceService();
//
// final tx = Transaction(
// txid: "some txid",
// confirmedStatus: true,
// timestamp: 1648595998,
// txType: "Anonymized",
// amount: 100000000,
// aliens: [],
// worthNow: "0.01",
// worthAtBlockTimestamp: "0.01",
// fees: 3794,
// inputSize: 1,
// outputSize: 1,
// inputs: [],
// outputs: [],
// address: "",
// height: 450123,
// subType: "mint",
// confirmations: 10,
// isCancelled: false);
//
// final CoinServiceAPI wallet = MockFiroWallet();
//
// when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
// when(mockLocaleService.locale).thenAnswer((_) => "en_US");
// when(mockPrefs.currency).thenAnswer((_) => "USD");
// when(mockPrefs.externalCalls).thenAnswer((_) => true);
// when(mockPriceService.getPrice(Coin.firo))
// .thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
//
// when(wallet.coin).thenAnswer((_) => Coin.firo);
//
// when(wallets.getManager("wallet-id"))
// .thenAnswer((realInvocation) => Manager(wallet));
// //
// await tester.pumpWidget(
// ProviderScope(
// overrides: [
// walletsChangeNotifierProvider.overrideWithValue(wallets),
// localeServiceChangeNotifierProvider
// .overrideWithValue(mockLocaleService),
// prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
// priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
// ],
// child: MaterialApp(
// theme: ThemeData(
// extensions: [
// StackColors.fromStackColorTheme(
// LightColors(),
// ),
// ],
// ),
// home: TransactionCard(transaction: tx, walletId: "wallet-id"),
// ),
// ),
// );
//
// //
// final title = find.text("Anonymized");
// // final price1 = find.text("0.00 USD");
// final amount = find.text("1.00000000 FIRO");
//
// final icon = find.byIcon(FeatherIcons.arrowUp);
//
// expect(title, findsOneWidget);
// // expect(price1, findsOneWidget);
// expect(amount, findsOneWidget);
// // expect(icon, findsOneWidget);
// //
// await tester.pumpAndSettle(Duration(seconds: 2));
// //
// // final price2 = find.text("\$10.00");
// // expect(price2, findsOneWidget);
// //
// // verify(mockManager.addListener(any)).called(1);
// verify(mockLocaleService.addListener(any)).called(1);
//
// verify(mockPrefs.currency).called(1);
// verify(mockPriceService.getPrice(Coin.firo)).called(1);
// verify(wallet.coin.ticker).called(1);
//
// verify(mockLocaleService.locale).called(1);
//
// verifyNoMoreInteractions(mockManager);
// verifyNoMoreInteractions(mockLocaleService);
// });
//
// testWidgets("Received unconfirmed tx displays correctly", (tester) async {
// final mockManager = MockManager();
// final mockLocaleService = MockLocaleService();
// final wallets = MockWallets();
// final mockPrefs = MockPrefs();
// final mockPriceService = MockPriceService();
//
// final tx = Transaction(
// txid: "some txid",
// confirmedStatus: false,
// timestamp: 1648595998,
// txType: "Received",
// amount: 100000000,
// aliens: [],
// worthNow: "0.01",
// worthAtBlockTimestamp: "0.01",
// fees: 3794,
// inputSize: 1,
// outputSize: 1,
// inputs: [],
// outputs: [],
// address: "",
// height: 0,
// subType: "",
// confirmations: 0,
// );
//
// final CoinServiceAPI wallet = MockFiroWallet();
//
// when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
// when(mockLocaleService.locale).thenAnswer((_) => "en_US");
// when(mockPrefs.currency).thenAnswer((_) => "USD");
// when(mockPrefs.externalCalls).thenAnswer((_) => true);
// when(mockPriceService.getPrice(Coin.firo))
// .thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
//
// when(wallet.coin).thenAnswer((_) => Coin.firo);
//
// when(wallets.getManager("wallet-id"))
// .thenAnswer((realInvocation) => Manager(wallet));
//
// await tester.pumpWidget(
// ProviderScope(
// overrides: [
// walletsChangeNotifierProvider.overrideWithValue(wallets),
// localeServiceChangeNotifierProvider
// .overrideWithValue(mockLocaleService),
// prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
// priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
// ],
// child: MaterialApp(
// theme: ThemeData(
// extensions: [
// StackColors.fromStackColorTheme(
// LightColors(),
// ),
// ],
// ),
// home: TransactionCard(transaction: tx, walletId: "wallet-id"),
// ),
// ),
// );
//
// final title = find.text("Receiving");
// final amount = find.text("1.00000000 FIRO");
//
// expect(title, findsOneWidget);
// expect(amount, findsOneWidget);
//
// await tester.pumpAndSettle(Duration(seconds: 2));
//
// verify(mockLocaleService.addListener(any)).called(1);
//
// verify(mockPrefs.currency).called(1);
// verify(mockPriceService.getPrice(Coin.firo)).called(1);
// verify(wallet.coin.ticker).called(1);
//
// verify(mockLocaleService.locale).called(1);
//
// verifyNoMoreInteractions(mockManager);
// verifyNoMoreInteractions(mockLocaleService);
// });
//
// testWidgets("Tap gesture", (tester) async {
// final mockManager = MockManager();
// final mockLocaleService = MockLocaleService();
// final wallets = MockWallets();
// final mockPrefs = MockPrefs();
// final mockPriceService = MockPriceService();
// final navigator = mockingjay.MockNavigator();
//
// final tx = Transaction(
// txid: "some txid",
// confirmedStatus: false,
// timestamp: 1648595998,
// txType: "Received",
// amount: 100000000,
// aliens: [],
// worthNow: "0.01",
// worthAtBlockTimestamp: "0.01",
// fees: 3794,
// inputSize: 1,
// outputSize: 1,
// inputs: [],
// outputs: [],
// address: "",
// height: 250,
// subType: "",
// confirmations: 10,
// );
//
// final CoinServiceAPI wallet = MockFiroWallet();
//
// when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
// when(mockLocaleService.locale).thenAnswer((_) => "en_US");
// when(mockPrefs.currency).thenAnswer((_) => "USD");
// when(mockPrefs.externalCalls).thenAnswer((_) => true);
// when(mockPriceService.getPrice(Coin.firo))
// .thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
//
// when(wallet.coin).thenAnswer((_) => Coin.firo);
//
// when(wallets.getManager("wallet id"))
// .thenAnswer((realInvocation) => Manager(wallet));
//
// mockingjay
// .when(() => navigator.pushNamed("/transactionDetails",
// arguments: Tuple3(tx, Coin.firo, "wallet id")))
// .thenAnswer((_) async => {});
//
// await tester.pumpWidget(
// ProviderScope(
// overrides: [
// walletsChangeNotifierProvider.overrideWithValue(wallets),
// localeServiceChangeNotifierProvider
// .overrideWithValue(mockLocaleService),
// prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
// priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
// ],
// child: MaterialApp(
// theme: ThemeData(
// extensions: [
// StackColors.fromStackColorTheme(LightColors()),
// ],
// ),
// home: mockingjay.MockNavigatorProvider(
// navigator: navigator,
// child: TransactionCard(transaction: tx, walletId: "wallet id")),
// ),
// ),
// );
//
// expect(find.byType(GestureDetector), findsOneWidget);
//
// await tester.tap(find.byType(GestureDetector));
// await tester.pump();
//
// verify(mockLocaleService.addListener(any)).called(1);
//
// verify(mockPrefs.currency).called(1);
// verify(mockLocaleService.locale).called(1);
// verify(wallet.coin.ticker).called(1);
//
// verifyNoMoreInteractions(wallet);
// verifyNoMoreInteractions(mockLocaleService);
//
// mockingjay
// .verify(() => navigator.pushNamed("/transactionDetails",
// arguments: Tuple3(tx, Coin.firo, "wallet id")))
// .called(1);
// });
TestWidgetsFlutterBinding.ensureInitialized();
testWidgets("Sent confirmed tx displays correctly", (tester) async {
final mockManager = MockManager();
final mockLocaleService = MockLocaleService();
final wallets = MockWallets();
final mockPrefs = MockPrefs();
final mockPriceService = MockPriceService();
final tx = Transaction(
txid: "some txid",
confirmedStatus: true,
timestamp: 1648595998,
txType: "Sent",
amount: 100000000,
aliens: [],
worthNow: "0.01",
worthAtBlockTimestamp: "0.01",
fees: 3794,
inputSize: 1,
outputSize: 1,
inputs: [],
outputs: [],
address: "",
height: 450123,
subType: "",
confirmations: 10,
isCancelled: false);
final CoinServiceAPI wallet = MockFiroWallet();
when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
when(mockLocaleService.locale).thenAnswer((_) => "en_US");
when(mockPrefs.currency).thenAnswer((_) => "USD");
when(mockPrefs.externalCalls).thenAnswer((_) => true);
when(mockPriceService.getPrice(Coin.firo))
.thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
when(wallet.coin).thenAnswer((_) => Coin.firo);
when(wallets.getManager("wallet-id"))
.thenAnswer((realInvocation) => Manager(wallet));
//
await tester.pumpWidget(
ProviderScope(
overrides: [
walletsChangeNotifierProvider.overrideWithValue(wallets),
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: TransactionCard(transaction: tx, walletId: "wallet-id"),
),
),
);
//
final title = find.text("Sent");
// final price1 = find.text("0.00 USD");
final amount = Util.isDesktop
? find.text("-1.00000000 FIRO")
: find.text("1.00000000 FIRO");
final icon = find.byIcon(FeatherIcons.arrowUp);
expect(title, findsOneWidget);
// expect(price1, findsOneWidget);
expect(amount, findsOneWidget);
// expect(icon, findsOneWidget);
//
await tester.pumpAndSettle(const Duration(seconds: 2));
//
// final price2 = find.text("\$10.00");
// expect(price2, findsOneWidget);
//
// verify(mockManager.addListener(any)).called(1);
verify(mockLocaleService.addListener(any)).called(1);
verify(mockPrefs.currency).called(1);
verify(mockPriceService.getPrice(Coin.firo)).called(1);
verify(wallet.coin.ticker).called(1);
verify(mockLocaleService.locale).called(1);
verifyNoMoreInteractions(mockManager);
verifyNoMoreInteractions(mockLocaleService);
});
testWidgets("Anonymized confirmed tx displays correctly", (tester) async {
final mockManager = MockManager();
final mockLocaleService = MockLocaleService();
final wallets = MockWallets();
final mockPrefs = MockPrefs();
final mockPriceService = MockPriceService();
final tx = Transaction(
txid: "some txid",
confirmedStatus: true,
timestamp: 1648595998,
txType: "Anonymized",
amount: 100000000,
aliens: [],
worthNow: "0.01",
worthAtBlockTimestamp: "0.01",
fees: 3794,
inputSize: 1,
outputSize: 1,
inputs: [],
outputs: [],
address: "",
height: 450123,
subType: "mint",
confirmations: 10,
isCancelled: false);
final CoinServiceAPI wallet = MockFiroWallet();
when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
when(mockLocaleService.locale).thenAnswer((_) => "en_US");
when(mockPrefs.currency).thenAnswer((_) => "USD");
when(mockPrefs.externalCalls).thenAnswer((_) => true);
when(mockPriceService.getPrice(Coin.firo))
.thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
when(wallet.coin).thenAnswer((_) => Coin.firo);
when(wallets.getManager("wallet-id"))
.thenAnswer((realInvocation) => Manager(wallet));
//
await tester.pumpWidget(
ProviderScope(
overrides: [
walletsChangeNotifierProvider.overrideWithValue(wallets),
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: TransactionCard(transaction: tx, walletId: "wallet-id"),
),
),
);
//
final title = find.text("Anonymized");
// final price1 = find.text("0.00 USD");
final amount = find.text("1.00000000 FIRO");
final icon = find.byIcon(FeatherIcons.arrowUp);
expect(title, findsOneWidget);
// expect(price1, findsOneWidget);
expect(amount, findsOneWidget);
// expect(icon, findsOneWidget);
//
await tester.pumpAndSettle(const Duration(seconds: 2));
//
// final price2 = find.text("\$10.00");
// expect(price2, findsOneWidget);
//
// verify(mockManager.addListener(any)).called(1);
verify(mockLocaleService.addListener(any)).called(1);
verify(mockPrefs.currency).called(1);
verify(mockPriceService.getPrice(Coin.firo)).called(1);
verify(wallet.coin.ticker).called(1);
verify(mockLocaleService.locale).called(1);
verifyNoMoreInteractions(mockManager);
verifyNoMoreInteractions(mockLocaleService);
});
testWidgets("Received unconfirmed tx displays correctly", (tester) async {
final mockManager = MockManager();
final mockLocaleService = MockLocaleService();
final wallets = MockWallets();
final mockPrefs = MockPrefs();
final mockPriceService = MockPriceService();
final tx = Transaction(
txid: "some txid",
confirmedStatus: false,
timestamp: 1648595998,
txType: "Received",
amount: 100000000,
aliens: [],
worthNow: "0.01",
worthAtBlockTimestamp: "0.01",
fees: 3794,
inputSize: 1,
outputSize: 1,
inputs: [],
outputs: [],
address: "",
height: 0,
subType: "",
confirmations: 0,
);
final CoinServiceAPI wallet = MockFiroWallet();
when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
when(mockLocaleService.locale).thenAnswer((_) => "en_US");
when(mockPrefs.currency).thenAnswer((_) => "USD");
when(mockPrefs.externalCalls).thenAnswer((_) => true);
when(mockPriceService.getPrice(Coin.firo))
.thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
when(wallet.coin).thenAnswer((_) => Coin.firo);
when(wallets.getManager("wallet-id"))
.thenAnswer((realInvocation) => Manager(wallet));
await tester.pumpWidget(
ProviderScope(
overrides: [
walletsChangeNotifierProvider.overrideWithValue(wallets),
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: TransactionCard(transaction: tx, walletId: "wallet-id"),
),
),
);
final title = find.text("Receiving");
final amount = Util.isDesktop
? find.text("+1.00000000 FIRO")
: find.text("1.00000000 FIRO");
expect(title, findsOneWidget);
expect(amount, findsOneWidget);
await tester.pumpAndSettle(const Duration(seconds: 2));
verify(mockLocaleService.addListener(any)).called(1);
verify(mockPrefs.currency).called(1);
verify(mockPriceService.getPrice(Coin.firo)).called(1);
verify(wallet.coin.ticker).called(1);
verify(mockLocaleService.locale).called(1);
verifyNoMoreInteractions(mockManager);
verifyNoMoreInteractions(mockLocaleService);
});
testWidgets("Tap gesture", (tester) async {
final mockManager = MockManager();
final mockLocaleService = MockLocaleService();
final wallets = MockWallets();
final mockPrefs = MockPrefs();
final mockPriceService = MockPriceService();
final navigator = mockingjay.MockNavigator();
final tx = Transaction(
txid: "some txid",
confirmedStatus: false,
timestamp: 1648595998,
txType: "Received",
amount: 100000000,
aliens: [],
worthNow: "0.01",
worthAtBlockTimestamp: "0.01",
fees: 3794,
inputSize: 1,
outputSize: 1,
inputs: [],
outputs: [],
address: "",
height: 250,
subType: "",
confirmations: 10,
);
final CoinServiceAPI wallet = MockFiroWallet();
when(wallet.coin.ticker).thenAnswer((_) => "FIRO");
when(mockLocaleService.locale).thenAnswer((_) => "en_US");
when(mockPrefs.currency).thenAnswer((_) => "USD");
when(mockPrefs.externalCalls).thenAnswer((_) => true);
when(mockPriceService.getPrice(Coin.firo))
.thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00));
when(wallet.coin).thenAnswer((_) => Coin.firo);
when(wallets.getManager("wallet id"))
.thenAnswer((realInvocation) => Manager(wallet));
mockingjay
.when(() => navigator.pushNamed("/transactionDetails",
arguments: Tuple3(tx, Coin.firo, "wallet id")))
.thenAnswer((_) async => {});
await tester.pumpWidget(
ProviderScope(
overrides: [
walletsChangeNotifierProvider.overrideWithValue(wallets),
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
priceAnd24hChangeNotifierProvider.overrideWithValue(mockPriceService)
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: mockingjay.MockNavigatorProvider(
navigator: navigator,
child: TransactionCard(transaction: tx, walletId: "wallet id")),
),
),
);
expect(find.byType(GestureDetector), findsOneWidget);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
verify(mockLocaleService.addListener(any)).called(1);
verify(mockPrefs.currency).called(2);
verify(mockLocaleService.locale).called(4);
verify(wallet.coin.ticker).called(1);
verifyNoMoreInteractions(wallet);
verifyNoMoreInteractions(mockLocaleService);
if (Util.isDesktop) {
expect(find.byType(TransactionDetailsView), findsOneWidget);
} else {
mockingjay
.verify(() => navigator.pushNamed("/transactionDetails",
arguments: Tuple3(tx, Coin.firo, "wallet id")))
.called(1);
}
});
}