102 lines
3.0 KiB
Dart
102 lines
3.0 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:fruitshorts/core/data/models/wallet.dart';
|
|
import 'package:fruitshorts/core/data/repositories/commerce_repository.dart';
|
|
import 'package:fruitshorts/core/data/services/wallet_controller.dart';
|
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
|
import 'package:fruitshorts/pages/wallet/wallet_page.dart';
|
|
|
|
void main() {
|
|
testWidgets('should_show_server_balance_and_ledger_when_wallet_opens', (
|
|
tester,
|
|
) async {
|
|
final controller = WalletController(_FakeCommerceRepository());
|
|
|
|
await tester.pumpWidget(
|
|
ChangeNotifierProvider<WalletController>.value(
|
|
value: controller,
|
|
child: MaterialApp(
|
|
locale: const Locale('en'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const WalletPage(),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('wallet-balance')), findsOneWidget);
|
|
expect(
|
|
tester.widget<Text>(find.byKey(const Key('wallet-balance'))).data,
|
|
'320',
|
|
);
|
|
expect(find.text('Episode unlock'), findsOneWidget);
|
|
expect(find.text('-50'), findsOneWidget);
|
|
expect(find.byKey(const Key('wallet-ledger-11')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('should_show_empty_ledger_copy_when_wallet_has_no_entries', (
|
|
tester,
|
|
) async {
|
|
final controller = WalletController(
|
|
_FakeCommerceRepository(includeLedger: false),
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
ChangeNotifierProvider<WalletController>.value(
|
|
value: controller,
|
|
child: MaterialApp(
|
|
locale: const Locale('en'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const WalletPage(),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('No coin activity yet.'), findsOneWidget);
|
|
});
|
|
}
|
|
|
|
class _FakeCommerceRepository implements CommerceRepository {
|
|
_FakeCommerceRepository({this.includeLedger = true});
|
|
|
|
final bool includeLedger;
|
|
|
|
@override
|
|
Future<WalletSnapshot> fetchWallet() async => WalletSnapshot(
|
|
wallet: const CoinWallet(
|
|
coinBalance: 320,
|
|
totalRechargedCoin: 500,
|
|
totalConsumedCoin: 180,
|
|
totalRefundedCoin: 0,
|
|
),
|
|
ledger: includeLedger
|
|
? [
|
|
CoinLedgerEntry(
|
|
id: '11',
|
|
changeAmount: -50,
|
|
balanceAfter: 320,
|
|
bizType: 'UNLOCK',
|
|
remark: '',
|
|
createdAt: DateTime(2026, 10, 19, 10),
|
|
),
|
|
]
|
|
: const [],
|
|
);
|
|
|
|
@override
|
|
Future<UnlockResult> unlock(String episodeId) async =>
|
|
const UnlockResult(
|
|
unlocked: true,
|
|
accessType: 'UNLOCKED',
|
|
coinCost: 50,
|
|
coinBalance: 270,
|
|
);
|
|
}
|