// Author: fruit.com.cn import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:fruitshorts/core/data/remote/api_client.dart'; import 'package:fruitshorts/core/data/remote/auth_api.dart'; import 'package:fruitshorts/core/data/services/app_config_controller.dart'; import 'package:fruitshorts/core/data/services/auth_controller.dart'; import 'package:fruitshorts/core/data/services/auth_session_store.dart'; import 'package:fruitshorts/core/platform/haptics.dart'; import 'package:fruitshorts/l10n/app_localizations.dart'; import 'package:fruitshorts/pages/auth/auth_view.dart'; import '../support/fake_app_config.dart'; import '../support/fake_haptics.dart'; import '../support/fake_http_adapter.dart'; void main() { testWidgets('should_show_real_login_entries_and_open_phone_sheet', ( tester, ) async { SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); final auth = AuthController( AuthApi( ApiClient( baseUrl: 'http://127.0.0.1:1', adapter: FakeHttpAdapter((_) async => FakeHttpResponse('{}', 500)), ), ), AuthSessionStore(), ); await tester.pumpWidget( MultiProvider( providers: [ ChangeNotifierProvider.value(value: auth), ChangeNotifierProvider.value( value: await fakeAppConfigController(), ), Provider.value(value: FakeHaptics()), ], child: MaterialApp( locale: const Locale('en'), localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: const AuthPage(), ), ), ); await tester.pumpAndSettle(); expect(find.byKey(const Key('auth-entry-google')), findsNothing); expect(find.byKey(const Key('auth-entry-phone')), findsOneWidget); expect(find.byKey(const Key('auth-entry-email')), findsOneWidget); expect(find.byKey(const Key('auth-legal')), findsOneWidget); expect( tester.getTopLeft(find.byKey(const Key('auth-landing'))).dy, lessThan(80), ); await tester.tap(find.byKey(const Key('auth-entry-phone'))); await tester.pumpAndSettle(); expect(find.byKey(const Key('phone-auth-sheet')), findsOneWidget); await tester.tapAt(const Offset(8, 8)); await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('auth-entry-email'))); await tester.pumpAndSettle(); expect(find.byKey(const Key('auth-email')), findsOneWidget); expect(find.byKey(const Key('auth-password')), findsOneWidget); }); }