mirror of
https://github.com/Dvorinka/1356.git
synced 2026-06-04 20:12:56 +00:00
small fix, don't worry about it
This commit is contained in:
@@ -3,10 +3,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lifetimer/features/auth/application/auth_controller.dart';
|
||||
import 'package:lifetimer/features/auth/presentation/auth_gate.dart';
|
||||
import 'package:lifetimer/features/auth/presentation/auth_choice_screen.dart';
|
||||
import 'package:lifetimer/features/auth/presentation/auth_showcase_screen.dart';
|
||||
import 'package:lifetimer/features/onboarding/presentation/onboarding_intro_screen.dart';
|
||||
import 'package:lifetimer/features/onboarding/application/onboarding_controller.dart';
|
||||
import 'package:lifetimer/data/models/user_model.dart';
|
||||
import 'package:lifetimer/data/repositories/auth_repository.dart';
|
||||
import 'package:lifetimer/core/utils/unit_conversion_utils.dart';
|
||||
|
||||
class MockAuthRepository extends AuthRepository {
|
||||
bool _isAuthenticated = false;
|
||||
@@ -29,13 +31,14 @@ class MockAuthRepository extends AuthRepository {
|
||||
Future<void> signInWithEmail(String email, String password) async {}
|
||||
|
||||
@override
|
||||
Future<void> signUpWithEmail(String email, String password, String username) async {}
|
||||
Future<void> signUpWithEmail(String email, String password, String username, {double? heightCm, double? weightKg, int? age, Gender? gender, HeightUnit? heightUnit, WeightUnit? weightUnit}) async {}
|
||||
|
||||
@override
|
||||
Future<void> signInWithGoogle() async {}
|
||||
|
||||
@override
|
||||
Future<void> signInWithApple() async {}
|
||||
Future<void> signInWithApple() async {
|
||||
// Mock implementation
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> signOut() async {}
|
||||
@@ -55,12 +58,27 @@ class MockAuthRepository extends AuthRepository {
|
||||
String? bio,
|
||||
String? avatarUrl,
|
||||
bool? isPublicProfile,
|
||||
double? heightCm,
|
||||
double? weightKg,
|
||||
int? age,
|
||||
Gender? gender,
|
||||
HeightUnit? heightUnit,
|
||||
WeightUnit? weightUnit,
|
||||
}) async {}
|
||||
|
||||
@override
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
class MockOnboardingController extends OnboardingController {
|
||||
MockOnboardingController() : super();
|
||||
|
||||
@override
|
||||
Future<void> loadOnboardingStatus() async {
|
||||
// Do nothing in test
|
||||
}
|
||||
}
|
||||
|
||||
class TestData {
|
||||
static User createTestUser() {
|
||||
return User(
|
||||
@@ -75,23 +93,28 @@ class TestData {
|
||||
|
||||
void main() {
|
||||
group('AuthGate Widget', () {
|
||||
testWidgets('should show AuthChoiceScreen when user is not authenticated',
|
||||
testWidgets('should continue to onboarding when backend is unavailable and user is not authenticated',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
authRepositoryProvider.overrideWithValue(MockAuthRepository()),
|
||||
onboardingControllerProvider.overrideWith((ref) => MockOnboardingController()),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: AuthGate(),
|
||||
child: MaterialApp(
|
||||
home: const AuthGate(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(800, 600)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AuthChoiceScreen), findsOneWidget);
|
||||
expect(find.byType(OnboardingIntroScreen), findsNothing);
|
||||
expect(find.byType(OnboardingIntroScreen), findsOneWidget);
|
||||
expect(find.byType(AuthShowcaseScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should show OnboardingIntroScreen when user is authenticated',
|
||||
@@ -103,9 +126,14 @@ void main() {
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
authRepositoryProvider.overrideWithValue(mockRepo),
|
||||
onboardingControllerProvider.overrideWith((ref) => MockOnboardingController()),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: AuthGate(),
|
||||
child: MaterialApp(
|
||||
home: const AuthGate(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(800, 600)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -113,7 +141,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(OnboardingIntroScreen), findsOneWidget);
|
||||
expect(find.byType(AuthChoiceScreen), findsNothing);
|
||||
expect(find.byType(AuthShowcaseScreen), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,9 +58,13 @@ void main() {
|
||||
|
||||
testWidgets('should validate username field', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: const MaterialApp(
|
||||
home: SignUpScreen(),
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
home: const SignUpScreen(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(400, 1200)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -73,7 +77,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Try to submit
|
||||
final signUpButton = find.text('Sign Up');
|
||||
final signUpButton = find.text('Create Account');
|
||||
await tester.tap(signUpButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -83,9 +87,13 @@ void main() {
|
||||
|
||||
testWidgets('should validate email field', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: const MaterialApp(
|
||||
home: SignUpScreen(),
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
home: const SignUpScreen(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(400, 1200)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -98,7 +106,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Try to submit
|
||||
final signUpButton = find.text('Sign Up');
|
||||
final signUpButton = find.text('Create Account');
|
||||
await tester.tap(signUpButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -108,9 +116,13 @@ void main() {
|
||||
|
||||
testWidgets('should validate password field', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: const MaterialApp(
|
||||
home: SignUpScreen(),
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
home: const SignUpScreen(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(400, 1200)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -123,7 +135,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Try to submit
|
||||
final signUpButton = find.text('Sign Up');
|
||||
final signUpButton = find.text('Create Account');
|
||||
await tester.tap(signUpButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -134,9 +146,13 @@ void main() {
|
||||
testWidgets('should toggle password visibility',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: const MaterialApp(
|
||||
home: SignUpScreen(),
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
home: const SignUpScreen(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(400, 800)), // Smaller height
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -144,44 +160,56 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Find password visibility toggle button
|
||||
final toggleButton = find.byIcon(Icons.visibility_off);
|
||||
final toggleButton = find.byIcon(Icons.visibility_off_outlined);
|
||||
expect(toggleButton, findsOneWidget);
|
||||
|
||||
await tester.tap(toggleButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Should now show visibility icon
|
||||
expect(find.byIcon(Icons.visibility), findsOneWidget);
|
||||
expect(find.byIcon(Icons.visibility_outlined), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should show Google sign up button',
|
||||
testWidgets('should show email sign up form',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: const MaterialApp(
|
||||
home: SignUpScreen(),
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
home: const SignUpScreen(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(400, 1200)), // Taller for form
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Sign up with Google'), findsOneWidget);
|
||||
expect(find.text('Create Account'), findsOneWidget);
|
||||
expect(find.byType(TextFormField), findsNWidgets(6)); // email, password, confirm, username, height, weight
|
||||
});
|
||||
|
||||
testWidgets('should show Apple sign up button',
|
||||
testWidgets('should show email sign up form only',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: const MaterialApp(
|
||||
home: SignUpScreen(),
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
home: const SignUpScreen(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: const MediaQueryData(size: Size(400, 1200)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Sign up with Apple'), findsOneWidget);
|
||||
// Should not have social sign-up buttons
|
||||
expect(find.text('Sign up with Google'), findsNothing);
|
||||
expect(find.text('Sign up with Apple'), findsNothing);
|
||||
expect(find.text('Create Account'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user