94 lines
3.5 KiB
Dart
94 lines
3.5 KiB
Dart
// 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() {
|
|
setUp(() {
|
|
SharedPreferencesAsyncPlatform.instance =
|
|
InMemorySharedPreferencesAsync.empty();
|
|
});
|
|
|
|
testWidgets('should_show_sign_up_subtitle_and_password_rule_when_switched', (
|
|
tester,
|
|
) async {
|
|
await _pumpAuth(tester);
|
|
final l10n = await AppLocalizations.delegate.load(const Locale('en'));
|
|
|
|
expect(find.byKey(const Key('auth-password-rule')), findsNothing);
|
|
await tester.tap(find.byKey(const Key('auth-mode-sign-up')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text(l10n.authSignUpSubtitle), findsOneWidget);
|
|
final rule = find.byKey(const Key('auth-password-rule'));
|
|
expect(rule, findsOneWidget);
|
|
expect(tester.widget<Text>(rule).data, l10n.authPasswordHint);
|
|
});
|
|
|
|
testWidgets('should_apply_semantic_error_border_when_email_is_invalid', (
|
|
tester,
|
|
) async {
|
|
await _pumpAuth(tester);
|
|
await tester.enterText(find.byKey(const Key('auth-email')), 'invalid');
|
|
await tester.enterText(find.byKey(const Key('auth-password')), 'abcd1234');
|
|
await tester.tap(find.byKey(const Key('auth-submit')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final emailFinder = find.byKey(const Key('auth-email'));
|
|
final email = tester.widget<TextField>(emailFinder);
|
|
final errorBorder = email.decoration!.errorBorder! as OutlineInputBorder;
|
|
final scheme = Theme.of(tester.element(emailFinder)).colorScheme;
|
|
expect(errorBorder.borderSide.color, scheme.error);
|
|
expect(errorBorder.borderSide.width, 1);
|
|
});
|
|
}
|
|
|
|
Future<void> _pumpAuth(WidgetTester tester) async {
|
|
final auth = AuthController(
|
|
AuthApi(
|
|
ApiClient(
|
|
baseUrl: 'http://127.0.0.1:1',
|
|
adapter: FakeHttpAdapter((_) async => FakeHttpResponse('{}', 500)),
|
|
),
|
|
),
|
|
AuthSessionStore(),
|
|
);
|
|
await tester.pumpWidget(
|
|
MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider<AuthController>.value(value: auth),
|
|
ChangeNotifierProvider<AppConfigController>.value(
|
|
value: await fakeAppConfigController(),
|
|
),
|
|
Provider<Haptics>.value(value: FakeHaptics()),
|
|
],
|
|
child: MaterialApp(
|
|
locale: const Locale('en'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const AuthPage(),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.ensureVisible(find.byKey(const Key('auth-entry-email')));
|
|
await tester.tap(find.byKey(const Key('auth-entry-email')));
|
|
await tester.pumpAndSettle();
|
|
}
|