import 'package:afterwork/core/utils/validators.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('Validators', () {
    group('validateEmail', () {
      test('should return null for valid email', () {
        // Act
        final result = Validators.validateEmail('test@example.com');

        // Assert
        expect(result, isNull);
      });

      test('should return error message for null email', () {
        // Act
        final result = Validators.validateEmail(null);

        // Assert
        expect(result, 'Veuillez entrer votre email');
      });

      test('should return error message for empty email', () {
        // Act
        final result = Validators.validateEmail('');

        // Assert
        expect(result, 'Veuillez entrer votre email');
      });

      test('should return error message for invalid email without @', () {
        // Act
        final result = Validators.validateEmail('invalidemail.com');

        // Assert
        expect(result, 'Veuillez entrer un email valide');
      });

      test('should return error message for invalid email without domain', () {
        // Act
        final result = Validators.validateEmail('test@');

        // Assert
        expect(result, 'Veuillez entrer un email valide');
      });

      test('should return error message for invalid email without extension', () {
        // Act
        final result = Validators.validateEmail('test@example');

        // Assert
        expect(result, 'Veuillez entrer un email valide');
      });

      test('should accept valid email with subdomain', () {
        // Act
        final result = Validators.validateEmail('test@mail.example.com');

        // Assert
        expect(result, isNull);
      });

      test('should accept valid email with numbers', () {
        // Act
        final result = Validators.validateEmail('test123@example123.com');

        // Assert
        expect(result, isNull);
      });

      test('should accept valid email with special characters', () {
        // Act
        final result = Validators.validateEmail('test.name+tag@example.co.uk');

        // Assert
        expect(result, isNull);
      });
    });

    group('validatePassword', () {
      test('should return null for valid password (6+ characters)', () {
        // Act
        final result = Validators.validatePassword('password123');

        // Assert
        expect(result, isNull);
      });

      test('should return null for password with exactly 6 characters', () {
        // Act
        final result = Validators.validatePassword('123456');

        // Assert
        expect(result, isNull);
      });

      test('should return error message for null password', () {
        // Act
        final result = Validators.validatePassword(null);

        // Assert
        expect(result, 'Veuillez entrer votre mot de passe');
      });

      test('should return error message for empty password', () {
        // Act
        final result = Validators.validatePassword('');

        // Assert
        expect(result, 'Veuillez entrer votre mot de passe');
      });

      test('should return error message for password with less than 6 characters', () {
        // Act
        final result = Validators.validatePassword('12345');

        // Assert
        expect(result, 'Le mot de passe doit comporter au moins 6 caractères');
      });

      test('should return error message for password with 5 characters', () {
        // Act
        final result = Validators.validatePassword('abcde');

        // Assert
        expect(result, 'Le mot de passe doit comporter au moins 6 caractères');
      });

      test('should accept password with special characters', () {
        // Act
        final result = Validators.validatePassword('P@ssw0rd!');

        // Assert
        expect(result, isNull);
      });

      test('should accept long password', () {
        // Act
        final result = Validators.validatePassword('a' * 100);

        // Assert
        expect(result, isNull);
      });
    });
  });
}

