Merge pull request #130 from cypherstack/widget-tests

Widget tests
This commit is contained in:
Marco Salazar 2022-10-24 11:59:24 -06:00 committed by GitHub
commit 734ddfec8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 3340 additions and 210 deletions

View file

@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/models/notification_model.dart';
import 'package:stackwallet/notifications/notification_card.dart';
import 'package:stackwallet/utilities/assets.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';
void main() {
testWidgets("test notification card", (widgetTester) async {
final key = UniqueKey();
final notificationCard = NotificationCard(
key: key,
notification: NotificationModel(
id: 1,
title: "notification title",
description: "notification description",
iconAssetName: Assets.svg.iconFor(coin: Coin.bitcoin),
date: DateTime.parse("1662544771"),
walletId: "wallet id",
read: true,
shouldWatchForUpdates: true,
coinName: "Bitcoin"),
);
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: notificationCard,
),
),
);
expect(find.byWidget(notificationCard), findsOneWidget);
expect(find.text("notification title"), findsOneWidget);
expect(find.text("notification description"), findsOneWidget);
expect(find.byType(SvgPicture), findsOneWidget);
});
}

View file

@ -0,0 +1,157 @@
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/send_view_auto_fill_data.dart';
import 'package:stackwallet/pages/send_view/send_view.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/coins/bitcoin/bitcoin_wallet.dart';
import 'package:stackwallet/services/coins/coin_service.dart';
import 'package:stackwallet/services/coins/manager.dart';
import 'package:stackwallet/services/locale_service.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/services/wallets.dart';
import 'package:stackwallet/services/wallets_service.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 'send_view_test.mocks.dart';
@GenerateMocks([
Wallets,
WalletsService,
NodeService,
BitcoinWallet,
LocaleService,
Prefs,
], customMocks: [
MockSpec<Manager>(returnNullOnMissingStub: true),
MockSpec<CoinServiceAPI>(returnNullOnMissingStub: true),
])
void main() {
testWidgets("Send to valid address", (widgetTester) async {
final mockWallets = MockWallets();
final mockWalletsService = MockWalletsService();
final mockNodeService = MockNodeService();
final CoinServiceAPI wallet = MockBitcoinWallet();
final mockLocaleService = MockLocaleService();
final mockPrefs = MockPrefs();
when(wallet.coin).thenAnswer((_) => Coin.bitcoin);
when(wallet.walletName).thenAnswer((_) => "some wallet");
when(wallet.walletId).thenAnswer((_) => "wallet id");
final manager = Manager(wallet);
when(mockWallets.getManagerProvider("wallet id")).thenAnswer(
(realInvocation) => ChangeNotifierProvider((ref) => manager));
when(mockWallets.getManager("wallet id"))
.thenAnswer((realInvocation) => manager);
when(mockLocaleService.locale).thenAnswer((_) => "en_US");
when(mockPrefs.currency).thenAnswer((_) => "USD");
when(wallet.validateAddress("send to address"))
.thenAnswer((realInvocation) => true);
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
walletsChangeNotifierProvider.overrideWithValue(mockWallets),
walletsServiceChangeNotifierProvider
.overrideWithValue(mockWalletsService),
nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService),
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
// previewTxButtonStateProvider
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: SendView(
walletId: "wallet id",
coin: Coin.bitcoin,
autoFillData: SendViewAutoFillData(
address: "send to address", contactLabel: "contact label"),
),
),
),
);
expect(find.text("Send to"), findsOneWidget);
expect(find.text("Amount"), findsOneWidget);
expect(find.text("Note (optional)"), findsOneWidget);
expect(find.text("Transaction fee (estimated)"), findsOneWidget);
verify(manager.validateAddress("send to address")).called(1);
});
testWidgets("Send to invalid address", (widgetTester) async {
final mockWallets = MockWallets();
final mockWalletsService = MockWalletsService();
final mockNodeService = MockNodeService();
final CoinServiceAPI wallet = MockBitcoinWallet();
final mockLocaleService = MockLocaleService();
final mockPrefs = MockPrefs();
when(wallet.coin).thenAnswer((_) => Coin.bitcoin);
when(wallet.walletName).thenAnswer((_) => "some wallet");
when(wallet.walletId).thenAnswer((_) => "wallet id");
final manager = Manager(wallet);
when(mockWallets.getManagerProvider("wallet id")).thenAnswer(
(realInvocation) => ChangeNotifierProvider((ref) => manager));
when(mockWallets.getManager("wallet id"))
.thenAnswer((realInvocation) => manager);
when(mockLocaleService.locale).thenAnswer((_) => "en_US");
when(mockPrefs.currency).thenAnswer((_) => "USD");
when(wallet.validateAddress("send to address"))
.thenAnswer((realInvocation) => false);
// when(manager.isOwnAddress("send to address"))
// .thenAnswer((realInvocation) => Future(() => true));
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
walletsChangeNotifierProvider.overrideWithValue(mockWallets),
walletsServiceChangeNotifierProvider
.overrideWithValue(mockWalletsService),
nodeServiceChangeNotifierProvider.overrideWithValue(mockNodeService),
localeServiceChangeNotifierProvider
.overrideWithValue(mockLocaleService),
prefsChangeNotifierProvider.overrideWithValue(mockPrefs),
// previewTxButtonStateProvider
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: SendView(
walletId: "wallet id",
coin: Coin.bitcoin,
autoFillData: SendViewAutoFillData(
address: "send to address", contactLabel: "contact label"),
),
),
),
);
expect(find.text("Send to"), findsOneWidget);
expect(find.text("Amount"), findsOneWidget);
expect(find.text("Note (optional)"), findsOneWidget);
expect(find.text("Transaction fee (estimated)"), findsOneWidget);
expect(find.text("Invalid address"), findsOneWidget);
verify(manager.validateAddress("send to address")).called(1);
});
}

