-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-enhanced-gpt.js
More file actions
175 lines (166 loc) · 6.18 KB
/
test-enhanced-gpt.js
File metadata and controls
175 lines (166 loc) · 6.18 KB
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
const { performGPT4AccessibilityAnalysis } = require('./lib/enhanced-gpt-analysis');
// Mock page object for testing
const mockPage = {
title: () => Promise.resolve('Test Page'),
url: () => 'https://example.com',
viewportSize: () => ({ width: 1280, height: 720 }),
$eval: (selector, fn) => {
if (selector === 'meta[name="description"]') return Promise.resolve('Test description');
if (selector === 'html') return Promise.resolve('en');
return Promise.resolve('');
},
$$eval: (selector, fn) => {
if (selector === 'h1, h2, h3, h4, h5, h6') {
return Promise.resolve([
{ tagName: 'H1', textContent: 'Main Title', id: 'main-title', level: 1, ariaLabel: '' },
{ tagName: 'H3', textContent: 'Subtitle', id: '', level: 3, ariaLabel: '' }
]);
}
if (selector === 'img') {
return Promise.resolve([
{ src: 'image1.jpg', alt: 'screenshot', title: '', role: '', ariaLabel: '', decorative: false },
{ src: 'image2.jpg', alt: '', title: '', role: '', ariaLabel: '', decorative: false }
]);
}
if (selector === 'a') {
return Promise.resolve([
{ textContent: 'click here', href: '/page1', title: '', ariaLabel: '', target: '', role: '' },
{ textContent: 'read more', href: '/page2', title: '', ariaLabel: '', target: '', role: '' }
]);
}
if (selector === 'form') {
return Promise.resolve([
{
action: '/submit',
method: 'post',
ariaLabel: '',
inputs: [
{ type: 'text', name: 'username', id: 'username', placeholder: '', required: true, ariaLabel: '', ariaDescribedby: '', ariaRequired: '', label: '' },
{ type: 'password', name: 'password', id: 'password', placeholder: '', required: true, ariaLabel: '', ariaDescribedby: '', ariaRequired: '', label: '' }
]
}
]);
}
if (selector === 'button, input[type="button"], input[type="submit"], input[type="reset"]') {
return Promise.resolve([
{ textContent: 'Submit', type: 'submit', ariaLabel: '', disabled: false, form: 'login-form' }
]);
}
if (selector === 'main, nav, header, footer, aside, section, article, [role="main"], [role="navigation"], [role="banner"], [role="contentinfo"], [role="complementary"]') {
return Promise.resolve([
{ tagName: 'HEADER', role: 'banner', ariaLabel: '', ariaLabelledby: '' },
{ tagName: 'MAIN', role: 'main', ariaLabel: '', ariaLabelledby: '' }
]);
}
if (selector === 'table') {
return Promise.resolve([
{ caption: '', headers: ['Name', 'Email'], rows: 3, hasScope: false, summary: '' }
]);
}
if (selector === 'ul, ol, dl') {
return Promise.resolve([
{ type: 'UL', items: 3, ariaLabel: '', role: '' }
]);
}
if (selector === 'a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])') {
return Promise.resolve([
{ tag: 'A', tabIndex: 0, disabled: false, visible: true },
{ tag: 'BUTTON', tabIndex: 0, disabled: false, visible: true }
]);
}
if (selector === '[aria-label], [aria-labelledby], [aria-describedby], [aria-expanded], [aria-hidden], [aria-live]') {
return Promise.resolve([
{ tagName: 'BUTTON', ariaLabel: 'Close dialog', ariaLabelledby: '', ariaDescribedby: '', ariaExpanded: '', ariaHidden: '', ariaLive: '' }
]);
}
return Promise.resolve([]);
},
evaluate: (fn) => {
if (fn.toString().includes('colorData')) {
return Promise.resolve([
{ element: 'P', color: 'rgb(0, 0, 0)', backgroundColor: 'rgb(255, 255, 255)', fontSize: '16px', fontWeight: 'normal' }
]);
}
return Promise.resolve([]);
},
content: () => Promise.resolve(`
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Page</title>
<meta name="description" content="Test description">
</head>
<body>
<header>
<h1 id="main-title">Main Title</h1>
<nav>
<a href="/page1">click here</a>
<a href="/page2">read more</a>
</nav>
</header>
<main>
<h3>Subtitle</h3>
<img src="image1.jpg" alt="screenshot">
<img src="image2.jpg">
<form action="/submit" method="post">
<input type="text" name="username" id="username" required>
<input type="password" name="password" id="password" required>
<button type="submit">Submit</button>
</form>
</main>
</body>
</html>
`)
};
// Mock sendLog function
const mockSendLog = (message, type = 'info') => {
console.log(`[${type.toUpperCase()}] ${message}`);
};
// Mock axe results
const mockAxeResults = {
violations: [
{
id: 'color-contrast',
impact: 'serious',
tags: ['wcag2aa'],
nodes: [
{
target: ['body'],
failureSummary: 'Elements must have sufficient color contrast',
html: '<body>...</body>'
}
]
}
]
};
// Test the enhanced GPT-4 analysis
async function testEnhancedGPT() {
console.log('🧪 Testing Enhanced GPT-4 Analysis System...\n');
try {
const htmlContent = await mockPage.content();
const issues = await performGPT4AccessibilityAnalysis(htmlContent, mockAxeResults, mockPage, mockSendLog);
console.log('\n📊 Test Results:');
console.log(`Found ${issues.length} GPT-4 issues`);
if (issues.length > 0) {
console.log('\n🔍 Issue Details:');
issues.forEach((issue, index) => {
console.log(`\n${index + 1}. ${issue.message}`);
console.log(` Type: ${issue.type}`);
console.log(` Severity: ${issue.severity}`);
console.log(` WCAG: ${issue.wcagReference}`);
console.log(` Suggestion: ${issue.suggestion}`);
});
} else {
console.log('\n⚠️ No additional issues found by GPT-4 analysis');
console.log('This could mean:');
console.log('- The test page is already accessible');
console.log('- The GPT-4 analysis endpoints are not responding');
console.log('- There are network connectivity issues');
}
} catch (error) {
console.error('\n❌ Test failed:', error.message);
console.error('Stack trace:', error.stack);
}
}
// Run the test
testEnhancedGPT();