95 lines
3.1 KiB
Dart
95 lines
3.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tm_app/view_models/auth_view_model.dart';
|
|
|
|
import '../mocks/mock_auth_repository.dart';
|
|
|
|
void main() {
|
|
group('AuthViewModel Validation', () {
|
|
late MockAuthRepository mockRepository;
|
|
late AuthViewModel authViewModel;
|
|
|
|
setUp(() {
|
|
mockRepository = MockAuthRepository();
|
|
authViewModel = AuthViewModel(authRepository: mockRepository);
|
|
});
|
|
|
|
tearDown(() {
|
|
authViewModel.dispose();
|
|
});
|
|
|
|
group('Email Validation', () {
|
|
test('should return true for valid email', () {
|
|
authViewModel.emailController.text = 'test@example.com';
|
|
expect(authViewModel.isEmailValid, true);
|
|
});
|
|
|
|
test('should return false for invalid email', () {
|
|
authViewModel.emailController.text = 'invalid-email';
|
|
expect(authViewModel.isEmailValid, false);
|
|
});
|
|
|
|
test('should return false for empty email', () {
|
|
authViewModel.emailController.text = '';
|
|
expect(authViewModel.isEmailValid, false);
|
|
});
|
|
|
|
test('should return false for email without domain', () {
|
|
authViewModel.emailController.text = 'test@';
|
|
expect(authViewModel.isEmailValid, false);
|
|
});
|
|
});
|
|
|
|
group('OTP Validation', () {
|
|
test('should return true for valid 6-digit OTP', () {
|
|
authViewModel.otpController.text = '123456';
|
|
expect(authViewModel.isOtpValid, true);
|
|
expect(authViewModel.canSubmitOtpPage, true);
|
|
});
|
|
|
|
test('should return false for invalid OTP length', () {
|
|
authViewModel.otpController.text = '12345';
|
|
expect(authViewModel.isOtpValid, false);
|
|
expect(authViewModel.canSubmitOtpPage, false);
|
|
});
|
|
|
|
test('should return false for empty OTP', () {
|
|
authViewModel.otpController.text = '';
|
|
expect(authViewModel.isOtpValid, false);
|
|
expect(authViewModel.canSubmitOtpPage, false);
|
|
});
|
|
});
|
|
|
|
group('Password Validation', () {
|
|
test('should return true for valid password', () {
|
|
authViewModel.newPasswordController.text = 'Test123!';
|
|
expect(authViewModel.isNewPasswordValid, true);
|
|
});
|
|
|
|
test('should return false for password without uppercase', () {
|
|
authViewModel.newPasswordController.text = 'test123!';
|
|
expect(authViewModel.isNewPasswordValid, false);
|
|
});
|
|
|
|
test('should return false for password without lowercase', () {
|
|
authViewModel.newPasswordController.text = 'TEST123!';
|
|
expect(authViewModel.isNewPasswordValid, false);
|
|
});
|
|
|
|
test('should return false for password without special character', () {
|
|
authViewModel.newPasswordController.text = 'Test123';
|
|
expect(authViewModel.isNewPasswordValid, false);
|
|
});
|
|
|
|
test('should return false for password too short', () {
|
|
authViewModel.newPasswordController.text = 'Te1!';
|
|
expect(authViewModel.isNewPasswordValid, false);
|
|
});
|
|
|
|
test('should return false for empty password', () {
|
|
authViewModel.newPasswordController.text = '';
|
|
expect(authViewModel.isNewPasswordValid, false);
|
|
});
|
|
});
|
|
});
|
|
}
|