Story 5.2: validation JS contact

This commit is contained in:
2026-02-04 21:06:19 +01:00
parent 70580f2d96
commit fb95a39792
6 changed files with 293 additions and 46 deletions

View File

@@ -0,0 +1,23 @@
<?php
function assertTrue($cond, $msg) {
if (!$cond) {
fwrite(STDERR, $msg . PHP_EOL);
exit(1);
}
}
$path = __DIR__ . '/../assets/js/contact-form.js';
assertTrue(file_exists($path), 'missing contact-form.js');
$content = file_get_contents($path);
assertTrue(strpos($content, 'class FormValidator') !== false, 'missing FormValidator class');
assertTrue(strpos($content, 'validateField') !== false, 'missing validateField');
assertTrue(strpos($content, 'validateAll') !== false, 'missing validateAll');
assertTrue(strpos($content, 'handleSubmit') !== false, 'missing handleSubmit');
assertTrue(strpos($content, 'updateSubmitButton') !== false, 'missing updateSubmitButton');
assertTrue(preg_match('/addEventListener\\(\\s*[\'\"]blur[\'\"]/', $content) === 1, 'missing blur listener');
assertTrue(preg_match('/addEventListener\\(\\s*[\'\"]submit[\'\"]/', $content) === 1, 'missing submit listener');
assertTrue(strpos($content, 'input-error') !== false, 'missing input-error handling');
assertTrue(strpos($content, 'submitBtn.disabled') !== false, 'missing submit disable');
fwrite(STDOUT, "OK\n");

View File

@@ -33,6 +33,14 @@ assertTrue(strpos($content, 'label for="objet"') !== false, 'missing objet label
assertTrue(strpos($content, 'id="objet"') !== false, 'missing objet input');
assertTrue(strpos($content, 'label for="message"') !== false, 'missing message label');
assertTrue(strpos($content, 'id="message"') !== false, 'missing message textarea');
assertTrue(strpos($content, 'data-error="nom"') !== false, 'missing nom error');
assertTrue(strpos($content, 'data-error="prenom"') !== false, 'missing prenom error');
assertTrue(strpos($content, 'data-error="email"') !== false, 'missing email error');
assertTrue(strpos($content, 'data-error="categorie"') !== false, 'missing categorie error');
assertTrue(strpos($content, 'data-error="objet"') !== false, 'missing objet error');
assertTrue(strpos($content, 'data-error="message"') !== false, 'missing message error');
assertTrue(strpos($content, 'id="submit-btn"') !== false, 'missing submit id');
assertTrue(strpos($content, '/assets/js/contact-form.js') !== false, 'missing contact script');
assertTrue(preg_match('/id="nom"[^>]*required/', $content) === 1, 'nom missing required');
assertTrue(preg_match('/id="prenom"[^>]*required/', $content) === 1, 'prenom missing required');

View File

@@ -21,4 +21,5 @@ php (Join-Path $here 'about.test.php')
php (Join-Path $here 'passions.test.php')
php (Join-Path $here 'testimonials.test.php')
php (Join-Path $here 'contact.test.php')
php (Join-Path $here 'contact-validation.test.php')
'OK'