mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-03 11:46:41 +00:00
Widget testing, add more tests
This commit is contained in:
parent
777ca516bf
commit
c8ec409efa
8 changed files with 4610 additions and 40 deletions
66
test/widget_tests/managed_favorite_test.dart
Normal file
66
test/widget_tests/managed_favorite_test.dart
Normal file
|
@ -0,0 +1,66 @@
|
|||
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/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||
import 'package:stackwallet/services/coins/manager.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
import 'package:stackwallet/services/wallets.dart';
|
||||
import 'package:stackwallet/services/wallets_service.dart';
|
||||
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 'managed_favorite_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([
|
||||
Wallets,
|
||||
WalletsService,
|
||||
BitcoinWallet
|
||||
], customMocks: [
|
||||
MockSpec<NodeService>(returnNullOnMissingStub: true),
|
||||
MockSpec<Manager>(returnNullOnMissingStub: true),
|
||||
MockSpec<CoinServiceAPI>(returnNullOnMissingStub: true),
|
||||
// MockSpec<WalletsService>(returnNullOnMissingStub: true),
|
||||
])
|
||||
void main() {
|
||||
testWidgets("Test wallet info row displays correctly", (widgetTester) async {
|
||||
final wallets = MockWallets();
|
||||
final CoinServiceAPI wallet = MockBitcoinWallet();
|
||||
when(wallet.coin).thenAnswer((_) => Coin.bitcoin);
|
||||
when(wallet.walletName).thenAnswer((_) => "some wallet");
|
||||
when(wallet.walletId).thenAnswer((_) => "some wallet id");
|
||||
|
||||
final manager = Manager(wallet);
|
||||
when(wallets.getManager("some wallet id"))
|
||||
.thenAnswer((realInvocation) => manager);
|
||||
|
||||
when(manager.isFavorite).thenAnswer((realInvocation) => false);
|
||||
const managedFavorite = ManagedFavorite(walletId: "some wallet id");
|
||||
await widgetTester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
walletsChangeNotifierProvider.overrideWithValue(wallets),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(
|
||||
LightColors(),
|
||||
),
|
||||
],
|
||||
),
|
||||
home: const Material(
|
||||
child: managedFavorite,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ManagedFavorite), findsOneWidget);
|
||||
});
|
||||
}
|
2231
test/widget_tests/managed_favorite_test.mocks.dart
Normal file
2231
test/widget_tests/managed_favorite_test.mocks.dart
Normal file
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@ import 'table_view_row_test.mocks.dart';
|
|||
MockSpec<CoinServiceAPI>(returnNullOnMissingStub: true)
|
||||
])
|
||||
void main() {
|
||||
testWidgets('Blah blah', (widgetTester) async {
|
||||
testWidgets('Test table view row', (widgetTester) async {
|
||||
final mockWallet = MockWallets();
|
||||
final CoinServiceAPI wallet = MockBitcoinWallet();
|
||||
when(wallet.coin).thenAnswer((_) => Coin.bitcoin);
|
||||
|
@ -71,22 +71,6 @@ void main() {
|
|||
),
|
||||
);
|
||||
|
||||
// await widgetTester.pumpWidget(
|
||||
// MaterialApp(
|
||||
// theme: ThemeData(
|
||||
// extensions: [
|
||||
// StackColors.fromStackColorTheme(LightColors()),
|
||||
// ],
|
||||
// ),
|
||||
// home: Material(
|
||||
// child: TableViewRow(cells: [
|
||||
// for (int j = 1; j <= 5; j++)
|
||||
// TableViewCell(flex: 16, child: Text("Some Text ${j}"))
|
||||
// ], expandingChild: CoinWalletsTable(walletIds: walletIds)),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
|
||||
expect(find.text("Some Text 1"), findsOneWidget);
|
||||
expect(find.byType(TableViewRow), findsWidgets);
|
||||
expect(find.byType(TableViewCell), findsWidgets);
|
||||
|
|
|
@ -351,13 +351,12 @@ void main() {
|
|||
|
||||
when(wallet.coin).thenAnswer((_) => Coin.firo);
|
||||
|
||||
when(wallets.getManager("wallet-id"))
|
||||
when(wallets.getManager("wallet id"))
|
||||
.thenAnswer((realInvocation) => Manager(wallet));
|
||||
|
||||
mockingjay
|
||||
.when(() => navigator.push(mockingjay.any(
|
||||
that: mockingjay.isRoute(
|
||||
whereName: equals("/transactiondetailsview")))))
|
||||
.when(() => navigator.pushNamed("/transactionDetails",
|
||||
arguments: Tuple3(tx, Coin.firo, "wallet id")))
|
||||
.thenAnswer((_) async => {});
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -377,7 +376,7 @@ void main() {
|
|||
),
|
||||
home: mockingjay.MockNavigatorProvider(
|
||||
navigator: navigator,
|
||||
child: TransactionCard(transaction: tx, walletId: "wallet-id")),
|
||||
child: TransactionCard(transaction: tx, walletId: "wallet id")),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -386,11 +385,11 @@ void main() {
|
|||
|
||||
await tester.tap(find.byType(GestureDetector));
|
||||
await tester.pump();
|
||||
//
|
||||
|
||||
// verify(mockManager.addListener(any)).called(1);
|
||||
// verify(mockLocaleService.addListener(any)).called(1);
|
||||
verify(mockLocaleService.addListener(any)).called(1);
|
||||
// verify(mockNotesService.addListener(any)).called(1);
|
||||
//
|
||||
|
||||
// verify(mockNotesService.getNoteFor(txid: "some txid")).called(1);
|
||||
//
|
||||
// verify(mockManager.fiatCurrency).called(1);
|
||||
|
@ -405,10 +404,10 @@ void main() {
|
|||
//
|
||||
// mockingjay
|
||||
// .verify(() => navigator.push(mockingjay.any(
|
||||
// that: mockingjay.isRoute(
|
||||
// whereName: equals("/transactiondetailsview")))))
|
||||
// that:
|
||||
// mockingjay.isRoute(whereName: equals("/transactionDetails"), whereArguments: equals(Tuple3(item1, item2, item3))))))
|
||||
// .called(1);
|
||||
//
|
||||
|
||||
// mockingjay.verifyNoMoreInteractions(navigator);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import 'wallet_card_test.mocks.dart';
|
|||
|
||||
@GenerateMocks([Wallets, BitcoinWallet, LocaleService])
|
||||
void main() {
|
||||
testWidgets("When pop popOver redirect", (widgetTester) async {
|
||||
testWidgets("Test button pressed", (widgetTester) async {
|
||||
final CoinServiceAPI wallet = MockBitcoinWallet();
|
||||
mockito.when(wallet.walletId).thenAnswer((realInvocation) => "wallet id");
|
||||
mockito.when(wallet.coin).thenAnswer((realInvocation) => Coin.bitcoin);
|
||||
|
@ -50,15 +50,6 @@ void main() {
|
|||
arguments: Tuple2("wallet id", managerProvider)))
|
||||
.thenAnswer((_) async => {});
|
||||
|
||||
// mockingjay
|
||||
// .when(() => navigator.push(mockingjay.any(
|
||||
// that: mockingjay.isRoute(
|
||||
// whereName: equals("/wallets"),
|
||||
// whereArguments: equals(Tuple2(
|
||||
// "wallet id", wallets.getManagerProvider("wallet id")))))))
|
||||
// .thenAnswer((_) async => {});
|
||||
// mockingjay.when(() => navigator.pop()).thenAnswer((invocation) {});
|
||||
|
||||
await widgetTester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
|
@ -79,10 +70,9 @@ void main() {
|
|||
),
|
||||
),
|
||||
);
|
||||
//
|
||||
|
||||
expect(find.byType(MaterialButton), findsOneWidget);
|
||||
await widgetTester.tap(find.byType(MaterialButton));
|
||||
// });
|
||||
});
|
||||
|
||||
testWidgets('test widget loads correctly', (widgetTester) async {
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
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/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||
import 'package:stackwallet/services/coins/manager.dart';
|
||||
import 'package:stackwallet/services/node_service.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/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/theme/light_colors.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
|
||||
import 'wallet_info_row_balance_future_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([
|
||||
Wallets,
|
||||
WalletsService,
|
||||
BitcoinWallet
|
||||
], customMocks: [
|
||||
MockSpec<NodeService>(returnNullOnMissingStub: true),
|
||||
MockSpec<Manager>(returnNullOnMissingStub: true),
|
||||
MockSpec<CoinServiceAPI>(returnNullOnMissingStub: true),
|
||||
// MockSpec<WalletsService>(returnNullOnMissingStub: true),
|
||||
])
|
||||
void main() {
|
||||
testWidgets("Test wallet info row balance loads correctly",
|
||||
(widgetTester) async {
|
||||
final wallets = MockWallets();
|
||||
final CoinServiceAPI wallet = MockBitcoinWallet();
|
||||
when(wallet.coin).thenAnswer((_) => Coin.bitcoin);
|
||||
when(wallet.walletName).thenAnswer((_) => "some wallet");
|
||||
when(wallet.walletId).thenAnswer((_) => "some-wallet-id");
|
||||
|
||||
final manager = Manager(wallet);
|
||||
when(wallets.getManagerProvider("some-wallet-id")).thenAnswer(
|
||||
(realInvocation) => ChangeNotifierProvider((ref) => manager));
|
||||
|
||||
const walletInfoRowBalance =
|
||||
WalletInfoRowBalanceFuture(walletId: "some-wallet-id");
|
||||
await widgetTester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
walletsChangeNotifierProvider.overrideWithValue(wallets),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(
|
||||
LightColors(),
|
||||
),
|
||||
],
|
||||
),
|
||||
home: const Material(
|
||||
child: walletInfoRowBalance,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
//
|
||||
// expect(find.text("some wallet"), findsOneWidget);
|
||||
expect(find.byType(WalletInfoRowBalanceFuture), findsOneWidget);
|
||||
});
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -64,5 +64,6 @@ void main() {
|
|||
);
|
||||
|
||||
expect(find.text("some wallet"), findsOneWidget);
|
||||
expect(find.byType(WalletInfoRowBalanceFuture), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue