feat(app): 接入金币充值与会员商品下单
This commit is contained in:
1 parent
ec2db6842e
commit
730e38622f
21 files changed
+1325
-1
No files matched your search
@@ -0,0 +1,105 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/order.dart';
|
||||
import 'package:fruitshorts/core/data/models/product.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/store_repository.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/store/recharge_page.dart';
|
||||
import 'package:fruitshorts/pages/store/vip_page.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('should_show_coin_packs_and_create_order_when_buying', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = _FakeStoreRepository();
|
||||
|
||||
await tester.pumpWidget(_app(RechargePage(repository: repository)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('550 Coins'), findsOneWidget);
|
||||
expect(find.textContaining('500 coins'), findsOneWidget);
|
||||
expect(find.textContaining('+50 bonus'), findsOneWidget);
|
||||
expect(find.text('Rp 15.000'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('store-buy-pack-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(repository.requestedTypes, ['COIN_PACK']);
|
||||
expect(repository.orderedProductIds, ['pack-1']);
|
||||
expect(find.textContaining('Order ORD1 created.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_show_vip_tiers_and_create_order_when_joining', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = _FakeStoreRepository();
|
||||
|
||||
await tester.pumpWidget(_app(VipPage(repository: repository)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('30-day VIP'), findsOneWidget);
|
||||
expect(find.text('Rp 99.000'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('store-buy-vip-1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(repository.requestedTypes, ['VIP']);
|
||||
expect(repository.orderedProductIds, ['vip-1']);
|
||||
expect(find.textContaining('Order ORD1 created.'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _app(Widget home) => MaterialApp(
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: home,
|
||||
);
|
||||
|
||||
class _FakeStoreRepository implements StoreRepository {
|
||||
final List<String?> requestedTypes = [];
|
||||
final List<String> orderedProductIds = [];
|
||||
|
||||
@override
|
||||
Future<List<AppProduct>> fetchProducts({String? type}) async {
|
||||
requestedTypes.add(type);
|
||||
if (type == AppProduct.vipType) {
|
||||
return const [
|
||||
AppProduct(
|
||||
id: 'vip-1',
|
||||
code: 'vip_30',
|
||||
name: 'Monthly VIP',
|
||||
type: AppProduct.vipType,
|
||||
displayPrice: 'Rp 99.000',
|
||||
vipDays: 30,
|
||||
),
|
||||
];
|
||||
}
|
||||
return const [
|
||||
AppProduct(
|
||||
id: 'pack-1',
|
||||
code: 'coin_550',
|
||||
name: '550 Coins',
|
||||
type: AppProduct.coinPackType,
|
||||
coinAmount: 500,
|
||||
bonusCoin: 50,
|
||||
totalCoin: 550,
|
||||
displayPrice: 'Rp 15.000',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AppOrder> createOrder(String productId) async {
|
||||
orderedProductIds.add(productId);
|
||||
return const AppOrder(
|
||||
id: 'order-1',
|
||||
orderNo: 'ORD1',
|
||||
productName: 'Coin pack',
|
||||
coinAmount: 550,
|
||||
status: AppOrder.created,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user