mirror of
https://github.com/Dvorinka/1356.git
synced 2026-07-29 05:33:48 +00:00
148 lines
4.2 KiB
Dart
148 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
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_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;
|
|
|
|
MockAuthRepository() : super(null);
|
|
|
|
@override
|
|
User? get currentUser => _isAuthenticated ? TestData.createTestUser() : null;
|
|
|
|
@override
|
|
Stream<User?> get authStateChanges => Stream.value(currentUser);
|
|
|
|
@override
|
|
bool get isAuthenticated => _isAuthenticated;
|
|
|
|
@override
|
|
String? get currentUserId => currentUser?.id;
|
|
|
|
@override
|
|
Future<void> signInWithEmail(String email, String password) async {}
|
|
|
|
@override
|
|
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 {}
|
|
|
|
Future<void> signInWithApple() async {
|
|
// Mock implementation
|
|
}
|
|
|
|
@override
|
|
Future<void> signOut() async {}
|
|
|
|
@override
|
|
Future<void> resetPassword(String email) async {}
|
|
|
|
@override
|
|
Future<bool> isSessionValid() async => true;
|
|
|
|
@override
|
|
Future<void> refreshSession() async {}
|
|
|
|
@override
|
|
Future<void> updateProfile({
|
|
String? username,
|
|
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(
|
|
id: 'test-user-id',
|
|
username: 'testuser',
|
|
email: '[email protected]',
|
|
createdAt: DateTime.now(),
|
|
updatedAt: DateTime.now(),
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
group('AuthGate Widget', () {
|
|
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: MaterialApp(
|
|
home: const AuthGate(),
|
|
builder: (context, child) => MediaQuery(
|
|
data: const MediaQueryData(size: Size(800, 600)),
|
|
child: child!,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(OnboardingIntroScreen), findsOneWidget);
|
|
expect(find.byType(AuthShowcaseScreen), findsNothing);
|
|
});
|
|
|
|
testWidgets('should show OnboardingIntroScreen when user is authenticated',
|
|
(WidgetTester tester) async {
|
|
final mockRepo = MockAuthRepository();
|
|
mockRepo._isAuthenticated = true;
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authRepositoryProvider.overrideWithValue(mockRepo),
|
|
onboardingControllerProvider.overrideWith((ref) => MockOnboardingController()),
|
|
],
|
|
child: MaterialApp(
|
|
home: const AuthGate(),
|
|
builder: (context, child) => MediaQuery(
|
|
data: const MediaQueryData(size: Size(800, 600)),
|
|
child: child!,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(OnboardingIntroScreen), findsOneWidget);
|
|
expect(find.byType(AuthShowcaseScreen), findsNothing);
|
|
});
|
|
});
|
|
}
|