Skip to content

Commit

Permalink
chore(innate): add empty title test
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 3, 2023
1 parent d05ff6d commit 4fe8c08
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion kayle/tests/innate-playwright.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ test("kayle_innate, fast_htmlcs, fast_axecore, and ace audit drakeMock profiling
});
const mock = html.replace("<title>Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels</title>", "")
const startTime = performance.now();
// 8 - after building end engine optimized most likely will be at 12 ms
const audit = await _audit_not_ready(mock, css);
const nextTime = performance.now() - startTime;
console.log("Rust/WASM TIME ", nextTime);
Expand Down
1 change: 0 additions & 1 deletion kayle/tests/innate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { _audit_not_ready } from "kayle_innate";
});
const mock = html.replace("<title>Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels</title>", "")
const startTime = performance.now();
// 8 - after building end engine optimized most likely will be at 12 ms
const audit = await _audit_not_ready(mock, css);
const nextTime = performance.now() - startTime;
console.log("Rust/WASM TIME ", nextTime);
Expand Down
18 changes: 10 additions & 8 deletions kayle_innate/src/engine/rules/wcag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct Rule {
/// validate a test
pub validate: fn(
&String,
&Vec<scraper::node::Element>,
&Vec<scraper::node::Node>,
css: &cssparser::Parser<'_, '_>,
) -> (bool, &'static str),
/// the principle type
Expand All @@ -84,7 +84,7 @@ impl Rule {
guideline: Guideline,
validate: fn(
&String,
&Vec<scraper::node::Element>,
&Vec<scraper::node::Node>,
&cssparser::Parser<'_, '_>,
) -> (bool, &'static str),
) -> Rule {
Expand All @@ -101,13 +101,14 @@ impl Rule {
lazy_static! {
/// a list of rules that should be applied for WCAG1
static ref RULES_A: BTreeMap<&'static str, Vec<Rule>> =
// empty titles
vec![("title", Vec::from([
Rule::new(RuleID::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, elements, _css_parser| {
(!elements.is_empty(), "1.NoTitleEl")
}),
// Rule::new(RuleID::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, elements, _css_parser| {
// (!elements.is_empty(), "1.EmptyTitle")
// }),
Rule::new(RuleID::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, elements, _css_parser| {
(elements.is_empty() || elements[0].as_text().unwrap_or(&scraper::node::Text { text: "".into() }).text.is_empty(), "1.EmptyTitle")
}),
]))]
.into_iter()
.collect();
Expand All @@ -122,7 +123,7 @@ impl WCAG3AA {
/// init the rules
pub fn audit(
// allow tree mutation until threads or setup the tree with initial elements.
mut tree: std::collections::BTreeMap<String, Vec<scraper::node::Element>>,
mut tree: std::collections::BTreeMap<String, Vec<scraper::node::Node>>,
_css: cssparser::Parser<'_, '_>,
// todo: get configs like viewport
) -> Vec<Issue> {
Expand Down Expand Up @@ -161,11 +162,12 @@ impl WCAG3AA {
);
issues.push(issue);
}

console_log!(
"RULE {:?} {:?} Valid: {:?}",
"RULE {:?} {:?} {:?} Valid: {:?}",
rule.rule_id,
rule.criteria,
section,
valid
);
}
Expand Down
16 changes: 9 additions & 7 deletions kayle_innate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ pub fn get_document_links(res: &str, domain: &str) -> Box<[JsValue]> {
pub fn parse_accessibility_tree(
html: &str,
// todo: return the nodes with a tuple of the layout node and the element node
) -> std::collections::BTreeMap<String, Vec<scraper::node::Element>> {
) -> std::collections::BTreeMap<String, Vec<scraper::node::Node>> {
use scraper::Node;

console_log!("Starting accessibility tree parsing. This is incomplete and should not be used in production.");
// use taffy::prelude::*;
// // todo: use optional variable for clips or layout creation
Expand Down Expand Up @@ -203,16 +205,16 @@ pub fn parse_accessibility_tree(
// parse doc will start from html downwards
let h = scraper::Html::parse_document(html);
// accessibility tree for ordered element mappings
let mut accessibility_tree: BTreeMap<String, Vec<_>> = BTreeMap::new();
let mut hh = h.tree.nodes();
let mut accessibility_tree: BTreeMap<String, Vec<Node>> = BTreeMap::new();
let nodes = h.tree.into_iter();

while let Some(node) = hh.next() {
if let Some(element) = node.value().as_element() {
for node in nodes {
if let Some(element) = node.as_element() {
let element_name = element.name();
accessibility_tree
.entry(element_name.to_string())
.and_modify(|n| n.push(element.to_owned()))
.or_insert(Vec::from([element.to_owned()]));
.and_modify(|n| n.push(node.clone()))
.or_insert(Vec::from([node]));
}
}

Expand Down

0 comments on commit 4fe8c08

Please sign in to comment.