102 lines
3.3 KiB
Dart
102 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:sxchnge_kyc/sxchnge_kyc.dart';
|
|
|
|
import 'package:sxchnge_wallet/sxchnge_wallet.dart';
|
|
|
|
import 'package:sxchnge_app/main.dart';
|
|
|
|
const destinationLabel =
|
|
'Saved bank ending 1234 — Personal current account for daily transfers and reimbursements';
|
|
|
|
class LiveWallet extends DummyWalletService {
|
|
LiveWallet({this.hasMethod = true})
|
|
: super(DummyIdentityService(delay: Duration.zero), delay: Duration.zero);
|
|
final bool hasMethod;
|
|
String? received;
|
|
@override
|
|
bool get isSimulated => false;
|
|
@override
|
|
Future<WalletSnapshot> fetch() async => WalletSnapshot(
|
|
accounts: [
|
|
CurrencyAccount(
|
|
id: 'real-account',
|
|
currency: 'EUR',
|
|
precision: 2,
|
|
available: 7500,
|
|
payoutMethod: hasMethod ? 'method-ref' : '',
|
|
payoutLabel: hasMethod ? destinationLabel : '',
|
|
canFund: false,
|
|
),
|
|
],
|
|
operations: [],
|
|
);
|
|
@override
|
|
Future<Quote> quote(TransferRequest request) async {
|
|
received = request.recipient;
|
|
return Quote(
|
|
id: 'quote',
|
|
request: TransferRequest(
|
|
kind: request.kind,
|
|
source: request.source,
|
|
amount: request.amount,
|
|
recipient: destinationLabel,
|
|
),
|
|
fee: 100,
|
|
debit: request.amount + 100,
|
|
credit: request.amount,
|
|
expiresAt: DateTime.now().add(const Duration(minutes: 5)),
|
|
rateNumerator: 1,
|
|
rateDenominator: 1,
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
for (final hasMethod in [true, false]) {
|
|
testWidgets(
|
|
'backend payout ${hasMethod ? 'reviews saved destination' : 'explains missing destination'} at narrow width',
|
|
(t) async {
|
|
t.view.physicalSize = const Size(320, 1100);
|
|
t.view.devicePixelRatio = 1;
|
|
t.platformDispatcher.textScaleFactorTestValue = 1.6;
|
|
t.platformDispatcher.defaultRouteNameTestValue = '/payout';
|
|
addTearDown(t.view.resetPhysicalSize);
|
|
addTearDown(t.view.resetDevicePixelRatio);
|
|
addTearDown(t.platformDispatcher.clearTextScaleFactorTestValue);
|
|
addTearDown(t.platformDispatcher.clearDefaultRouteNameTestValue);
|
|
final wallet = LiveWallet(hasMethod: hasMethod);
|
|
await t.pumpWidget(SxchngeApp(walletService: wallet));
|
|
await t.pumpAndSettle();
|
|
expect(find.byKey(const ValueKey('transfer-recipient')), findsNothing);
|
|
await t.enterText(find.byKey(const ValueKey('transfer-amount')), '20');
|
|
final review = find.byKey(const ValueKey('transfer-review'));
|
|
await t.ensureVisible(review);
|
|
if (hasMethod) {
|
|
expect(find.text(destinationLabel), findsOneWidget);
|
|
await t.tap(review);
|
|
await t.pumpAndSettle();
|
|
expect(wallet.received, 'method-ref');
|
|
expect(find.text(destinationLabel), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('transfer-confirm')),
|
|
findsOneWidget,
|
|
);
|
|
} else {
|
|
expect(t.widget<FilledButton>(review).onPressed, isNull);
|
|
expect(
|
|
find.text(
|
|
'No payout destination is set up for this account. Contact support to add one.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
}
|
|
expect(t.takeException(), isNull);
|
|
await t.pumpWidget(const SizedBox.shrink());
|
|
},
|
|
);
|
|
}
|
|
}
|