File diff suppressed because it is too large Load diff

View file

@ -21,207 +21,46 @@ class MockedFunctions extends Mock {
@GenerateMocks([AddressBookService])
void main() {
group('Navigation tests', () {
late AddressBookService service;
setUp(() {
service = MockAddressBookService();
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));
});
when(service.getContactById("default"))
.thenAnswer((realInvocation) => Contact(
name: "John Doe",
addresses: [
const ContactAddressEntry(
coin: Coin.bitcoincash,
address: "some bch address",
label: "Bills")
],
isFavorite: true));
testWidgets('test returns Contact Address Entry', (widgetTester) async {
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
addressBookServiceProvider.overrideWithValue(
service,
),
],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: const AddressBookCard(
contactId: "some id",
),
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(Coin.bitcoincash.ticker), findsOneWidget);
});
expect(find.text("John Doe"), findsOneWidget);
expect(find.text("BCH"), findsOneWidget);
expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
// testWidgets("Test button press opens dialog", (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",
// ),
// ),
// ),
// );
// //
// // when(service.getContactById("03177ce0-4af4-11ed-9617-af8aa7a3796f"))
// // .thenAnswer((realInvocation) => Contact(
// // name: "John Doe",
// // addresses: [
// // const ContactAddressEntry(
// // coin: Coin.bitcoincash,
// // address: "some bch address",
// // label: "Bills")
// // ],
// // isFavorite: true));
// await widgetTester.tap(find.byType(RawMaterialButton));
// // verify(MockedFunctions().showDialog()).called(1);
// await widgetTester.pump();
// when(service.getContactById("03177ce0-4af4-11ed-9617-af8aa7a3796f"))
// .thenAnswer((realInvocation) => Contact(
// name: "John Doe",
// addresses: [
// const ContactAddressEntry(
// coin: Coin.bitcoincash,
// address: "some bch address",
// label: "Bills")
// ],
// isFavorite: true));
//
// expect(
// find.byWidget(const ContactPopUp(
// contactId: "03177ce0-4af4-11ed-9617-af8aa7a3796f")),
// findsOneWidget);
// // await widgetTester.pump();
// // // when(contact)
// // await widgetTester.pump();
// });
await widgetTester.tap(find.byType(RawMaterialButton));
});
// 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(
// serv,
// ),
// ],
// child: MaterialApp(
// theme: ThemeData(
// extensions: [
// StackColors.fromStackColorTheme(
// LightColors(),
// ),
// ],
// ),
// home: const AddressBookCard(
// contactId: "some id",
// ),
// ),
// ),
// );
//
// expect(find.text("John Doe"), findsOneWidget);
// expect(find.text(Coin.bitcoincash.ticker), findsOneWidget);
// });
// testWidgets("Test button press opens dialog", (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: "03177ce0-4af4-11ed-9617-af8aa7a3796f",
// ),
// ),
// ),
// );
// //
// // when(service.getContactById("03177ce0-4af4-11ed-9617-af8aa7a3796f"))
// // .thenAnswer((realInvocation) => Contact(
// // name: "John Doe",
// // addresses: [
// // const ContactAddressEntry(
// // coin: Coin.bitcoincash,
// // address: "some bch address",
// // label: "Bills")
// // ],
// // isFavorite: true));
// // await widgetTester.tap(find.byType(RawMaterialButton));
// // // when(contact)
// // await widgetTester.pump();
// });
}

