use stratum_core::aria::AriaRole;
use stratum_core::render::RenderOutput;
pub fn assert_aria_role(output: &RenderOutput, expected: AriaRole) -> bool {
output.aria.role == Some(expected)
}
pub fn assert_has_class(output: &RenderOutput, class: &str) -> bool {
output.classes.iter().any(|c| c == class)
}
pub fn assert_has_attr(output: &RenderOutput, name: &str) -> bool {
output.attrs.iter().any(|(k, _)| k == name)
}
pub fn assert_attr_value(output: &RenderOutput, name: &str, expected: &str) -> bool {
output
.attrs
.iter()
.any(|(k, v)| k == name && v.to_html_value().as_deref() == Some(expected))
}
pub fn assert_has_data_attr(output: &RenderOutput, name: &str) -> bool {
output.data_attrs.iter().any(|(k, _)| k == name)
}
pub fn assert_not_aria_hidden(output: &RenderOutput) -> bool {
output.aria.hidden != Some(true)
}
pub fn assert_tag(output: &RenderOutput, expected: &str) -> bool {
output.effective_tag() == expected
}
#[cfg(test)]
mod tests {
use super::*;
use stratum_core::aria::AriaAttributes;
#[test]
fn test_assert_aria_role_match() {
let output =
RenderOutput::new().with_aria(AriaAttributes::new().with_role(AriaRole::Button));
assert!(assert_aria_role(&output, AriaRole::Button));
}
#[test]
fn test_assert_aria_role_mismatch() {
let output = RenderOutput::new().with_aria(AriaAttributes::new().with_role(AriaRole::Link));
assert!(!assert_aria_role(&output, AriaRole::Button));
}
#[test]
fn test_assert_has_class() {
let output = RenderOutput::new()
.with_class("btn")
.with_class("btn-primary");
assert!(assert_has_class(&output, "btn"));
assert!(assert_has_class(&output, "btn-primary"));
assert!(!assert_has_class(&output, "btn-secondary"));
}
#[test]
fn test_assert_has_data_attr() {
let output = RenderOutput::new().with_data("testid", "save-btn");
assert!(assert_has_data_attr(&output, "testid"));
assert!(!assert_has_data_attr(&output, "other"));
}
#[test]
fn test_assert_tag() {
let output = RenderOutput::new().with_tag("button");
assert!(assert_tag(&output, "button"));
assert!(!assert_tag(&output, "div"));
}
#[test]
fn test_assert_tag_default() {
let output = RenderOutput::new();
assert!(assert_tag(&output, "div"));
}
}