File size: 6,930 Bytes
bbfde3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
const fs = require('fs');
const JSZip = require('jszip');

// Test forms and flashing objects detection
async function testFormsAndFlashingDetection() {
  console.log('=== Testing Forms and Flashing Objects Detection ===\n');
  
  try {
    // Create test content with forms and animations
    const testContent = `

      <w:document>

        <w:body>

          <w:p>

            <w:pStyle w:val="Heading1"/>

            <w:r><w:t>Document with Forms</w:t></w:r>

          </w:p>

          <w:p>

            <w:fldSimple w:fldChar="FORMTEXT">

              <w:r><w:t>Enter your name:</w:t></w:r>

            </w:fldSimple>

          </w:p>

          <w:p>

            <w:fldSimple w:fldChar="FORMCHECKBOX">

              <w:r><w:t>I agree to terms</w:t></w:r>

            </w:fldSimple>

          </w:p>

          <w:p>

            <w:checkBox>

              <w:r><w:t>Check this box</w:t></w:r>

            </w:checkBox>

          </w:p>

          <w:p>

            <w:sdt>

              <w:sdtContent>

                <w:r><w:t>Content control field</w:t></w:r>

              </w:sdtContent>

            </w:sdt>

          </w:p>

          <w:p>

            <w:pStyle w:val="Heading2"/>  

            <w:r><w:t>Animated Content Section</w:t></w:r>

          </w:p>

          <w:p>

            <w:drawing>

              <a:animClr type="flash">

                <w:r><w:t>Flashing color animation</w:t></w:r>

              </a:animClr>

            </w:drawing>

          </w:p>

          <w:p>

            <w:drawing>

              <a:animRot angle="360">

                <w:r><w:t>Rotating element</w:t></w:r>

              </a:animRot>

            </w:drawing>

          </w:p>

          <w:p>

            <a:videoFile loop="true" src="video.mp4">

              <w:r><w:t>Looping video content</w:t></w:r>

            </a:videoFile>

          </w:p>

        </w:body>

      </w:document>

    `;
    
    console.log('πŸ§ͺ Testing with Content Containing:');
    console.log('   - Text form field (FORMTEXT)');
    console.log('   - Checkbox form field (FORMCHECKBOX)');
    console.log('   - Checkbox control');
    console.log('   - Content control (SDT)');
    console.log('   - Color animation (flashing)');
    console.log('   - Rotation animation');  
    console.log('   - Looping video\n');
    
    const results = testFormsAndFlashingAnalysis(testContent);
    
    console.log('πŸ“Š Forms Detection Results:');
    console.log(`   Total forms found: ${results.formsDetected.length}`);
    console.log(`   Expected: 4 form elements\n`);
    
    results.formsDetected.forEach((form, index) => {
      console.log(`   ${index + 1}. Form Type: ${form.type}`);
      console.log(`      Location: ${form.location}`);
      console.log(`      Context: ${form.context}`);
      console.log(`      Preview: "${form.preview}"`);
      console.log(`      Recommendation: ${form.recommendation}`);
      console.log('');
    });
    
    console.log('πŸ“Š Flashing Objects Detection Results:');
    console.log(`   Total flashing objects found: ${results.flashingObjects.length}`);
    console.log(`   Expected: 3 animated elements\n`);
    
    results.flashingObjects.forEach((flash, index) => {
      console.log(`   ${index + 1}. Animation Type: ${flash.type}`);
      console.log(`      Location: ${flash.location}`);
      console.log(`      Context: ${flash.context}`);
      console.log(`      Preview: "${flash.preview}"`);
      console.log(`      Recommendation: ${flash.recommendation}`);
      console.log('');
    });
    
    if (results.formsDetected.length >= 4 && results.flashingObjects.length >= 3) {
      console.log('βœ… Forms and Flashing Objects detection test PASSED!');
      console.log('   All expected form fields and animated content detected.');
    } else {
      console.log('❌ Detection test FAILED!');
      console.log(`   Expected: 4+ forms, 3+ animations`);
      console.log(`   Got: ${results.formsDetected.length} forms, ${results.flashingObjects.length} animations`);
    }
    
  } catch (error) {
    console.error('❌ Test failed:', error.message);
  }
}

// Test function for forms and flashing analysis
function testFormsAndFlashingAnalysis(documentXml) {
  const results = {
    formsDetected: [],
    flashingObjects: []
  };

  let paragraphCount = 0;
  let currentHeading = null;

  // Extract text from XML
  function extractTextFromParagraph(xml) {
    const textMatches = xml.match(/<w:t[^>]*>(.*?)<\/w:t>/g);
    if (!textMatches) return '';
    return textMatches.map(t => t.replace(/<w:t[^>]*>|<\/w:t>/g, '')).join('').trim();
  }

  const paragraphRegex = /<w:p\b[^>]*>[\s\S]*?<\/w:p>/g;
  const paragraphs = documentXml.match(paragraphRegex) || [];

  paragraphs.forEach((paragraph, index) => {
    paragraphCount++;
    
    // Track headings
    const headingMatch = paragraph.match(/<w:pStyle w:val="(Heading\d+)"\/>/);
    if (headingMatch) {
      const headingText = extractTextFromParagraph(paragraph);
      currentHeading = `${headingMatch[1]}: ${headingText.substring(0, 50)}`;
    }

    // Check for form fields
    const formElements = [
      { regex: /<w:fldSimple[^>]*fldChar[^>]*FORMTEXT/, type: 'text-field' },
      { regex: /<w:fldSimple[^>]*fldChar[^>]*FORMCHECKBOX/, type: 'checkbox-field' },
      { regex: /<w:checkBox>/, type: 'checkbox-control' },
      { regex: /<w:sdt>/, type: 'content-control' }
    ];

    formElements.forEach(({ regex, type }) => {
      if (regex.test(paragraph)) {
        results.formsDetected.push({
          type: type,
          location: `Paragraph ${paragraphCount}`,
          approximatePage: 1,
          context: currentHeading || 'Document body',
          preview: extractTextFromParagraph(paragraph).substring(0, 150),
          recommendation: 'Consider using alternative formats like accessible web forms instead of Word form fields'
        });
      }
    });

    // Check for flashing/animated content
    const flashingElements = [
      { regex: /<a:animClr/, type: 'color-animation' },
      { regex: /<a:animRot/, type: 'rotation-animation' },
      { regex: /<a:videoFile[^>]*loop/, type: 'looping-video' }
    ];

    flashingElements.forEach(({ regex, type }) => {
      if (regex.test(paragraph)) {
        results.flashingObjects.push({
          type: type,
          location: `Paragraph ${paragraphCount}`,
          approximatePage: 1,
          context: currentHeading || 'Document body',
          preview: extractTextFromParagraph(paragraph).substring(0, 150) || 'Animated content detected',
          recommendation: 'Remove animated/flashing content to prevent seizures and improve accessibility'
        });
      }
    });
  });

  return results;
}

testFormsAndFlashingDetection();