From cb974be8c81e63974ae7ff03a4f6d24452b4a6f8 Mon Sep 17 00:00:00 2001 From: j-mendez Date: Wed, 18 Oct 2023 16:17:33 -0400 Subject: [PATCH] chore(rules): add duplicate label for [H93] --- Cargo.lock | 2 +- RULES.md | 3 +- accessibility-rs/Cargo.toml | 2 +- .../src/engine/rules/techniques.rs | 2 ++ .../src/engine/rules/wcag_rule_map.rs | 30 +++++++++++++++++++ accessibility-rs/tests/unit/label.rs | 20 +++++++++++++ accessibility-rs/tests/unit/mod.rs | 1 + 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 accessibility-rs/tests/unit/label.rs diff --git a/Cargo.lock b/Cargo.lock index fbcd33e..844977a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "accessibility-rs" -version = "0.0.37" +version = "0.0.38" dependencies = [ "accessibility-scraper", "accessibility-tree", diff --git a/RULES.md b/RULES.md index dc696d1..cd840ff 100644 --- a/RULES.md +++ b/RULES.md @@ -23,11 +23,12 @@ List of [WCAG2.1 techniques](https://www.w3.org/TR/WCAG21/) and whether or not w | [H91](https://www.w3.org/TR/WCAG20-TECHS/H91.html) | anchor valid href attribute, but no link content | A-AAA | error | A.NoContent | ✅ | | [H91](https://www.w3.org/TR/WCAG20-TECHS/H91.html) | anchor found but no link content | A-AAA | error | A.EmptyNoId | ✅ | | [H91](https://www.w3.org/TR/WCAG20-TECHS/H91.html) | form control needs name | A-AAA | error | [NodeName].Name | ✔️ | +| [H93](https://www.w3.org/TR/WCAG20-TECHS/H93.html) | label has multiple for ids | A-AAA | error | | ✅ | | [F40](https://www.w3.org/TR/WCAG20-TECHS/F40.html) | meta redirect used with a time limit | A-AAA | error | 2 | ✅ | | [F41](https://www.w3.org/TR/WCAG20-TECHS/F41.html) | meta refresh used to reload the page | A-AAA | error | 2 | ✅ | | [F47](https://www.w3.org/TR/WCAG20-TECHS/F47.html) | blink element used for attention | A-AAA | error | | ✅ | | [F77](https://www.w3.org/TR/WCAG20-TECHS/F77.html) | duplicate ID found | A-AAA | error | | ✅ | -Errors that can be to be tested with automation `21/70`. +Errors that can be to be tested with automation `22/70`. Key: ✅ = Complete, ✔️ = Complete with a bit of missing details. diff --git a/accessibility-rs/Cargo.toml b/accessibility-rs/Cargo.toml index f32594e..f472b46 100644 --- a/accessibility-rs/Cargo.toml +++ b/accessibility-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-rs" -version = "0.0.37" +version = "0.0.38" authors = ["The A11yWatch Project Developers", "Jeff Mendez "] edition = "2021" license = "MIT OR Apache-2.0" diff --git a/accessibility-rs/src/engine/rules/techniques.rs b/accessibility-rs/src/engine/rules/techniques.rs index ad3cde3..bbff678 100644 --- a/accessibility-rs/src/engine/rules/techniques.rs +++ b/accessibility-rs/src/engine/rules/techniques.rs @@ -27,6 +27,8 @@ pub enum Techniques { H71, /// H91, + /// + H93, /// F40, /// diff --git a/accessibility-rs/src/engine/rules/wcag_rule_map.rs b/accessibility-rs/src/engine/rules/wcag_rule_map.rs index 2a44e9f..943d3bf 100644 --- a/accessibility-rs/src/engine/rules/wcag_rule_map.rs +++ b/accessibility-rs/src/engine/rules/wcag_rule_map.rs @@ -287,6 +287,36 @@ lazy_static! { validate_empty_nodes(nodes, "2").into() }), ])), + ("label", Vec::from([ + Rule::new(Techniques::H93.into(), IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |nodes, _lang| { + let mut valid = true; + let mut elements = Vec::new(); + let mut id_map: HashMap<&str, u8> = HashMap::new(); + + for ele in nodes { + match ele.0.attr("for") { + Some(s) => { + if id_map.contains_key(s) { + let u = id_map.get(s); + match u { + Some(u) => { + valid = false; + id_map.insert(s, u.add(1)); + elements.push(get_unique_selector(&ele.0)) + } + _ => () + } + } else { + id_map.insert(s, 1); + } + } + _ => () + } + } + + Validation::new(valid, "", elements, Default::default()).into() + }) + ])), ("input", Vec::from([ Rule::new(Techniques::H91.into(), IssueType::Error, Principle::Robust, Guideline::Compatible, "2", |nodes, lang| { let mut valid = true; diff --git a/accessibility-rs/tests/unit/label.rs b/accessibility-rs/tests/unit/label.rs new file mode 100644 index 0000000..01d0c67 --- /dev/null +++ b/accessibility-rs/tests/unit/label.rs @@ -0,0 +1,20 @@ +//! Test for label elements. +use accessibility_rs::AuditConfig; +use maud::html; + +#[test] +/// label needs unique target ids +fn _audit_label_valid_name() { + let markup = html! { + label for="accessibility" { "My label" } + input id="accessibility" type="text" placeholder="Accessibility rocks!" value="Here"; + label for="accessibility" { "My label" } + }; + + let audit = accessibility_rs::audit(AuditConfig::basic(&markup.into_string())); + let valid = !audit + .iter() + .any(|x| x.code == "WCAGAAA.Principle1.Guideline1_3.H93"); + + assert_eq!(valid, false) +} diff --git a/accessibility-rs/tests/unit/mod.rs b/accessibility-rs/tests/unit/mod.rs index 151bfc7..5cb3273 100644 --- a/accessibility-rs/tests/unit/mod.rs +++ b/accessibility-rs/tests/unit/mod.rs @@ -6,3 +6,4 @@ pub mod html; pub mod img; pub mod input; pub mod meta; +pub mod label; \ No newline at end of file