mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
Widget testing add more tests
This commit is contained in:
parent
bb40d4b165
commit
7e5b149079
5 changed files with 2856 additions and 3 deletions
157
test/pages/send_view/send_view_test.dart
Normal file
157
test/pages/send_view/send_view_test.dart
Normal 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);
|
||||
});
|
||||
}
|
2626
test/pages/send_view/send_view_test.mocks.dart
Normal file
2626
test/pages/send_view/send_view_test.mocks.dart
Normal file
File diff suppressed because it is too large
Load diff
35
test/widget_tests/custom_buttons/favorite_toggle_test.dart
Normal file
35
test/widget_tests/custom_buttons/favorite_toggle_test.dart
Normal 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);
|
||||
});
|
||||
}
|
|
@ -46,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: [
|
||||
|
@ -60,8 +61,11 @@ void main() {
|
|||
),
|
||||
],
|
||||
),
|
||||
home: const Material(
|
||||
child: managedFavorite,
|
||||
home: Material(
|
||||
child: ManagedFavorite(
|
||||
walletId: "some wallet id",
|
||||
key: key,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -2,3 +2,34 @@ 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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue