feat: add accessibility smoke test script

This commit is contained in:
2026-04-10 23:50:46 +00:00
parent 535df05665
commit 63babc8ced

51
tests/a11y_audit.js Normal file
View File

@@ -0,0 +1,51 @@
/**
* Accessibility Smoke Test for The Beacon
* This script can be run in the browser console or via a headless test runner.
* It verifies that key interactive elements have the required ARIA attributes.
*/
function runA11yAudit() {
console.log("--- The Beacon: Accessibility Audit ---");
let errors = 0;
// 1. Check progress bars
const progressBars = document.querySelectorAll('[role="progressbar"]');
if (progressBars.length === 0) {
console.error("[FAIL] No progress bars found with role='progressbar'");
errors++;
} else {
progressBars.forEach(bar => {
if (!bar.hasAttribute('aria-valuenow')) {
console.error("[FAIL] Progress bar missing aria-valuenow", bar);
errors++;
}
});
}
// 2. Check buy buttons
const buyButtons = document.querySelectorAll('.build-btn:not([aria-disabled="true"])');
buyButtons.forEach(btn => {
if (!btn.hasAttribute('aria-label')) {
console.error("[FAIL] Active buy button missing aria-label", btn);
errors++;
}
});
// 3. Check buy amount toggles
const toggles = document.querySelectorAll('button[onclick^="setBuyAmount"]');
toggles.forEach(btn => {
if (!btn.hasAttribute('aria-pressed')) {
console.error("[FAIL] Buy amount toggle missing aria-pressed", btn);
errors++;
}
});
if (errors === 0) {
console.log("PASSED: All checked elements have required ARIA attributes.");
} else {
console.error(`FAILED: Found ${errors} accessibility issues.`);
}
}
// Export for use in other scripts if needed
if (typeof module !== 'undefined') module.exports = { runA11yAudit };