Skip to content

Commit

Permalink
chore(validation): fix primary test for H44 [#4]
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 17, 2024
1 parent b7cf15a commit 95e2725
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 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.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Rust web accessibility engine.

```toml
[dependencies]
accessibility-rs = "^0.0.48"
accessibility-rs = "^0.0.49"
```

```rs
Expand Down
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.48"
version = "0.0.49"
authors = ["The A11yWatch Project Developers", "Jeff Mendez <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
59 changes: 46 additions & 13 deletions accessibility-rs/src/engine/rules/wcag_rule_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,24 +420,57 @@ lazy_static! {
let mut elements = Vec::new();

for ele in nodes {
match ele.0.attr("for") {
Some(s) => {
let selector = unsafe { Selector::parse(&("#".to_string() + &s)).unwrap_unchecked() };
let root_tree = ele.0.tree().root();

match ElementRef::new(root_tree) {
t => {
let e = t.select(&selector);
let has_valid_aria_label = ele.0.attr("aria-label").map_or(false, |s| !s.trim().is_empty());
let mut has_valid_text_match = false;

if !has_valid_aria_label && ele.0.text().next().is_some() {
for child in ele.0.children() {
match ElementRef::wrap(child) {
Some(child_element) => {
let name = child_element.value().name();

if vec!["textareas", "select"].contains(&name) {
has_valid_text_match = true;
} else if name == "input" {
match child_element.attr("type") {
Some(s) => {
if vec!["text", "file", "password"].contains(&s) {
has_valid_text_match = true;
}
}
_ => ()
}
}

if e.count() == 0 {
valid = false;
elements.push(get_unique_selector(&ele.0))
if has_valid_text_match {
break;
}
}
_ => ()
}
}
_ => ()
}

if !has_valid_aria_label && !has_valid_text_match {
match ele.0.attr("for") {
Some(s) => {
let selector = unsafe { Selector::parse(&("#".to_string() + &s)).unwrap_unchecked() };
let root_tree = ele.0.tree().root();

match ElementRef::new(root_tree) {
t => {
let e = t.select(&selector);

if e.count() == 0 {
valid = false;
elements.push(get_unique_selector(&ele.0))
}
}
}
}
_ => ()
}
}
}

Validation::new(valid, "NonExistent", elements, Default::default()).into()
Expand Down Expand Up @@ -541,7 +574,7 @@ lazy_static! {
elements.push(get_unique_selector(&ele));
}
}

Validation::new(valid, "ImageMapAreaNoAlt", elements, Default::default()).into()
})
])),
Expand Down
6 changes: 3 additions & 3 deletions accessibility-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
//! Audit html to see how it complies with WCAG
//! standards.
//!
//! Accessibility-RS is a web accessibility
//! accessibility-rs is a web accessibility
//! engine that can replicate websites without
//! a browser to get complex accessibility reports.
//!
//! # How to use Accessibility-RS
//! # How to use accessibility-rs
//!
//! There are a couple of ways to use Accessibility-RS:
//! There are a couple of ways to use accessibility-rs:
//!
//! - **Audit** perform an audit against an html page.
//! - [`audit`] is used to audit a web page for issues.
Expand Down
4 changes: 2 additions & 2 deletions accessibility-rs/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn _audit() {
let report = accessibility_rs::audit(AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
true,
false,
"en",
));
println!("{:?}", report)
Expand All @@ -20,7 +20,7 @@ fn _audit_large() {
let report = accessibility_rs::audit(AuditConfig::new(
mock::MOCK_HTML_LARGE_PAGE,
&mock::MOCK_CSS_RULES_LARGE,
true,
false,
"en",
));
println!("{:?}", report)
Expand Down
3 changes: 1 addition & 2 deletions accessibility-rs/tests/unit/area.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Test for anchors.
use accessibility_rs::{engine::audit, AuditConfig};
use maud::html;
use accessibility_rs::AuditConfig;

#[test]
fn _audit_missing_alt_area() {
Expand Down
2 changes: 1 addition & 1 deletion 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 area;
pub mod contrast;
pub mod fieldset;
pub mod heading;
Expand All @@ -8,4 +9,3 @@ pub mod img;
pub mod input;
pub mod label;
pub mod meta;
pub mod area;

0 comments on commit 95e2725

Please sign in to comment.