Files
pdfcraft/crates/ui-egui/tests/ui_group/identity.rs
mtlcl410andClaude Opus 5.5 8356665d7b test(ui): wait for the text layer by state, not for a fixed second (#1277) (#2327)
Four ui_group harnesses waited at most one wall-clock second (200 x 5 ms)
for the page to render, and stopped as soon as nothing was pending, which
can be before the text layer is even asked for. Under load the text
layer came later and column-select, identity and update-check tests
failed. They now wait through support::wait_until for what they use (a
glyph on screen, the highlight in the document), with its 30-second
deadline. The highlighter quick-click test of #1277 itself did not fail
on this base in 256 runs.


Claude-Session: https://claude.ai/code/session_01PCdPYhYkggLJVYoME2kr5R

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 02:54:56 -04:00

64 lines
3.2 KiB
Rust

//! Preferences ▸ Identity: the name new comments are signed with.
use egui::accesskit::Role;
use egui::{Key, Modifiers};
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use pdfcraft_ui_egui::PdfCraftApp;
const PDF: &[u8] = b"%PDF-1.7
1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj
3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 300 200] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >> endobj
4 0 obj << /Length 55 >> stream
BT /F1 14 Tf 20 150 Td (The quick brown fox) Tj ET
endstream endobj
5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj
trailer << /Root 1 0 R >>
%%EOF";
#[test]
fn the_identity_name_signs_new_comments_and_is_remembered() {
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {
let mut app = PdfCraftApp::new();
app.set_option("language", "en").unwrap();
app.open_bytes("doc.pdf", None, PDF.to_vec()).expect("opens");
app.set_option("author", "Tester").unwrap();
app.set_option("dialog", "preferences").unwrap();
app
});
h.run_steps(4);
h.get_by_label_contains("Name on new comments");
// Replace the name in the field (the preferences scroll to it in a 900-point window).
h.get_by_role_and_label(Role::TextInput, "Name on new comments").scroll_to_me();
h.run_steps(4);
h.get_by_role_and_label(Role::TextInput, "Name on new comments").click();
h.run_steps(1);
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
h.get_by_role_and_label(Role::TextInput, "Name on new comments").type_text("Grace Hopper");
h.run_steps(2);
assert_eq!(h.state().comment_prefs.author, "Grace Hopper");
// New comments carry it. Wait for the page (and its text) to finish loading first: selecting
// text that hasn't loaded selects nothing, and no highlight is made (seen on slow CI runners).
h.state_mut().set_option("dialog", "none").unwrap();
crate::support::wait_until(&mut h, "the page's text layer", |app| app.views[0].glyph_screen_pos(0, 8).is_some() && !app.render_pending());
h.state_mut().views[0].select_text(0, 4, 8);
assert!(h.state_mut().execute("comment.highlight"));
// Wait for the edit to land in the document (it applies on a later frame).
let author = |h: &Harness<'static, PdfCraftApp>| {
let doc = h.state().session.get(h.state().views[0].id).unwrap();
doc.info.annotations.first().and_then(|a| a.author.clone())
};
crate::support::wait_until(&mut h, "the highlight", |app| app.session.get(app.views[0].id).is_some_and(|d| !d.info.annotations.is_empty()));
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 = PdfCraftApp::new();
restored.set_option("language", "en").unwrap();
restored.restore(&h.state().persist());
assert_eq!(restored.comment_prefs.author, "Grace Hopper");
restored.restore(r#"{"author": " "}"#);
assert_eq!(restored.comment_prefs.author, "Grace Hopper");
restored.restore(&format!(r#"{{"author": "{}"}}"#, "x".repeat(10_000)));
assert_eq!(restored.comment_prefs.author.chars().count(), 200);
}