View file

@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.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:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/widgets/custom_buttons/favorite_toggle.dart';
void main() {
testWidgets("Test widget build", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
ProviderScope(
overrides: [],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: FavoriteToggle(
onChanged: null,
key: key,
),
),
),
);
expect(find.byType(FavoriteToggle), findsOneWidget);
expect(find.byType(SvgPicture), findsOneWidget);
});
}

View file

@ -1,3 +1,4 @@
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
@ -6,8 +7,7 @@ import 'package:stackwallet/widgets/custom_loading_overlay.dart';
void main() {
testWidgets("Test wiget displays correct text", (widgetTester) async {
const customLoadingOverlay =
CustomLoadingOverlay(message: "Updating exchange rate", eventBus: null);
final eventBus = EventBus();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
@ -15,8 +15,9 @@ void main() {
StackColors.fromStackColorTheme(LightColors()),
],
),
home: const Material(
child: customLoadingOverlay,
home: Material(
child: CustomLoadingOverlay(
message: "Updating exchange rate", eventBus: eventBus),
),
),
);

View file

@ -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/utilities/util.dart';
import 'package:stackwallet/widgets/desktop/custom_text_button.dart';
void main() {
testWidgets("Test text button ", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: CustomTextButtonBase(
key: key,
width: 200,
height: 300,
textButton:
const TextButton(onPressed: null, child: Text("Some Text")),
),
),
),
);
expect(find.byType(CustomTextButtonBase), findsOneWidget);
});
}

View file

@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/pages_desktop_specific/home/my_stack_view/exit_to_my_stack_button.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
void main() {
testWidgets("Test DesktopAppBar widget", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: DesktopAppBar(
key: key,
isCompactHeight: false,
leading: const AppBarBackButton(),
trailing: const ExitToMyStackButton(),
center: const Text("Some Text"),
),
),
),
);
expect(find.byType(DesktopAppBar), findsOneWidget);
});
}

View file

@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockingjay/mockingjay.dart' as mockingjay;
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
void main() {
testWidgets("test DesktopDialog button pressed", (widgetTester) async {
final key = UniqueKey();
final navigator = mockingjay.MockNavigator();
await widgetTester.pumpWidget(
ProviderScope(
overrides: [],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: mockingjay.MockNavigatorProvider(
navigator: navigator,
child: DesktopDialogCloseButton(
key: key,
onPressedOverride: null,
)),
),
),
);
await widgetTester.tap(find.byType(AppBarIconButton));
await widgetTester.pumpAndSettle();
mockingjay.verify(() => navigator.pop()).called(1);
});
}

View file

@ -0,0 +1,30 @@
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/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
void main() {
testWidgets("test DesktopDialog builds", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: DesktopDialog(
key: key,
child: const DesktopDialogCloseButton(),
),
),
),
);
expect(find.byType(DesktopDialog), findsOneWidget);
});
}

View file

@ -0,0 +1,70 @@
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/desktop/desktop_scaffold.dart';
void main() {
testWidgets("test DesktopScaffold", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: DesktopScaffold(
key: key,
body: const SizedBox(),
),
),
),
);
});
testWidgets("Test MasterScaffold for non desktop", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: MasterScaffold(
key: key,
body: const SizedBox(),
appBar: AppBar(),
isDesktop: false,
),
),
),
);
});
testWidgets("Test MasterScaffold for desktop", (widgetTester) async {
final key = UniqueKey();
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: MasterScaffold(
key: key,
body: const SizedBox(),
appBar: AppBar(),
isDesktop: true,
),
),
),
);
});
}

View file

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.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/icon_widgets/addressbook_icon.dart';
void main() {
testWidgets("test address book icon widget", (widgetTester) async {
final key = UniqueKey();
final addressBookIcon = AddressBookIcon(
key: key,
);
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: addressBookIcon,
),
),
);
expect(find.byWidget(addressBookIcon), findsOneWidget);
expect(find.byType(SvgPicture), findsOneWidget);
});
}

