diff --git a/crates/text/tests/it/find.rs b/crates/text/tests/it/find.rs index cb2fc5ca0..33749ba00 100644 --- a/crates/text/tests/it/find.rs +++ b/crates/text/tests/it/find.rs @@ -3,7 +3,7 @@ use craft_text::ui::find::{FindReplaceDialog, FindRequest, FindTab, GoToKind}; use craft_ui::dialog::{DialogStack, StackDialog as _}; use craft_ui::runtime::access::Role; -use craft_ui::testing::{Fixture, trial}; +use craft_ui::testing::{Fixture, Target, trial}; use std::cell::RefCell; use std::rc::Rc; @@ -17,6 +17,12 @@ fn open(kinds: Vec) -> (Fixture, Rc>) { (fixture, dialog) } +/// The footer button named `label`: the Go To tab carries the same words, and `by_label` finds the tab first. +fn button(fixture: &Fixture, label: &str) -> Option { + let tree = fixture.tree(); + fixture.by_role(Role::BUTTON).into_iter().find(|target| craft_ui::testing::access::name(tree, target.node) == Some(label)) +} + #[trial] fn go_to_steps_on_an_empty_page_and_names_a_bookmark() { let (mut fixture, dialog) = open(vec![GoToKind::typed("Page", "Enter a page number", true)]); @@ -30,7 +36,7 @@ fn go_to_steps_on_an_empty_page_and_names_a_bookmark() { let field = fixture.by_label("Page").expect("the target field"); fixture.click(&field).type_text("12").idle(4); assert!(fixture.by_label("Previous").is_none(), "a typed target leaves Previous out"); - let go = fixture.by_label("Go To").expect("a typed target turns Next back into Go To"); + let go = button(&fixture, "Go To").expect("a typed target turns Next back into Go To"); fixture.click(&go).idle(4); assert_eq!(dialog.borrow_mut().take_request(), Some(FindRequest::go_to(0, "12"))); @@ -45,13 +51,13 @@ fn go_to_steps_on_an_empty_page_and_names_a_bookmark() { let fields = dialog.borrow().json_fields().expect("the dialog's fields"); assert_eq!(fields["goToKind"], 1); assert_eq!(fields["goToTarget"], "", "a kind change clears the target"); - let go = fixture.by_label("Go To").expect("Go To is shown"); + let go = button(&fixture, "Go To").expect("Go To is shown"); fixture.click(&go).idle(4); assert_eq!(dialog.borrow_mut().take_request(), Some(FindRequest::go_to(1, ""))); let (mut fixture, dialog) = open(vec![GoToKind::named("Bookmark", Vec::new(), "No bookmarks")]); assert!(fixture.by_label("No bookmarks").is_some(), "no names shows the empty line"); - let go = fixture.by_label("Go To").expect("Go To is shown"); + let go = button(&fixture, "Go To").expect("Go To is shown"); fixture.click(&go).idle(4); assert_eq!(dialog.borrow_mut().take_request(), None, "Go To is disabled without names"); }