Skip to content

Commit

Permalink
Testing: Fix querying for elements by id when using _
Browse files Browse the repository at this point in the history
The compiler normalizes `the_element` to `the-element`, so we also need to normalize that behind our API.
  • Loading branch information
tronical committed Aug 5, 2024
1 parent 531da6a commit cadfd9e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internal/backends/testing/search_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

0 comments on commit cadfd9e

Please sign in to comment.