fix(a11y): 修复链接可访问性问题
- 为Logo链接添加aria-label - 增强可访问性测试的详细输出 - 扩大测试范围至前20个链接 任务 2/4
This commit is contained in:
@@ -63,16 +63,34 @@ test.describe('无障碍测试 @feature @frontend', () => {
|
|||||||
|
|
||||||
test('链接有明确的文本', async ({ page }) => {
|
test('链接有明确的文本', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
await page.waitForLoadState('domcontentloaded');
|
||||||
|
|
||||||
const links = page.locator('a');
|
const links = page.locator('a');
|
||||||
const count = await links.count();
|
const count = await links.count();
|
||||||
|
const problematicLinks: string[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < Math.min(count, 10); i++) {
|
for (let i = 0; i < Math.min(count, 20); i++) {
|
||||||
const link = links.nth(i);
|
const link = links.nth(i);
|
||||||
const text = await link.textContent();
|
const text = await link.textContent();
|
||||||
const ariaLabel = await link.getAttribute('aria-label');
|
const ariaLabel = await link.getAttribute('aria-label');
|
||||||
|
const title = await link.getAttribute('title');
|
||||||
|
const href = await link.getAttribute('href');
|
||||||
|
|
||||||
expect(text || ariaLabel).toBeTruthy();
|
const hasAccessibleName = text?.trim() || ariaLabel || title;
|
||||||
|
const isSpecialLink = !href || href === '#' || href.startsWith('javascript:') || href.startsWith('mailto:');
|
||||||
|
|
||||||
|
if (!hasAccessibleName && !isSpecialLink) {
|
||||||
|
const linkHtml = await link.innerHTML();
|
||||||
|
problematicLinks.push(`链接 ${i + 1}: href="${href}", innerHTML="${linkHtml}"`);
|
||||||
|
console.log(`链接 ${i + 1} 缺少可访问名称: href="${href}", innerHTML="${linkHtml}"`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (problematicLinks.length > 0) {
|
||||||
|
console.log('\n缺少可访问名称的链接列表:');
|
||||||
|
problematicLinks.forEach(link => console.log(link));
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(problematicLinks.length).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ function HeaderContent() {
|
|||||||
<Link
|
<Link
|
||||||
href="/"
|
href="/"
|
||||||
className="flex items-center group"
|
className="flex items-center group"
|
||||||
|
aria-label="返回首页"
|
||||||
>
|
>
|
||||||
<Image
|
<Image
|
||||||
src="/logo.svg"
|
src="/logo.svg"
|
||||||
|
|||||||
Reference in New Issue
Block a user