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 pending = Completer(); int calls = 0; @override Future 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(); 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()); }, ); } } }