Files
social-app/apps/test/widget_test.dart
T
qzl e20b1905cb fix(apps): consolidate FormzInput validators and fix login screen
- Move FormzInput validators to core/form_inputs/form_inputs.dart
- Fix login_screen.dart syntax error (missing 'class' keyword)
- Remove unused _isLoading field
- Fix unnecessary const keywords
- Update login_cubit and register_cubit imports
- Remove duplicate FormzInput definitions from register_cubit
- Add Toast and Banner UI feedback system
- Remove legacy login/register screens (login_code, login_email, login_password, register_step2)
- Remove unused warning_banner widget
- Update tests for new error messages and DI setup
2026-02-25 18:00:02 +08:00

64 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:social_app/main.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_bloc.dart';
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
import 'package:social_app/features/auth/data/auth_repository.dart';
import 'package:social_app/core/di/injection.dart';
class MockAuthBloc extends Mock implements AuthBloc {}
class MockAuthRepository extends Mock implements AuthRepository {}
class FakeAuthState extends Fake implements AuthState {}
void main() {
setUpAll(() {
registerFallbackValue(FakeAuthState());
});
setUp(() async {
if (sl.isRegistered<AuthRepository>()) {
await sl.reset();
}
sl.registerSingleton<AuthRepository>(MockAuthRepository());
});
testWidgets('Login screen loads correctly', (WidgetTester tester) async {
final mockAuthBloc = MockAuthBloc();
when(() => mockAuthBloc.state).thenReturn(AuthInitial());
when(
() => mockAuthBloc.stream,
).thenAnswer((_) => Stream.value(AuthInitial()));
await tester.pumpWidget(LinksyApp(authBloc: mockAuthBloc));
expect(find.text('linksy'), findsOneWidget);
expect(find.text('登录'), findsOneWidget);
expect(find.text('还没有账号?去注册'), findsOneWidget);
});
testWidgets('Main content is vertically centered above footer', (
WidgetTester tester,
) async {
final mockAuthBloc = MockAuthBloc();
when(() => mockAuthBloc.state).thenReturn(AuthInitial());
when(
() => mockAuthBloc.stream,
).thenAnswer((_) => Stream.value(AuthInitial()));
await tester.pumpWidget(LinksyApp(authBloc: mockAuthBloc));
final safeAreaRect = tester.getRect(find.byType(SafeArea));
final mainRect = tester.getRect(
find.byKey(const Key('login_main_content')),
);
final footerRect = tester.getRect(find.byKey(const Key('login_footer')));
final topSpace = mainRect.top - safeAreaRect.top;
final bottomSpace = footerRect.top - mainRect.bottom;
expect((topSpace - bottomSpace).abs(), lessThanOrEqualTo(2));
});
}