Skip to content

Commit

Permalink
chore(rules): add fieldset legend [H71]
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 17, 2023
1 parent eab6239 commit 4f52f0e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ List of [WCAG2.1 techniques](https://www.w3.org/TR/WCAG21/) and whether or not w
| [H36](https://www.w3.org/TR/WCAG20-TECHS/H36.html) | missing form img alt | A-AAA | error | ||
| [H37](https://www.w3.org/TR/WCAG20-TECHS/H37.html) | missing img alt | A-AAA | error | ||
| [H42](https://www.w3.org/TR/WCAG20-TECHS/H42.html) | heading found with no content | A-AAA | error | ||
| [H53](https://www.w3.org/TR/WCAG20-TECHS/H53.html) | object elements must contain text alternative | A-AAA | error | ||
| [H53](https://www.w3.org/TR/WCAG20-TECHS/H53.html) | object elements must contain text alternative | A-AAA | error | ||
| [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | html contains valid lang | A-AAA | error | ||
| [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | lang attribute of the document element does not appear to be well-formed | A-AAA | error | 3.Lang ||
| [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | xml:lang attribute of the document element does not appear to be well-formed | A-AAA | error | 3.XmlLang ||
| [H64](https://www.w3.org/TR/WCAG20-TECHS/H64.html) | iframe missing title attribute | A-AAA | error | 1 ||
| [H71](https://www.w3.org/TR/WCAG20-TECHS/H71.html) | fieldset missing legend element | A-AAA | error | 2 ||
| [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 | ✔️ |
Expand All @@ -27,6 +28,6 @@ List of [WCAG2.1 techniques](https://www.w3.org/TR/WCAG21/) and whether or not w
| [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 `20/70`.
Errors that can be to be tested with automation `21/70`.

Key: ✅ = Complete, ✔️ = Complete with a bit of missing details.
2 changes: 1 addition & 1 deletion accessibility-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "accessibility-rs"
version = "0.0.36"
version = "0.0.37"
authors = ["The A11yWatch Project Developers", "Jeff Mendez <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 2 additions & 0 deletions accessibility-rs/src/engine/rules/techniques.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum Techniques {
H57,
/// <https://www.w3.org/TR/WCAG20-TECHS/H64>
H64,
/// <https://www.w3.org/TR/WCAG20-TECHS/H71>
H71,
/// <https://www.w3.org/TR/WCAG20-TECHS/H91>
H91,
/// <https://www.w3.org/TR/WCAG20-TECHS/F40>
Expand Down
26 changes: 26 additions & 0 deletions accessibility-rs/src/engine/rules/wcag_rule_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,32 @@ lazy_static! {
Validation::new(valid, "", elements, Default::default()).into()
}),
])),
("fieldset", Vec::from([
Rule::new(Techniques::H71.into(), IssueType::Error, Principle::Perceivable, Guideline::Adaptable, "1", |nodes, _lang| {
let mut valid = true;
let selector = unsafe { Selector::parse("legend").unwrap_unchecked() };
let mut elements = Vec::new();

for ele in nodes {
let ele = ele.0;
let mut e = ele.select(&selector);
let mut has_legend = false;

while let Some(el) = e.next() {
has_legend = true;
if el.text().count() == 0 {
valid = false;
elements.push(get_unique_selector(&ele))
}
}
if valid && !has_legend {
valid = false;
}
}

Validation::new(valid, "NoLegend", elements, Default::default()).into()
}),
])),
("applet", Vec::from([
Rule::new(Techniques::H35.into(), IssueType::Error, Principle::Perceivable, Guideline::TextAlternatives, "1", |nodes, _lang| {
let mut valid = true;
Expand Down
12 changes: 9 additions & 3 deletions accessibility-rs/tests/unit/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ fn _audit_missing_alt_anchor_img() {
</body>
</html>"###,
));
let valid = !audit.iter().any(|x| x.code == "WCAGAAA.Principle1.Guideline1_1.H30");
let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle1.Guideline1_1.H30");

assert_eq!(valid, false)
}
Expand All @@ -30,7 +32,9 @@ fn _audit_missing_anchor_content_valid_href() {
a href="www.example.com";
};
let audit = accessibility_rs::audit(AuditConfig::basic(&markup.into_string()));
let valid = !audit.iter().any(|x| x.code == "WCAGAAA.Principle4.Guideline4_1.H91");
let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle4.Guideline4_1.H91");

assert_eq!(valid, false)
}
Expand All @@ -42,7 +46,9 @@ fn _audit_missing_anchor_content() {
a { "" }
};
let audit = accessibility_rs::audit(AuditConfig::basic(&markup.into_string()));
let valid = !audit.iter().any(|x| x.code == "WCAGAAA.Principle4.Guideline4_1.H91");
let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle4.Guideline4_1.H91");

assert_eq!(valid, false)
}
24 changes: 24 additions & 0 deletions accessibility-rs/tests/unit/fieldset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Test for fieldsets.
use accessibility_rs::AuditConfig;
use maud::html;

#[test]
/// anchor contains single img element without alt
fn _audit_missing_fieldset_legend() {
let m = html! {
fieldset {
legend { "" };
input type="radio" id="shakesp" name="hamlet" checked="checked" value="a";
label for="shakesp" { "William Shakespeare" };
}
};

let audit = accessibility_rs::audit(AuditConfig::basic(&m.into_string()));

let valid = !audit
.iter()
.any(|x| x.code == "WCAGAAA.Principle1.Guideline1_3.H71");

assert_eq!(valid, false)
}
1 change: 1 addition & 0 deletions accessibility-rs/tests/unit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod anchor;
pub mod applet;
pub mod fieldset;
pub mod heading;
pub mod html;
pub mod img;
Expand Down

0 comments on commit 4f52f0e

Please sign in to comment.