Merge pull request 'Set up RUB, USDT and USDC accounts automatically' (#73) from wallet-72 into main
This commit was merged in pull request #73.
This commit is contained in:
commit
3b551f1565
21 files changed
+687
-62
No files matched your search
@@ -0,0 +1,104 @@
|
||||
import 'dart:async';
|
||||
|
||||
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';
|
||||
import 'package:sxchnge_app/providers/locale.dart';
|
||||
|
||||
class SetupWallet extends DummyWalletService {
|
||||
SetupWallet(String locale)
|
||||
: super(
|
||||
DummyIdentityService(delay: Duration.zero),
|
||||
delay: Duration.zero,
|
||||
initialLocale: locale,
|
||||
);
|
||||
|
||||
Completer<WalletSnapshot> pending = Completer<WalletSnapshot>();
|
||||
int calls = 0;
|
||||
|
||||
@override
|
||||
Future<WalletSnapshot> fetch() {
|
||||
calls++;
|
||||
return pending.future;
|
||||
}
|
||||
}
|
||||
|
||||
WalletSnapshot readyAccounts() => WalletSnapshot(
|
||||
accounts: [
|
||||
for (final currency in ['RUB', 'USDT', 'USDC'])
|
||||
CurrencyAccount(
|
||||
id: currency.toLowerCase(),
|
||||
currency: currency,
|
||||
precision: currency == 'RUB' ? 2 : 6,
|
||||
available: 0,
|
||||
),
|
||||
],
|
||||
operations: [],
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final locale in ['en', 'ru']) {
|
||||
for (final path in ['/accounts', '/top-up', '/exchange', '/payout']) {
|
||||
testWidgets(
|
||||
'$path recovers account setup in $locale at narrow width and large text',
|
||||
(t) async {
|
||||
t.view.physicalSize = const Size(320, 1100);
|
||||
t.view.devicePixelRatio = 1;
|
||||
t.platformDispatcher.textScaleFactorTestValue = 1.6;
|
||||
t.platformDispatcher.defaultRouteNameTestValue = path;
|
||||
addTearDown(t.view.resetPhysicalSize);
|
||||
addTearDown(t.view.resetDevicePixelRatio);
|
||||
addTearDown(t.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
addTearDown(t.platformDispatcher.clearDefaultRouteNameTestValue);
|
||||
final wallet = SetupWallet(locale);
|
||||
await t.pumpWidget(
|
||||
SxchngeApp(
|
||||
walletService: wallet,
|
||||
localeProvider: LocaleProvider(initialLocale: Locale(locale)),
|
||||
),
|
||||
);
|
||||
await t.pump();
|
||||
await t.pump();
|
||||
final loading = locale == 'en'
|
||||
? 'Getting your RUB, USDT and USDC accounts ready…'
|
||||
: 'Подготавливаем ваши счета в RUB, USDT и USDC…';
|
||||
final failed = locale == 'en'
|
||||
? 'We couldn’t load your currency accounts. Try again to continue.'
|
||||
: 'Не удалось загрузить валютные счета. Повторите попытку, чтобы продолжить.';
|
||||
final retry = locale == 'en' ? 'Try again' : 'Повторить попытку';
|
||||
expect(find.text(loading), findsOneWidget);
|
||||
expect(find.textContaining('Contact support'), findsNothing);
|
||||
expect(t.takeException(), isNull);
|
||||
wallet.pending.completeError(
|
||||
const WalletException(WalletError.unavailable),
|
||||
);
|
||||
await t.pumpAndSettle();
|
||||
expect(find.text(failed), findsOneWidget);
|
||||
expect(find.text(loading), findsNothing);
|
||||
expect(find.text(retry), findsOneWidget);
|
||||
expect(t.takeException(), isNull);
|
||||
wallet.pending = Completer<WalletSnapshot>();
|
||||
await t.ensureVisible(find.text(retry));
|
||||
await t.tap(find.text(retry));
|
||||
await t.pump();
|
||||
expect(wallet.calls, 2);
|
||||
expect(find.text(loading), findsOneWidget);
|
||||
expect(find.text(failed), findsNothing);
|
||||
wallet.pending.complete(readyAccounts());
|
||||
await t.pumpAndSettle();
|
||||
expect(find.text(loading), findsNothing);
|
||||
expect(find.text(failed), findsNothing);
|
||||
expect(find.text('RUB'), findsWidgets);
|
||||
expect(t.takeException(), isNull);
|
||||
await t.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user