const fs = require('fs'); const JSZip = require('jszip'); // Mock document content for testing forms and flashing separation const mockDocumentWithForms = ` Please fill out this form: Text Field Check this box: `; const mockDocumentWithFlashing = ` This document has animated content: Color changing animation Rotating element `; const mockDocumentWithBoth = ` This document has both forms and animations: Dropdown Field Scaling animation Enter your name: `; // Simple utility functions for testing function extractTextFromParagraph(paragraph) { const textMatch = paragraph.match(/]*>(.*?)<\/w:t>/g); if (!textMatch) return ''; return textMatch.map(match => match.replace(/<[^>]*>/g, '')).join(' '); } function getFormType(formIndex) { const formTypes = [ 'text-field', 'checkbox-field', 'dropdown-field', 'form-data', 'checkbox-control', 'dropdown-control', 'text-input', 'content-control', 'content-control-data' ]; return formTypes[formIndex] || 'form-element'; } function getFlashingType(flashIndex) { const flashTypes = [ 'color-animation', 'rotation-animation', 'scale-animation', 'motion-animation', 'generic-animation', 'effect-animation', 'timing-element', 'looping-video', 'looping-audio' ]; return flashTypes[flashIndex] || 'animated-content'; } // Test versions of our functions function analyzeForms(documentXml) { const results = []; let paragraphCount = 0; let currentHeading = null; let approximatePageNumber = 1; // Check for form elements in Word documents const formElements = [ /[\s\S]*?/, // Text content controls /[\s\S]*?/, // Checkbox content controls /[\s\S]*?]*>/, // Form data elements /]*>/, // Checkbox form fields /]*>/, // Dropdown form fields /]*>/, // Text input form fields //, // Any content control // // Content control data ]; // Split into paragraphs for analysis const paragraphRegex = /]*>[\s\S]*?<\/w:p>/g; const paragraphs = documentXml.match(paragraphRegex) || []; paragraphs.forEach((paragraph, index) => { paragraphCount++; // Track page numbers (estimate) if (paragraphCount % 15 === 0) { approximatePageNumber++; } // Track headings for context if (/ { if (regex.test(paragraph)) { const flashType = getFlashingType(flashIndex); results.push({ type: flashType, location: `Paragraph ${paragraphCount}`, approximatePage: approximatePageNumber, context: currentHeading || 'Document body', preview: extractTextFromParagraph(paragraph).substring(0, 150) || 'Animated content detected', recommendation: 'Remove animated/flashing content to prevent seizures and improve accessibility for all users' }); } }); }); return results; } console.log('๐Ÿงช Testing Forms and Flashing Objects Separation'); console.log('================================================\n'); // Test 1: Document with only forms console.log('Test 1: Document with only forms'); console.log('----------------------------------'); const formsResult = analyzeForms(mockDocumentWithForms); const flashingFromFormsDoc = analyzeFlashingObjects(mockDocumentWithForms); console.log('Forms found:', formsResult.length); formsResult.forEach((issue, index) => { console.log(` ${index + 1}. Type: ${issue.type}`); console.log(` Location: ${issue.location}`); console.log(` Preview: ${issue.preview}`); }); console.log('Flashing objects found:', flashingFromFormsDoc.length); if (flashingFromFormsDoc.length === 0) { console.log(' โœ… Correctly found no flashing objects in forms-only document'); } console.log(''); // Test 2: Document with only flashing objects console.log('Test 2: Document with only flashing objects'); console.log('--------------------------------------------'); const flashingResult = analyzeFlashingObjects(mockDocumentWithFlashing); const formsFromFlashingDoc = analyzeForms(mockDocumentWithFlashing); console.log('Flashing objects found:', flashingResult.length); flashingResult.forEach((issue, index) => { console.log(` ${index + 1}. Type: ${issue.type}`); console.log(` Location: ${issue.location}`); console.log(` Preview: ${issue.preview}`); }); console.log('Forms found:', formsFromFlashingDoc.length); if (formsFromFlashingDoc.length === 0) { console.log(' โœ… Correctly found no forms in flashing-only document'); } console.log(''); // Test 3: Document with both forms and flashing objects console.log('Test 3: Document with both forms and flashing objects'); console.log('-----------------------------------------------------'); const bothFormsResult = analyzeForms(mockDocumentWithBoth); const bothFlashingResult = analyzeFlashingObjects(mockDocumentWithBoth); console.log('Forms found:', bothFormsResult.length); bothFormsResult.forEach((issue, index) => { console.log(` ${index + 1}. Type: ${issue.type}`); console.log(` Location: ${issue.location}`); console.log(` Preview: ${issue.preview.substring(0, 50)}...`); }); console.log('Flashing objects found:', bothFlashingResult.length); bothFlashingResult.forEach((issue, index) => { console.log(` ${index + 1}. Type: ${issue.type}`); console.log(` Location: ${issue.location}`); console.log(` Preview: ${issue.preview.substring(0, 50)}...`); }); // Summary console.log('\n๐Ÿ“Š Test Summary'); console.log('================'); console.log(`โœ… Forms function correctly identifies forms: ${formsResult.length > 0 && bothFormsResult.length > 0}`); console.log(`โœ… Flashing function correctly identifies animations: ${flashingResult.length > 0 && bothFlashingResult.length > 0}`); console.log(`โœ… Functions are properly separated: ${flashingFromFormsDoc.length === 0 && formsFromFlashingDoc.length === 0}`); console.log(`โœ… Both functions work on mixed content: ${bothFormsResult.length > 0 && bothFlashingResult.length > 0}`); console.log('\n๐ŸŽ‰ Forms and flashing objects are now properly separated into two distinct checks!');