2023-09-12 16:41:49 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-04-09 23:02:11 +00:00
|
|
|
import 'package:decimal/decimal.dart';
|
2022-10-13 18:40:19 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:mockito/annotations.dart';
|
2022-10-16 06:50:10 +00:00
|
|
|
import 'package:mockito/mockito.dart' as mockito;
|
2023-02-23 20:08:07 +00:00
|
|
|
import 'package:stackwallet/models/balance.dart';
|
2023-05-12 20:02:04 +00:00
|
|
|
import 'package:stackwallet/models/isar/stack_theme.dart';
|
2022-10-13 18:40:19 +00:00
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
|
|
|
import 'package:stackwallet/services/coins/bitcoin/bitcoin_wallet.dart';
|
|
|
|
import 'package:stackwallet/services/coins/coin_service.dart';
|
2023-11-04 01:18:22 +00:00
|
|
|
|
2022-10-16 06:50:10 +00:00
|
|
|
import 'package:stackwallet/services/locale_service.dart';
|
2022-10-13 18:40:19 +00:00
|
|
|
import 'package:stackwallet/services/wallets.dart';
|
2023-09-12 16:41:49 +00:00
|
|
|
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-05-12 20:02:04 +00:00
|
|
|
import 'package:stackwallet/themes/theme_service.dart';
|
2023-04-09 23:02:11 +00:00
|
|
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
2022-10-13 18:40:19 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/widgets/wallet_card.dart';
|
|
|
|
|
2023-05-12 20:02:04 +00:00
|
|
|
import '../sample_data/theme_json.dart';
|
2022-10-13 18:40:19 +00:00
|
|
|
import 'wallet_card_test.mocks.dart';
|
|
|
|
|
2023-04-09 23:02:11 +00:00
|
|
|
/// quick amount constructor wrapper. Using an int is bad practice but for
|
|
|
|
/// testing with small amounts this should be fine
|
|
|
|
Amount _a(int i) => Amount.fromDecimal(
|
|
|
|
Decimal.fromInt(i),
|
|
|
|
fractionDigits: 8,
|
|
|
|
);
|
2022-10-13 18:40:19 +00:00
|
|
|
|
2023-05-12 20:02:04 +00:00
|
|
|
@GenerateMocks([
|
|
|
|
Wallets,
|
|
|
|
BitcoinWallet,
|
|
|
|
LocaleService,
|
|
|
|
ThemeService,
|
|
|
|
])
|
2022-10-13 18:40:19 +00:00
|
|
|
void main() {
|
|
|
|
testWidgets('test widget loads correctly', (widgetTester) async {
|
|
|
|
final CoinServiceAPI wallet = MockBitcoinWallet();
|
2023-05-12 20:02:04 +00:00
|
|
|
final mockThemeService = MockThemeService();
|
|
|
|
|
|
|
|
mockito.when(mockThemeService.getTheme(themeId: "light")).thenAnswer(
|
|
|
|
(_) => StackTheme.fromJson(
|
|
|
|
json: lightThemeJsonMap,
|
|
|
|
),
|
|
|
|
);
|
2022-10-16 06:50:10 +00:00
|
|
|
mockito.when(wallet.walletId).thenAnswer((realInvocation) => "wallet id");
|
|
|
|
mockito.when(wallet.coin).thenAnswer((realInvocation) => Coin.bitcoin);
|
|
|
|
mockito
|
|
|
|
.when(wallet.walletName)
|
|
|
|
.thenAnswer((realInvocation) => "wallet name");
|
2023-02-23 20:08:07 +00:00
|
|
|
mockito.when(wallet.balance).thenAnswer(
|
|
|
|
(_) => Balance(
|
2023-04-09 23:02:11 +00:00
|
|
|
total: _a(0),
|
|
|
|
spendable: _a(0),
|
|
|
|
blockedTotal: _a(0),
|
|
|
|
pendingSpendable: _a(0),
|
2023-02-23 20:08:07 +00:00
|
|
|
),
|
|
|
|
);
|
2022-10-13 18:40:19 +00:00
|
|
|
|
|
|
|
final wallets = MockWallets();
|
2023-11-03 19:46:55 +00:00
|
|
|
final wallet = Manager(wallet);
|
2022-10-13 18:40:19 +00:00
|
|
|
|
2022-10-16 06:50:10 +00:00
|
|
|
mockito.when(wallets.getManagerProvider("wallet id")).thenAnswer(
|
2022-10-13 18:40:19 +00:00
|
|
|
(realInvocation) => ChangeNotifierProvider((ref) => manager));
|
|
|
|
|
2023-04-10 15:44:38 +00:00
|
|
|
const walletSheetCard = SimpleWalletCard(
|
2022-10-13 18:40:19 +00:00
|
|
|
walletId: "wallet id",
|
|
|
|
);
|
|
|
|
|
|
|
|
await widgetTester.pumpWidget(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [
|
2023-10-31 17:15:59 +00:00
|
|
|
pWallets.overrideWithValue(wallets),
|
2023-05-12 20:02:04 +00:00
|
|
|
pThemeService.overrideWithValue(mockThemeService),
|
2023-09-12 16:41:49 +00:00
|
|
|
coinIconProvider.overrideWithProvider(
|
|
|
|
(argument) => Provider<String>((_) =>
|
|
|
|
"${Directory.current.path}/test/sample_data/light/assets/dummy.svg"),
|
|
|
|
),
|
2022-10-13 18:40:19 +00:00
|
|
|
],
|
|
|
|
child: MaterialApp(
|
|
|
|
theme: ThemeData(
|
|
|
|
extensions: [
|
2023-05-08 17:59:00 +00:00
|
|
|
StackColors.fromStackColorTheme(
|
|
|
|
StackTheme.fromJson(
|
2023-05-12 20:02:04 +00:00
|
|
|
json: lightThemeJsonMap,
|
2023-05-08 17:59:00 +00:00
|
|
|
),
|
|
|
|
),
|
2022-10-13 18:40:19 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
home: const Material(
|
|
|
|
child: walletSheetCard,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-01-20 16:22:18 +00:00
|
|
|
|
|
|
|
await widgetTester.pumpAndSettle();
|
|
|
|
|
2022-10-13 18:40:19 +00:00
|
|
|
expect(find.byWidget(walletSheetCard), findsOneWidget);
|
|
|
|
});
|
|
|
|
}
|