Skip to content

Commit

Permalink
fixrule(img_alt_null, aria_accessiblename_exists) Update the rule…
Browse files Browse the repository at this point in the history
… mappings to be consistent with ACT rules (#2108)

* update the rule and test cases #2090

* add the help reference #2090

* Update aria_accessiblename_exists.ts

* fix baselines #2090

* update the test case #2090

* code clean up #2090

* undo change #2090

* Update Baseline_aChecker.Baseline.html.json

* Update JSONObjectStructureVerification.html.json

* Update JSONObjectStructureVerificationSelenium.html.json

* Update achecker.cy.js

* Update achecker.cy.js

* Create violations-no-match-diff.json

* clean up code #2090

* Update violations.json

* Update achecker.cy.js

* update ACT mapping #2090

* update reasonCode mapping #1090

---------

Co-authored-by: Tom Brunet <[email protected]>
Co-authored-by: Phill Jenkins <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent 79aacdd commit 66757d3
Show file tree
Hide file tree
Showing 8 changed files with 705 additions and 828 deletions.
28 changes: 17 additions & 11 deletions accessibility-checker-engine/src/v4/checker/Checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,27 @@ export class Checker implements IChecker {
}
for (const rsId of rsIds) {
if (rsId in rsInfo) {
Object.keys(rsInfo[rsId]).forEach(code => {
const reCode = new RegExp(`(^|--)${reasonCode}($|--)`);
Object.keys(rsInfo[rsId]).forEach(code => {
let level = null;
const reCode = new RegExp(`(^|--)${reasonCode}($|--)`);
if (code === 'None')
level = rsInfo[rsId]["None"];
else if (reCode.test(code))
level = rsInfo[rsId][code];
if (level === eRulePolicy.VIOLATION) {
retVal = eRulePolicy.VIOLATION;
} else if (level === eRulePolicy.RECOMMENDATION && retVal === null) {
retVal = eRulePolicy.RECOMMENDATION;
} else if (retVal === null) {
retVal = eRulePolicy.INFORMATION;
}
});
level = rsInfo[rsId][code];

if (level !== null) {
if (level === eRulePolicy.VIOLATION) {
retVal = eRulePolicy.VIOLATION;
} else if (level === eRulePolicy.RECOMMENDATION && retVal === null) {
retVal = eRulePolicy.RECOMMENDATION;
} else if (retVal === null) {
retVal = eRulePolicy.INFORMATION;
}
}
});
if (retVal === null) {
retVal = eRulePolicy.INFORMATION;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { AriaUtil } from "../util/AriaUtil";
import { CommonUtil } from "../util/CommonUtil";
import { VisUtil } from "../util/VisUtil";
import { ARIADefinitions } from "../../v2/aria/ARIADefinitions";
import { AccNameUtil } from "../util/AccNameUtil";

export const aria_accessiblename_exists: Rule = {
Expand All @@ -26,32 +24,42 @@ export const aria_accessiblename_exists: Rule = {
"en-US": {
"pass": "aria_accessiblename_exists.html",
"fail_no_accessible_name": "aria_accessiblename_exists.html",
"fail_no_accessible_name_image": "aria_accessiblename_exists.html",
"group": "aria_accessiblename_exists.html"
}
},
messages: {
"en-US": {
"pass": "An accessible name is provided for the element",
"fail_no_accessible_name": "Element <{0}> with \"{1}\" role has no accessible name",
"fail_no_accessible_name_image": "Element <{0}> with \"{1}\" role has no accessible name",
"group": "Elements with certain roles should have accessible names"
}
},
rulesets: [{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["4.1.2"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_no_accessible_name"]
},
{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["ARIA"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_no_accessible_name_image"]
}],
act: [],
act: [{"23a2a8": {"fail_no_accessible_name_image": "fail"}}],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;

//skip the rule
if (VisUtil.isNodeHiddenFromAT(ruleContext)) return null;

let nodeName = ruleContext.nodeName.toLocaleLowerCase();
// svg element is handled in svg_graphics)labbelled rule
if (nodeName === 'svg') return;
// svg element is handled in svg_graphics_labbelled rule and image rules
if (nodeName === 'svg' || nodeName === 'img') return;

// when table element with a caption as first child
if (nodeName === 'table'
Expand All @@ -69,9 +77,11 @@ export const aria_accessiblename_exists: Rule = {
let role = AriaUtil.getResolvedRole(ruleContext);

const name_pair = AccNameUtil.computeAccessibleName(ruleContext);
if (!name_pair || !name_pair.name || name_pair.name.trim().length === 0)
if (!name_pair || !name_pair.name || name_pair.name.trim().length === 0) {
if (role === 'img' || role === 'image')
return RuleFail("fail_no_accessible_name_image", [ruleContext.nodeName.toLowerCase(), role]);
return RuleFail("fail_no_accessible_name", [ruleContext.nodeName.toLowerCase(), role]);

}
return RulePass("pass");
}
}
13 changes: 11 additions & 2 deletions accessibility-checker-engine/src/v4/rules/img_alt_null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ export const img_alt_null: Rule = {
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["1.1.1"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
}],
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_decorative"]
},
{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["ARIA"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["potential_aria_override"]
}
],
act: [{"46ca7f": {"potential_aria_override": "fail"}}],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,7 @@
UnitTest = {
ruleIds: ["aria_accessiblename_exists"],
results: [
{
"ruleId": "aria_accessiblename_exists",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/img[1]",
"aria": "/document[1]/img[1]"
},
"reasonId": "pass",
"message": "An accessible name is provided for the element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}

]
}
</script>
Expand Down
Loading

0 comments on commit 66757d3

Please sign in to comment.