import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ikar/backend/api.dart'; import 'package:ikar/backend/modules/account.dart'; import 'package:ikar/frontend/screens/auth/registration_screen.dart'; import 'package:ikar/l10n/app_localizations.dart'; class _Api extends Api { @override Stream get stateStream => const Stream.empty(); } class _Account extends AccountModule { _Account(super.api); int registrations = 0; final loginAttempts = <(int?, String?)>[]; @override Future completeRegistration({ required String token, required String firstName, String? lastName, int? photoId, }) async { registrations++; expect(token, 'registration-token'); expect(firstName, 'New'); return 42; } @override Future login({ int? accountId, String? token, LoginSyncParams? syncParams, }) async { loginAttempts.add((accountId, token)); throw StateError('Synthetic network interruption'); } } void main() { testWidgets( 'failed first login retries saved session without registering again', (tester) async { final api = _Api(); final account = _Account(api); await tester.pumpWidget( MaterialApp( localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, locale: const Locale('ru'), home: RegistrationScreen( phoneNumber: '+7 999 000-00-00', registerToken: 'registration-token', presetAvatars: const [], account: account, ), ), ); await tester.enterText(find.byType(TextField).first, ' New '); await tester.pump(); await tester.tap(find.byType(FloatingActionButton)); await tester.pump(); await tester.pump(const Duration(milliseconds: 300)); expect(account.registrations, 1); expect(account.loginAttempts, [(42, null)]); expect( tester.widget(find.byType(TextField).first).enabled, isFalse, ); await tester.tap(find.byType(FloatingActionButton)); await tester.pump(); expect(account.registrations, 1); expect(account.loginAttempts, [(42, null), (42, null)]); await tester.pump(const Duration(seconds: 6)); await tester.pumpWidget(const SizedBox()); await tester.pumpAndSettle(); await api.dispose(); }, ); }