import { describe, it, expect } from 'vitest';
import { FormControl } from '@angular/forms';
import { eanValidator, isEan } from './ean-validation';

describe('eanValidator', () => {
  it('should return null for valid EAN', () => {
    // Arrange
    const control = new FormControl('1234567890123');

    // Act
    const result = eanValidator(control);

    // Assert
    expect(result).toBeNull();
  });

  it('should return null for empty value', () => {
    // Arrange
    const control = new FormControl('');

    // Act
    const result = eanValidator(control);

    // Assert
    expect(result).toBeNull();
  });
});

describe('isEan', () => {
  it('should return true for valid EAN', () => {
    // Arrange
    const validEan = '1234567890123';

    // Act
    const result = isEan(validEan);

    // Assert
    expect(result).toBe(true);
  });

  it('should return false for undefined value', () => {
    // Arrange
    const undefinedValue = undefined;

    // Act
    const result = isEan(undefinedValue);

    // Assert
    expect(result).toBe(false);
  });
});
