Skip to content

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

Identity test: wait for the highlight to land before reading its author

Brandon Thomasd7749e63794c
diff --git a/crates/ui-egui/tests/identity.rs b/crates/ui-egui/tests/identity.rs
index a09a6d5fa..1e4fa9a7b 100644
--- a/crates/ui-egui/tests/identity.rs
+++ b/crates/ui-egui/tests/identity.rs
@@ -39,9 +39,19 @@ fn the_identity_name_signs_new_comments_and_is_remembered() {
h.state_mut().set_option("dialog", "none").unwrap();
h.state_mut().views[0].select_text(0, 4, 8);
assert!(h.state_mut().execute("comment.highlight"));
- h.run_steps(2);
- let doc = h.state().session.get(h.state().views[0].id).unwrap();
- assert_eq!(doc.info.annotations.first().and_then(|a| a.author.as_deref()), Some("Grace Hopper"));
+ // Wait for the edit to land in the document (it applies on a later frame).
+ let author = |h: &Harness<'static, PrintCraftApp>| {
+ let doc = h.state().session.get(h.state().views[0].id).unwrap();
+ doc.info.annotations.first().and_then(|a| a.author.clone())
+ };
+ for _ in 0..100 {
+ if author(&h).is_some() {
+ break;
+ }
+ h.run_steps(1);
+ std::thread::sleep(std::time::Duration::from_millis(5));
+ }
+ assert_eq!(author(&h).as_deref(), Some("Grace Hopper"));
// It survives a restart; an empty or missing name keeps the default, and a huge one is cut.
let mut restored = PrintCraftApp::new();
restored.restore(&h.state().persist());