View file

@ -18,6 +18,7 @@ import 'package:stackwallet/widgets/managed_favorite.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 'managed_favorite_test.mocks.dart';
@ -45,7 +46,8 @@ void main() {
.thenAnswer((realInvocation) => manager);
when(manager.isFavorite).thenAnswer((realInvocation) => false);
const managedFavorite = ManagedFavorite(walletId: "some wallet id");
final key = UniqueKey();
// const managedFavorite = ManagedFavorite(walletId: "some wallet id", key: key,);
await widgetTester.pumpWidget(
ProviderScope(
overrides: [
@ -59,8 +61,11 @@ void main() {
),
],
),
home: const Material(
child: managedFavorite,
home: Material(
child: ManagedFavorite(
walletId: "some wallet id",
key: key,
),
),
),
),

View file

@ -82,7 +82,7 @@ void main() {
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
name: "Some other node name",
id: "node id",
useSSL: true,
enabled: true,
@ -94,7 +94,7 @@ void main() {
NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
name: "Some other node name",
id: "node id",
useSSL: true,
enabled: true,
@ -122,7 +122,7 @@ void main() {
);
await tester.pumpAndSettle();
expect(find.text("Stack Default"), findsOneWidget);
expect(find.text("Some other node name"), findsOneWidget);
expect(find.text("Connected"), findsOneWidget);
expect(find.byType(Text), findsNWidgets(2));
expect(find.byType(SvgPicture), findsWidgets);

View file

@ -29,7 +29,7 @@ void main() {
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
name: "Some other name",
id: "node id",
useSSL: true,
enabled: true,
@ -41,7 +41,7 @@ void main() {
(realInvocation) => NodeModel(
host: "127.0.0.1",
port: 2000,
name: "Stack Default",
name: "Some other name",
id: "node id",
useSSL: true,
enabled: true,
@ -72,7 +72,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.text("Node options"), findsOneWidget);
expect(find.text("Stack Default"), findsOneWidget);
expect(find.text("Some other name"), findsOneWidget);
expect(find.text("Connected"), findsOneWidget);
expect(find.byType(SvgPicture), findsNWidgets(2));
expect(find.text("Details"), findsOneWidget);
@ -204,7 +204,6 @@ void main() {
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"));

View file

@ -0,0 +1,35 @@
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/shake/shake.dart';
void main() {
testWidgets("Widget build", (widgetTester) async {
await widgetTester.pumpWidget(
MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(LightColors()),
],
),
home: Material(
child: Shake(
animationRange: 10,
controller: ShakeController(),
animationDuration: const Duration(milliseconds: 200),
child: Column(
children: const [
Center(
child: Text("Enter Pin"),
)
],
)),
),
),
);
expect(find.byType(Shake), findsOneWidget);
expect(find.byType(Text), findsOneWidget);
});
}

View file

@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/trade_card.dart';
void main() {
testWidgets("Test Trade card builds", (widgetTester) async {
final trade = Trade(
uuid: "uuid",
tradeId: "trade id",
rateType: "Estimate rate",
direction: "",
timestamp: DateTime.parse("1662544771"),
updatedAt: DateTime.parse("1662544771"),
payInCurrency: "BTC",
payInAmount: "10",
payInAddress: "btc address",
payInNetwork: "",
payInExtraId: "",
payInTxid: "",
payOutCurrency: "xmr",
payOutAmount: "10",
payOutAddress: "xmr address",
payOutNetwork: "",
payOutExtraId: "",
payOutTxid: "",
refundAddress: "refund address",
refundExtraId: "",
status: "Failed",
exchangeName: "Some Exchange");
await widgetTester.pumpWidget(
ProviderScope(
overrides: [],
child: MaterialApp(
theme: ThemeData(
extensions: [
StackColors.fromStackColorTheme(
LightColors(),
),
],
),
home: TradeCard(trade: trade, onTap: () {}),
),
),
);
expect(find.byType(TradeCard), findsOneWidget);
expect(find.text("BTC → XMR"), findsOneWidget);
expect(find.text("Some Exchange"), findsOneWidget);
});
}

View file

@ -131,6 +131,99 @@ void main() {
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();