Testing: Fix querying for elements by id when using _

The compiler normalizes `the_element` to `the-element`, so we also need to normalize that behind our API.
This commit is contained in:
Simon Hausmann 2024-08-02 14:54:56 +02:00 committed by Simon Hausmann
parent 531da6ac51
commit cadfd9e104

View file

@ -154,7 +154,7 @@ impl ElementQuery {
/// Include only elements in the results where [`ElementHandle::id()`] is equal to the provided `id`.
pub fn match_id(mut self, id: impl Into<String>) -> Self {
let id = id.into();
let id = id.into().replace('_', "-");
let mut id_split = id.split("::");
let type_name = id_split.next().map(ToString::to_string);
let local_id = id_split.next();
@ -908,3 +908,23 @@ fn test_matches() {
assert_eq!(root.query_descendants().match_inherits("Base").find_all().len(), 1);
}
#[test]
fn test_normalize_id() {
crate::init_no_event_loop();
slint::slint! {
export component App inherits Window {
the_element := Text {
text: "Found me";
}
}
}
let app = App::new().unwrap();
let root = app.root_element();
assert_eq!(root.query_descendants().match_id("App::the-element").find_all().len(), 1);
assert_eq!(root.query_descendants().match_id("App::the_element").find_all().len(), 1);
}