-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* aria-required-attr * try fixing tooltip tests * use summary reporter * publish test results * increase permissions for action
- Loading branch information
Showing
8 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { AccessibilityError } from "../scanner"; | ||
import { querySelectorAll } from "../utils"; | ||
|
||
// TODO: This list is incomplete! | ||
type Role = | ||
| "checkbox" | ||
| "combobox" | ||
| "heading" | ||
| "menuitemcheckbox" | ||
| "menuitemradio" | ||
| "meter" | ||
| "radio" | ||
| "scrollbar" | ||
| "seperator" | ||
| "slider" | ||
| "switch"; | ||
|
||
// TODO: This list is incomplete! | ||
type AriaAttribute = | ||
| "aria-checked" | ||
| "aria-expanded" | ||
| "aria-level" | ||
| "aria-checked" | ||
| "aria-valuenow" | ||
| "aria-controls"; | ||
|
||
/** | ||
* Required States and Properties: | ||
* | ||
* @see https://w3c.github.io/aria/#authorErrorDefaultValuesTable | ||
*/ | ||
const roleToRequiredStatesAndPropertiesMaps: Record<Role, AriaAttribute[]> = { | ||
checkbox: ["aria-checked"], | ||
combobox: ["aria-expanded"], | ||
heading: ["aria-level"], | ||
menuitemcheckbox: ["aria-checked"], | ||
menuitemradio: ["aria-checked"], | ||
meter: ["aria-valuenow"], | ||
radio: ["aria-checked"], | ||
scrollbar: ["aria-controls", "aria-valuenow"], | ||
// If focusable | ||
seperator: ["aria-valuenow"], | ||
slider: ["aria-valuenow"], | ||
switch: ["aria-checked"], | ||
}; | ||
|
||
const id = "aria-required-attr"; | ||
const text = "Required ARIA attributes must be provided"; | ||
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}?application=RuleDescription`; | ||
|
||
export function ariaRequiredAttr(el: Element): AccessibilityError[] { | ||
const errors = []; | ||
|
||
const selector = Object.entries(roleToRequiredStatesAndPropertiesMaps) | ||
.map(([role, attributes]) => { | ||
return `[role=${role}]:not(${attributes.map((attr) => `[${attr}]`).join("")})`; | ||
}) | ||
.join(","); | ||
|
||
const elements = querySelectorAll(selector, el); | ||
if (el.matches(selector)) elements.push(el); | ||
|
||
for (const element of elements) { | ||
errors.push({ | ||
element, | ||
text, | ||
url, | ||
}); | ||
} | ||
return errors; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { fixture, expect } from "@open-wc/testing"; | ||
import { Scanner } from "../src/scanner"; | ||
import ariaValidAttr from "../src/rules/aria-valid-attr"; | ||
|
||
const scanner = new Scanner([ariaValidAttr]); | ||
|
||
const passes = [ | ||
'<div id="target" role="switch" tabindex="1" aria-checked="false">', | ||
'<div id="target"></div>', | ||
'<input id="target" type="range" role="slider">', | ||
'<input id="target" type="checkbox" role="switch">', | ||
'<div id="target" role="separator"></div>', | ||
'<div id="target" role="combobox" aria-expanded="false"></div>', | ||
'<div id="target" role="combobox" aria-expanded="true" aria-controls="test"></div>', | ||
]; | ||
const violations = [ | ||
'<div id="target" role="switch" tabindex="1">', | ||
'<div id="target" role="switch" tabindex="1" aria-checked>', | ||
'<div id="target" role="switch" tabindex="1" aria-checked="">', | ||
'<div id="target" role="separator" tabindex="0"></div>', | ||
'<div id="target" role="combobox" aria-expanded="invalid-value"></div>', | ||
'<div id="target" role="combobox" aria-expanded="true" aria-owns="ownedchild"></div>', | ||
'<div id="target" role="combobox"></div>', | ||
'<div id="target" role="combobox" aria-expanded="true"></div>', | ||
]; | ||
|
||
describe("aria-required-attr", async function () { | ||
for (const markup of passes) { | ||
const el = await fixture(markup); | ||
it(el.outerHTML, async () => { | ||
const results = (await scanner.scan(el)).map(({ text, url }) => { | ||
return { text, url }; | ||
}); | ||
|
||
expect(results).to.be.empty; | ||
}); | ||
} | ||
|
||
for (const markup of violations) { | ||
const el = await fixture(markup); | ||
it(el.outerHTML, async () => { | ||
const results = (await scanner.scan(el)).map(({ text, url }) => { | ||
return { text, url }; | ||
}); | ||
|
||
expect(results).to.eql([ | ||
{ | ||
text: "ARIA attributes must conform to valid names", | ||
url: "https://dequeuniversity.com/rules/axe/4.4/aria-valid-attr", | ||
}, | ||
]); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters