Files
fanuzu/app/test/login_loading_test.dart
T

86 lines
2.8 KiB
Dart

import 'dart:async';
import 'package:fancake/core/i18n/app_locale.dart';
import 'package:fancake/core/theme/app_theme.dart';
import 'package:fancake/features/auth/auth.dart';
import 'package:fancake/features/auth/auth_repository.dart';
import 'package:fancake/features/auth/login_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
/// 소셜 로그인 진행 중(제공자 화면 복귀 뒤 서버 토큰 교환 포함) 화면 전체를 막고 진행 표시를 띄운다.
void main() {
for (final kind in AuthProviderKind.values.where(
(k) => k != AuthProviderKind.email,
)) {
testWidgets('${kind.name} — 진행 중 로딩 · 중복 입력 막음 · 실패하면 다시 누를 수 있다', (
tester,
) async {
var pending = Completer<AuthOutcome>();
final provider = _Provider(kind, () => pending.future);
final auth = AuthRepository(providers: [provider], releaseMode: true);
addTearDown(auth.dispose);
await tester.pumpWidget(
MaterialApp(
theme: buildAppTheme(),
locale: const Locale('ko'),
supportedLocales: appLocales,
localizationsDelegates: const [
RemoteL10nDelegate({}),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: SimpleLoginScreen(auth: auth),
),
);
await tester.pumpAndSettle();
final button = find.text(providerButtonLabel(kind));
expect(find.byType(BlockingProgress), findsNothing);
await tester.tap(button);
await tester.pump();
expect(find.byType(BlockingProgress), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
await tester.tap(button, warnIfMissed: false);
await tester.pump();
expect(provider.calls, 1);
pending.complete(const AuthFailed('E-AUTH-03', 'x'));
await tester.pumpAndSettle();
expect(find.byType(BlockingProgress), findsNothing);
pending = Completer<AuthOutcome>();
await tester.tap(button);
await tester.pump();
expect(provider.calls, 2);
pending.complete(const AuthCancelled());
await tester.pumpAndSettle();
});
}
}
final class _Provider implements SocialAuthProvider {
_Provider(this.provider, this._signIn);
@override
final AuthProviderKind provider;
final Future<AuthOutcome> Function() _signIn;
int calls = 0;
@override
bool get isLive => true;
@override
List<String> get missingConfig => const [];
@override
Future<AuthOutcome> signIn() {
calls += 1;
return _signIn();
}
@override
Future<void> signOut() async {}
}