Skip to content

Commit fc85aa0

Browse files
feat: add more tests
1 parent 601c8fe commit fc85aa0

30 files changed

Lines changed: 1802 additions & 142 deletions

Cargo.lock

Lines changed: 95 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dom/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ repository.workspace = true
1010
version.workspace = true
1111

1212
[dependencies]
13-
aria-query = "0.0.4"
13+
aria-query = "0.0.5"
1414
dom-accessibility-api = "0.0.3"
1515
log.workspace = true
16+
ordered_hash_map = "0.4.0"
1617
paste = "1.0.15"
1718
pretty-format = { path = "../pretty-format", version = "0.0.1" }
1819
regex.workspace = true
@@ -75,7 +76,9 @@ web-sys = { workspace = true, features = [
7576
[dev-dependencies]
7677
indoc = "2.0.5"
7778
mockall = "0.13.0"
79+
pretty_assertions = "1.4.1"
7880
send_wrapper = "0.6.0"
81+
testing_logger = "0.1.1"
7982
wasm-bindgen-test.workspace = true
8083

8184
[lints.rust]

packages/dom/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use crate::{
88

99
static CONFIG: LazyLock<Arc<Mutex<Config>>> = LazyLock::new(|| {
1010
Arc::new(Mutex::new(Config {
11-
test_id_attribute: "data-testid".into(),
11+
test_id_attribute: "data-testid".to_owned(),
1212
event_wrapper: Arc::new(|cb| cb()),
1313
default_hidden: false,
14-
default_ignore: "script, style".into(),
14+
default_ignore: "script, style".to_owned(),
1515
show_original_stack_trace: false,
1616
throw_suggestions: false,
1717
get_element_error: Arc::new(|message, container| {

packages/dom/src/dom_element_filter.rs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use regex::Regex;
55
use wasm_bindgen::{JsCast, JsValue};
66
use web_sys::{Comment, Element, Node, Text};
77

8-
use crate::util::{named_node_map_to_hashmap, node_list_to_vec};
8+
use crate::util::{named_node_map_to_hashmap, named_node_map_to_vec, node_list_to_vec};
99

1010
fn escape_html(text: String) -> String {
1111
text.replace('<', "&lt;").replace('>', "&gt;")
1212
}
1313

1414
fn print_props(
15-
attributes: HashMap<String, String>,
15+
keys: Vec<String>,
16+
props: HashMap<String, String>,
1617
config: &Config,
1718
indentation: String,
1819
depth: usize,
@@ -21,25 +22,26 @@ fn print_props(
2122
) -> String {
2223
let indentation_next = format!("{}{}", indentation, config.indent);
2324

24-
attributes
25-
.into_iter()
26-
.map(|(key, value)| {
27-
let printed = printer(
28-
&JsValue::from_str(&value),
29-
config,
30-
indentation_next.clone(),
31-
depth,
32-
refs.clone(),
33-
None,
34-
);
25+
keys.into_iter()
26+
.filter_map(|key| {
27+
props.get(&key).map(|value| {
28+
let printed = printer(
29+
&JsValue::from_str(value),
30+
config,
31+
indentation_next.clone(),
32+
depth,
33+
refs.clone(),
34+
None,
35+
);
3536

36-
format!(
37-
"{}{}{}={}",
38-
config.spacing_inner,
39-
indentation,
40-
config.colors.prop.paint(&key),
41-
config.colors.value.paint(&printed)
42-
)
37+
format!(
38+
"{}{}{}={}",
39+
config.spacing_inner,
40+
indentation,
41+
config.colors.prop.paint(&key),
42+
config.colors.value.paint(&printed)
43+
)
44+
})
4345
})
4446
.collect::<Vec<_>>()
4547
.join("")
@@ -67,7 +69,7 @@ fn print_children(
6769

6870
if printed_child.is_empty() && child.node_type() != Node::TEXT_NODE {
6971
// A plugin serialized this Node to '' meaning we should ignore it.
70-
"".into()
72+
"".to_owned()
7173
} else {
7274
format!("{}{}{}", config.spacing_outer, indentation, printed_child)
7375
}
@@ -99,7 +101,7 @@ fn print_element(
99101
"<{}{}{}>",
100102
r#type,
101103
if printed_props.is_empty() {
102-
"".into()
104+
"".to_owned()
103105
} else {
104106
format!(
105107
"{}{}{}{}{}",
@@ -112,9 +114,9 @@ fn print_element(
112114
},
113115
if printed_children.is_empty() {
114116
if !printed_props.is_empty() && !config.min {
115-
"/".into()
117+
"/".to_owned()
116118
} else {
117-
" /".into()
119+
" /".to_owned()
118120
}
119121
} else {
120122
format!(
@@ -207,7 +209,7 @@ impl Plugin for DomElementFilter {
207209
}
208210

209211
let r#type = if node_is_fragment(node) {
210-
"DocumentFragment".into()
212+
"DocumentFragment".to_owned()
211213
} else {
212214
node.unchecked_ref::<Element>().tag_name().to_lowercase()
213215
};
@@ -220,6 +222,19 @@ impl Plugin for DomElementFilter {
220222
print_element(
221223
r#type,
222224
print_props(
225+
if node_is_fragment(node) {
226+
vec![]
227+
} else {
228+
let mut keys =
229+
named_node_map_to_vec(node.unchecked_ref::<Element>().attributes())
230+
.into_iter()
231+
.map(|attr| attr.name())
232+
.collect::<Vec<_>>();
233+
234+
keys.sort();
235+
236+
keys
237+
},
223238
if node_is_fragment(node) {
224239
HashMap::new()
225240
} else {

packages/dom/src/label_helpers.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const LABELLED_NODE_NAMES: [&str; 7] = [
1010

1111
fn get_text_content(node: &Node) -> Option<String> {
1212
if LABELLED_NODE_NAMES.contains(&node.node_name().to_lowercase().as_str()) {
13-
Some("".into())
13+
Some("".to_owned())
1414
} else if node.node_type() == Node::TEXT_NODE {
1515
node.text_content()
1616
} else {
@@ -62,7 +62,8 @@ fn is_labelable(element: &Element) -> bool {
6262
Regex::new(r"BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA")
6363
.expect("Regex should be valid.")
6464
.is_match(&element.tag_name())
65-
|| element.tag_name() == "INPUT" && element.get_attribute("type") != Some("hidden".into())
65+
|| element.tag_name() == "INPUT"
66+
&& element.get_attribute("type") != Some("hidden".to_owned())
6667
}
6768

6869
#[derive(Clone, Debug)]
@@ -76,7 +77,7 @@ pub fn get_labels(
7677
element: &HtmlElement,
7778
selector: Option<String>,
7879
) -> Vec<Label> {
79-
let selector = selector.unwrap_or("*".into());
80+
let selector = selector.unwrap_or("*".to_owned());
8081

8182
let aria_labelled_by = element.get_attribute("aria-labelledby");
8283
let labels_id = aria_labelled_by
@@ -118,7 +119,7 @@ pub fn get_labels(
118119
form_control: None,
119120
})
120121
.unwrap_or(Label {
121-
content: Some("".into()),
122+
content: Some("".to_owned()),
122123
form_control: None,
123124
})
124125
})

packages/dom/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ pub use matches::get_default_normalizer;
2525
pub use pretty_dom::*;
2626
pub use queries::*;
2727
pub use query_helpers::*;
28-
pub use role_helpers::{get_roles, is_inaccessible, log_roles};
28+
pub use role_helpers::{
29+
GetRolesOptions, PrettyRolesOptions, get_implicit_aria_roles, get_roles, is_inaccessible,
30+
log_roles,
31+
};
2932
pub use suggestions::*;
3033
pub use types::*;
3134
pub use wait_for::*;
35+
36+
// TODO: Export useful types from `aria_query`.
37+
pub use aria_query::{AriaRole, AriaRoleDefinitionKey};

0 commit comments

Comments
 (0)