Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

About dialog test: wait for each control to stop moving before clicking it (#671) (#703)

DWAA1660c02fe8ca53c2
diff --git a/crates/ui-egui/tests/links.rs b/crates/ui-egui/tests/links.rs
index 199fdb3f6..b08036b11 100644
--- a/crates/ui-egui/tests/links.rs
+++ b/crates/ui-egui/tests/links.rs
@@ -66,22 +66,37 @@ fn help_commands_open_each_link() {
}
}
+/// Runs frames until the node labelled `label` exists and has stopped moving, then returns it.
+///
+/// The About dialog is a modal centred on its own size, and switching tabs changes that size, so
+/// for a few frames afterwards the modal grows and recentres and every control in it moves. A
+/// fixed number of frames is a guess at how long that takes: it was too few after the 0.5.0
+/// contributors refresh (78 names instead of 5) on some machines, the click on Table landed where
+/// the button had been, and the table never opened (#671).
+fn settled<'a>(h: &'a mut Harness<'static, PdfCraftApp>, label: &'a str) -> egui_kittest::Node<'a> {
+ let mut last = None;
+ for _ in 0..60 {
+ h.run_steps(1);
+ let now = h.query_by_label(label).map(|n| n.rect());
+ if now.is_some() && now == last {
+ return h.get_by_label(label);
+ }
+ last = now;
+ }
+ panic!("{label:?} never appeared or never stopped moving");
+}
+
#[test]
fn about_dialog_has_contributors_and_models_tabs() {
let mut h = harness(|app| app.dialog = Some(Dialog::About));
- h.get_by_label("Contributors").click();
- // Tab changes resize and recenter the modal as the compiled-in credits grow.
- // Let its layout settle before clicking the next control at its new position.
- h.run_steps(4);
+ settled(&mut h, "Contributors").click();
// The owner is always in the compiled-in credits (contributors/contributors.json), shown by username.
- h.get_by_label("@echelon");
- h.get_by_label("Table").click();
- h.run_steps(4);
- h.get_by_label("PRs");
- h.get_by_label("Display name").click();
- h.run_steps(4);
- h.get_by_label("Brandon Thomas");
- h.get_by_label("Models").click();
+ settled(&mut h, "@echelon");
+ settled(&mut h, "Table").click();
+ settled(&mut h, "PRs");
+ settled(&mut h, "Display name").click();
+ settled(&mut h, "Brandon Thomas");
+ settled(&mut h, "Models").click();
h.run_steps(4);
assert!(h.query_all_by_label("Anthropic").count() >= 1);
}