import { BMS_FORM_VALID_URL_REGEX } from './form.helper';
import { describe, expect, test } from 'vitest';

describe('BMS_FORM_VALID_URL_REGEX', () => {
  test.each([
    // URLs valides
    { url: 'https://google.com', expected: true },
    { url: 'http://google.com', expected: true },
    { url: 'google.com', expected: true },
    { url: 'sub.domain.com', expected: true },
    { url: 'domain.com/path', expected: true },
    { url: 'domain.com/path/to/resource', expected: true },
    { url: 'domain.com/path-with-dash', expected: true },
    { url: 'domain.com/', expected: true },
    { url: 'domaine-avec-tiret.fr', expected: true },
    { url: 'ouest-france.fr/actualite', expected: true },
    { url: 'http://UPPERCASE.com', expected: true }, // domaine en majuscules

    // URLs invalides
    { url: 'localhost:8080/actualite', expected: true },
    { url: '', expected: false },
    { url: 'not an url', expected: false },
    { url: 'http:/domain.com', expected: false }, // slash manquant
    { url: 'http://', expected: false }, // domaine manquant
    { url: 'domain', expected: false }, // pas d'extension
    { url: '.com', expected: false }, // pas de domaine
    { url: 'domain.toolongtld', expected: false }, // tld trop long
    { url: 'ftp://domain.com', expected: false }, // protocole non supporté
    { url: 'javascript:alert(1)', expected: false }, // injection JavaScript
  ])('should validate "$url" as $expected', ({ url, expected }) => {
    expect(BMS_FORM_VALID_URL_REGEX.test(url)).toBe(expected);
  });
});
