diff --git a/crates/ui-contract/src/testing/fixture.rs b/crates/ui-contract/src/testing/fixture.rs index af7fc72ce..69a3f167e 100644 --- a/crates/ui-contract/src/testing/fixture.rs +++ b/crates/ui-contract/src/testing/fixture.rs @@ -587,16 +587,21 @@ impl Fixture { } /// The node named `label`: the interactive node whose name resolves to it (its own, or the node that labels it - /// through `labelled_by`), else the first node that carries the text. + /// through `labelled_by`) and that labels no other node, so a field's control comes before its caption link; + /// else the first node that carries the text. pub fn by_label(&self, label: &str) -> Option { let tree = &self.tree; let reported: HashSet = tree.keys().into_iter().collect(); + let labels: HashSet = reported.iter().flat_map(|key| tree.labelled_by_key(*key)).collect(); let ordered = self.in_tree_order(&reported); let node = ordered .iter() .copied() .find(|key| { - super::access::name(tree, *key) == Some(label) && tree.role_of(*key) != Some(Role::LABEL) && super::access::is_interactive(tree, *key) + super::access::name(tree, *key) == Some(label) + && tree.role_of(*key) != Some(Role::LABEL) + && !labels.contains(key) + && super::access::is_interactive(tree, *key) }) .or_else(|| ordered.iter().copied().find(|key| tree.name_of(*key) == Some(label)))?; self.target(node) diff --git a/crates/ui-widgets/tests/it/label/link.rs b/crates/ui-widgets/tests/it/label/link.rs index 150005818..d67e81c3d 100644 --- a/crates/ui-widgets/tests/it/label/link.rs +++ b/crates/ui-widgets/tests/it/label/link.rs @@ -67,3 +67,15 @@ fn a_link_label_reports_its_click_to_the_host_and_still_scrubs() { fixture.drag_at(link.label_at(), Vec2::new(DRAG, 0.0)); assert!(link.value.get() > START, "a drag on a link label scrubs: {}", link.value.get()); } + +/// `Fixture::by_label` gives the control a link label names, not the link that carries the same name. +#[trial] +fn by_label_gives_the_control_a_link_label_names() { + let row = Row::new(); + let shown = row.clone(); + let mut fixture = Fixture::new(move |ui| shown.show(ui, "link", SideLabel::new().link(), ROW_A)); + fixture.settle(); + let dial = row.seen.borrow().id.expect("the dial ran"); + let control = fixture.node_of(dial).expect("the dial is in the access tree").node; + assert_eq!(fixture.by_label("Opacity").map(|found| found.node), Some(control), "the label's name finds its control"); +}