Tests: run the app window as an eframe app, so every pass has the app's input

The app-window harnesses built a ui closure that made the app's input inside a
pass and handed it to the runtime when the next pass began, so each pass ran
on the previous pass's input and the build pass had none. The page picture
loader fixes its job queue from the host it first sees, so in tests it took
the default thread queue instead of the app's host jobs, and the big-table
scrolling test read the resident picture count before those threads finished:
it failed intermittently on loaded runners (Windows).

The harnesses now build with kittest's `build_eframe` over a test-only
`eframe::App` for `WordApp` whose `raw_input_hook` calls `embed::before_input`,
as the desktop driver does. `driver_logic`, `HandOver` and its pending input
are gone.

The scrolling test gives the app a host with `ManualJobs`, runs the queued
renders after each scroll step and checks that the renders use the host's
jobs. Its table and scroll steps are smaller; the relations are unchanged.

Key chords fire their command in the runtime's key stage, which the app reads
before the next pass, as on the desktop: the chord rows step twice.

ui-egui declares `craft`'s `ui-testing` for its own tests, so they build
without the workspace's feature union.
This commit is contained in:
aiongg
2026-11-22 04:44:26 +00:00
parent 678f9473d8
commit 8fb8a5b789
9 changed files with 82 additions and 208 deletions
Generated
+1
View File
@@ -9328,6 +9328,7 @@ dependencies = [
"craft-fonts-build",
"craft-ui-test-kit",
"craft-zip",
"eframe",
"egui",
"egui_extras",
"egui_kittest",
+6 -1
View File
@@ -65,10 +65,15 @@ wordcraft-engine = { workspace = true, features = ["test-support"] }
# kittest's own dev-dependencies do not propagate their font features. Declare the fonts the
# interface tests lay out explicitly: default faces plus monochrome emoji fallbacks.
egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] }
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
egui_kittest = { workspace = true, features = ["wgpu", "snapshot", "eframe"] }
# The app-window tests run `WordApp` as an `eframe::App` (`test_harness`), so the runtime gets the app's input before
# every pass as on the desktop. The desktop app's feature set, so a workspace build shares one eframe.
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit", "clipboard", "wayland", "x11", "links"] }
craft-zip = { workspace = true }
# The window tests' frame driver for child viewports; it is not part of the `craft` facade.
craft-ui-test-kit = { workspace = true }
# The interface tests' fixture and access tree (`craft::ui::testing`).
craft = { workspace = true, features = ["ui-testing"] }
[build-dependencies]
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "243d68e12d05e89122db6d154924bf1992e10d38", features = ["subset"] }
+1 -8
View File
@@ -699,14 +699,7 @@ pub(crate) mod testing {
/// A harness that runs the app's logic and UI each frame in a 1440×900 window.
pub(crate) fn harness(app: WordApp) -> Harness<'static, WordApp> {
crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
app,
)
crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app)
}
/// Confirms the dialog `id` as OK does and runs the passes it takes to file the held OK and finish: the held OK
+25 -38
View File
@@ -10,6 +10,10 @@
//! Use [`builder`] instead of `egui_kittest::Harness::builder()` (the framework lint `test/kit`
//! flags direct use); chain `with_size`, `with_step_dt` and the rest on the result as before.
//! [`builder_with`] takes a custom install spec, e.g. a memory clipboard or a fake system.
//!
//! A test of the whole app window builds with `build_eframe(|_| app)`: the harness then runs the app
//! as the desktop driver does (the `eframe::App` impl below), handing the runtime the app's input
//! before every pass, the build pass included.
use craft::ui::InstallSpec;
use egui_kittest::HarnessBuilder;
@@ -33,37 +37,12 @@ pub(crate) fn builder<S>() -> HarnessBuilder<S> {
/// Like [`builder`], with the install spec `spec` makes (called when the context is set up).
pub(crate) fn builder_with<S>(spec: impl FnOnce() -> InstallSpec + 'static) -> HarnessBuilder<S> {
egui_kittest::Harness::builder().with_context_setup(move |ctx| {
// Before the runtime's plugin: egui runs input hooks in registration order, and the runtime's key stage reads
// the input this hands it.
ctx.add_plugin(HandOver);
// A frame may draw a file name or language name in CJK on its first pass; a CI runner has no CJK font.
cjk_stand_in(ctx);
craft::ui::shell::embed::install(ctx, spec(), &crate::ui_fonts(Lang::EN)).expect("the craft runtime installs on a fresh test context");
})
}
thread_local! {
/// The input the app made in the last pass ([`driver_logic`]), waiting for the next pass to start.
static PENDING: std::cell::RefCell<Option<craft::ui::runtime::frame::FrameInput>> = const { std::cell::RefCell::new(None) };
}
/// Hands the runtime the input [`driver_logic`] left, before the next pass begins (egui's input hook runs
/// before `begin_pass`). The runtime refuses input during a pass, and a kittest harness has no eframe
/// `raw_input_hook` to give it at the right time.
struct HandOver;
impl egui::Plugin for HandOver {
fn debug_name(&self) -> &'static str {
"wordcraft::test_harness::HandOver"
}
fn input_hook(&mut self, ctx: &egui::Context, _input: &mut egui::RawInput) {
if let Some(input) = PENDING.with(|p| p.borrow_mut().take()) {
craft::ui::runtime::frame::set_input(ctx, input);
}
}
}
/// A bare egui context with the craft runtime installed (the framework's test spec), for a test that
/// runs frames by hand (`ctx.run_ui`) instead of through a kittest harness. A frame on a context
/// without the runtime has no command registry, so the canvas's publish of its view commands
@@ -83,11 +62,12 @@ pub(crate) fn context_with(spec: impl FnOnce() -> InstallSpec) -> egui::Context
ctx
}
/// One frame of `h` as the app's driver runs it: the runtime is first handed the input the app makes
/// (`WordApp::frame_input`: the command catalog, each command's state, the fired commands), as
/// eframe's raw-input hook does (`embed::before_input`). `Harness::step` and `run_steps` skip the
/// hook, so a command-bound control is named by its command id and a clicked control's command never
/// runs. A test that finds such a control by its label, or needs its command to run, steps here.
/// One frame of `h`, a harness built with a ui closure, as the app's driver runs it: the runtime is first handed the
/// input the app makes (`WordApp::frame_input`: the command catalog, each command's state, the fired commands), as
/// eframe's raw-input hook does (`embed::before_input`). On such a harness `Harness::step` and `run_steps` skip the
/// hook, so a command-bound control is named by its command id and a clicked control's command never runs. A test
/// that finds such a control by its label, or needs its command to run, steps here. A `build_eframe` harness hands
/// the input itself on every step.
pub(crate) fn frame(h: &mut egui_kittest::Harness<'_, crate::WordApp>) {
let ctx = h.ctx.clone();
craft::ui::shell::embed::before_input(&ctx, |out| h.state_mut().frame_input(out));
@@ -153,14 +133,21 @@ pub(crate) fn logic(ctx: &egui::Context, app: &mut crate::WordApp) {
craft::ui::shell::embed::logic(ctx, || app.close_decision());
}
/// [`logic`] for a kittest closure, where the harness's `step` and `run_steps` skip eframe's input hook: the app
/// makes its input (`WordApp::frame_input`) at the head of the pass, and the runtime takes it when the next pass
/// begins (it refuses input during a pass), so command states, fired commands and focus requests reach the
/// passes after it, one frame behind. Needs a harness from [`builder`] or [`builder_with`].
pub(crate) fn driver_logic(ctx: &egui::Context, app: &mut crate::WordApp) {
let input = app.frame_input(craft::ui::runtime::frame::take_output(ctx));
PENDING.with(|p| *p.borrow_mut() = Some(input));
logic(ctx, app);
/// The app as the desktop driver runs it (apps/wordcraft's `eframe::App`), for a `build_eframe` harness: kittest
/// calls the raw-input hook before every pass, so each pass has the app's input (the root env with the host, the
/// command states, the fired commands), as in production.
impl eframe::App for crate::WordApp {
fn raw_input_hook(&mut self, ctx: &egui::Context, _raw: &mut egui::RawInput) {
craft::ui::shell::embed::before_input(ctx, |out| self.frame_input(out));
}
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
logic(ctx, self);
}
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
crate::WordApp::ui(self, ui);
}
}
/// One frame of `app` on a bare context from [`context`], as the app's driver runs it: the runtime is handed the
+20 -104
View File
@@ -80,10 +80,12 @@ fn press_ctrl_f1(h: &mut egui_kittest::Harness<'static, WordApp>) {
/// A harness over the app, as the tables below drive it.
type Rig = egui_kittest::Harness<'static, WordApp>;
/// One key press with `modifiers`, then a frame.
/// One key press with `modifiers`, then two frames: the runtime fires the chord's command in the first, and the app
/// runs it before the second (`raw_input_hook`), as on the desktop.
fn press(h: &mut Rig, key: egui::Key, modifiers: egui::Modifiers) {
h.event(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers });
h.step();
h.step();
}
/// The style of the first paragraph.
@@ -180,9 +182,6 @@ fn row_bound_ctrl_f1_runs_the_bound_command() {
let mut h = canvas_harness();
// PLAN(shell-w7): sh.A11 `Session::keymap_mut` over `Overrides::insert`.
h.state_mut().session.keymap_mut().insert("view.focus", vec!["Mod+F1".into()]);
// The harness hands the app's input (with the user's bindings) to the runtime one frame behind (`driver_logic`),
// so the binding reaches the keymap in the frame after it is made, as in the row for Mod+Shift+0.
h.step();
press_ctrl_f1(&mut h);
assert!(h.state().session.view.focus_mode, "the bound command ran");
assert!(!h.state().ui.ribbon_collapsed, "the ribbon is unchanged");
@@ -271,14 +270,15 @@ fn row_mod_shift_0_resets_the_interface_size_unless_bound() {
assert_eq!(body_text(h.state()), "}", "AltGr+0 types the character");
h.event(egui::Event::Key { key: egui::Key::Num0, physical_key: Some(egui::Key::Num0), pressed: true, repeat: false, modifiers: chord });
h.step();
h.step();
assert!(h.state().ui.interface_size.is_auto(), "Ctrl+Shift+0 returns to Auto");
// A binding the user made for the chord wins.
h.state_mut().run("ui.interfaceSize", json!({"percent": 300})).unwrap();
// PLAN(shell-w7): sh.A11 `Session::keymap_mut` over `Overrides::insert`.
h.state_mut().session.keymap_mut().insert("view.focus", vec!["Mod+Shift+0".into()]);
h.step();
h.event(egui::Event::Key { key: egui::Key::Num0, physical_key: Some(egui::Key::Num0), pressed: true, repeat: false, modifiers: chord });
h.step();
h.step();
assert_eq!(h.state().ui.interface_size.percent(), Some(300), "the size stays");
assert!(h.state().session.view.focus_mode, "the user's binding runs");
}
@@ -296,7 +296,7 @@ fn row_mod_shift_equals_stays_superscript() {
let chord = egui::Modifiers { alt: false, ctrl: true, shift: true, mac_cmd: false, command: true };
h.event(egui::Event::Key { key: egui::Key::Equals, physical_key: Some(egui::Key::Num0), pressed: true, repeat: false, modifiers: chord });
h.step();
// The chord fires its command in that pass; the app runs it when the next pass begins (`driver_logic`).
// The chord fires its command in that pass; the app runs it before the next pass (`raw_input_hook`).
h.step();
assert_eq!(h.state().ui.interface_size.percent(), Some(300), "Ctrl+Shift+= doesn't reset");
let pos = wordcraft_doc::Pos { story: wordcraft_doc::StoryRef::Body, path: wordcraft_doc::Path::top(0), off: 0 };
@@ -490,14 +490,7 @@ fn a_japanese_file_name_is_drawn_in_the_caption() {
/// first frame fires that release builds and the components' own trials never reach.
#[test]
fn the_app_window_shows_for_a_few_frames() {
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
app(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app());
h.run_steps(3);
assert!(h.state().has_document(), "the window opened on a document");
assert!(!h.state().quit_requested);
@@ -633,14 +626,7 @@ fn display_server_is_a_ui_command_and_survives_a_restart() {
}
fn harness(a: WordApp) -> egui_kittest::Harness<'static, WordApp> {
crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
)
crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a)
}
/// #1908: with no document open the Home ribbon's split buttons grey out like the plain
@@ -1539,14 +1525,7 @@ fn every_cut_entry_point_publishes_to_the_clipboard() {
assert!(copied(&ctx).contains(&text), "ribbon Cut published {text:?}: {:?}", copied(&ctx));
// A real Cut key event through the app's key handling.
let mut h = crate::test_harness::builder_with(spec).with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
typed(),
);
let mut h = crate::test_harness::builder_with(spec).with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| typed());
for _ in 0..6 {
h.step();
}
@@ -2009,14 +1988,7 @@ fn the_default_app_button_shows_only_with_the_hosts_hook() {
}));
}
a.run("ui.backstage", json!({"value": true, "page": "options"})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
h.run_steps(4);
assert!(h.query_by_label("Show the community button in the title bar").is_some(), "hook {hook}: the Options page rendered");
// The row carries the label too (macOS shows it, with Finder's steps instead of a button): ask for the button.
@@ -2069,14 +2041,7 @@ fn the_host_hears_about_edits_made_while_drawing() {
let mut a = app();
let seen = reported.clone();
a.services.on_dirty = Some(Box::new(move |d| seen.set(Some(d))));
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
for _ in 0..6 {
h.step();
}
@@ -2092,14 +2057,7 @@ fn the_host_hears_about_edits_made_while_drawing() {
fn paragraph_alignment_keeps_the_canvas_focused_for_typing() {
use wordcraft_doc::Align;
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
typed(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| typed());
for _ in 0..6 {
h.step();
}
@@ -2108,7 +2066,7 @@ fn paragraph_alignment_keeps_the_canvas_focused_for_typing() {
[("Align Left", Align::Left, " left"), ("Center", Align::Center, " center"), ("Align Right", Align::Right, " right")]
{
h.get_by_role_and_label(egui::accesskit::Role::Button, label).click();
// The click fires the button's command in that pass; the app runs it when the next pass begins (`driver_logic`).
// The click fires the button's command in that pass; the app runs it before the next pass (`raw_input_hook`).
h.step();
h.step();
@@ -2148,14 +2106,7 @@ fn type_after_click(h: &mut egui_kittest::Harness<'_, WordApp>, what: &str, text
fn clicks_on_ribbon_and_status_bar_chrome_keep_typing_in_the_document() {
use egui::accesskit::Role;
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
typed(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| typed());
for _ in 0..6 {
h.step();
}
@@ -3354,21 +3305,14 @@ fn ctrl_shift_equals_on_the_zero_key_stays_superscript() {
a.run("document.setText", json!({"text": "x"})).unwrap();
a.run("select.all", json!({})).unwrap();
a.run("ui.interfaceSize", json!({"percent": 300})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
for _ in 0..6 {
h.step();
}
let chord = egui::Modifiers { alt: false, ctrl: true, shift: true, mac_cmd: false, command: true };
h.event(egui::Event::Key { key: egui::Key::Equals, physical_key: Some(egui::Key::Num0), pressed: true, repeat: false, modifiers: chord });
h.step();
// The chord fires its command in that pass; the app runs it when the next pass begins (`driver_logic`).
// The chord fires its command in that pass; the app runs it before the next pass (`raw_input_hook`).
h.step();
assert_eq!(h.state().ui.interface_size.percent(), Some(300), "Ctrl+Shift+= doesn't reset");
let pos = wordcraft_doc::Pos { story: wordcraft_doc::StoryRef::Body, path: wordcraft_doc::Path::top(0), off: 0 };
@@ -3381,14 +3325,7 @@ fn ctrl_shift_equals_on_the_zero_key_stays_superscript() {
#[test]
fn f11_and_escape_toggle_full_screen() {
use egui::ViewportCommand::Fullscreen;
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
app(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app());
for _ in 0..6 {
h.step();
}
@@ -3432,14 +3369,7 @@ fn f11_and_escape_toggle_full_screen() {
#[test]
fn escape_collapses_a_selection_before_leaving_full_screen() {
use egui::ViewportCommand::Fullscreen;
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
app(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app());
for _ in 0..6 {
h.step();
}
@@ -3578,14 +3508,7 @@ fn pasted_picture_inserts_only_when_the_page_is_the_edit_target() {
fn paste_harness(a: WordApp) -> egui_kittest::Harness<'static, WordApp> {
use craft::platform::clipboard::Clipboard;
let spec = || crate::test_harness::install_spec().clipboard(Clipboard::new(LatePaste::default()));
let mut h = crate::test_harness::builder_with(spec).with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder_with(spec).with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
for _ in 0..6 {
h.step();
}
@@ -3847,14 +3770,7 @@ fn render_without_a_path_replies_with_the_png() {
#[test]
fn shift_f10_opens_the_context_menu_at_the_caret() {
use egui_kittest::kittest::Queryable;
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
app(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app());
for _ in 0..6 {
h.step();
}
+1 -1
View File
@@ -733,7 +733,7 @@ fn alt_q_opens_search_and_typing_goes_there() {
// Both in one frame's input, as the platform sends them: kittest's `event` runs a frame for each queued event.
h.input_mut().events.extend([open.clone(), egui::Event::Text("q".into())]);
h.step();
// The chord fires the command in that pass; the app runs it when the next pass begins (`driver_logic`).
// The chord fires the command in that pass; the app runs it before the next pass (`raw_input_hook`).
h.step();
// The title bar shows the Search box, so Search opens there, in place (#5398).
assert!(h.state().dialog_host.open_dialogs().is_empty(), "no Search Commands dialog over the page");
+3 -24
View File
@@ -69,14 +69,7 @@ fn table_properties_dialog_sets_every_selected_row() {
a.run("table.properties", json!({})).unwrap();
// Drawn: one click on the mixed box turns breaking on for every row.
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
for _ in 0..4 {
h.step();
}
@@ -305,14 +298,7 @@ fn recipient_grid_edits_the_right_record_through_the_ui() {
a.run("mailings.recipients", json!({"csv": "Name,City\nAda,London\nAlan,Wilmslow\nGrace,London\nÉmile,Paris"})).unwrap();
a.run("mailings.filterRecipients", json!({"rules": [{"field": "City", "op": "equal", "value": "London"}]})).unwrap();
dialogs::open(&mut a, "recipientList", &json!({})).expect("the dialog opens");
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut State| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
h.run_steps(4);
let dlg = |h: &egui_kittest::Harness<'_, State>| {
let d = h.state().dialog_host.get::<RecipientListDialog>().expect("the recipient dialog is open");
@@ -436,14 +422,7 @@ fn an_existing_list_picked_on_the_web_loads_recipients() {
/// pane's search box (with the selected text in it), not a dialog.
#[test]
fn find_replace_and_go_to_keys_like_word() {
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
app(),
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| app());
for _ in 0..6 {
h.step();
}
+23 -16
View File
@@ -1,5 +1,8 @@
//! Scrolling performance with a very large table (#811).
use std::sync::Arc;
use craft::host::{Host, ManualJobs};
use wordcraft_doc::table::{Cell, Table};
use wordcraft_doc::{Block, Document, Path, StoryRef};
@@ -20,16 +23,13 @@ pub(crate) fn big_table_doc(rows: usize, cols: usize) -> Document {
d
}
fn harness(doc: Document) -> egui_kittest::Harness<'static, WordApp> {
let a = WordApp::new(wordcraft_engine::Session::new(doc), Services::default());
crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
)
/// A harness over `doc` whose host runs a job only when the test runs its queue ([`ManualJobs`]): page pictures render
/// on the test thread at the points the test picks, so what is resident never depends on the runner's load.
fn harness(doc: Document) -> (egui_kittest::Harness<'static, WordApp>, Arc<ManualJobs>) {
let jobs = Arc::new(ManualJobs::new());
let host = Host::builder(crate::APP).i18n(crate::i18n::catalogs()).lang(craft::i18n::Lang::EN).jobs(jobs.clone()).build();
let a = WordApp::new(wordcraft_engine::Session::new(doc), Services::default()).with_host(Arc::new(host));
(crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a), jobs)
}
/// Queues a pointer move to (720, 500) and a vertical point-unit wheel event that scrolls the view `dy` points.
@@ -50,10 +50,12 @@ fn wheel(h: &mut egui_kittest::Harness<'static, WordApp>, dy: f32) {
/// #811: scrolling through one very large table was slow because every frame fingerprinted every
/// item of every page (thousands of cell borders a page) for the page texture cache, and every
/// page ever shown kept its texture. Now a frame lays nothing out again, fingerprints a page once
/// per layout and only when it is on screen, and keeps textures only near the view.
/// per layout and only when it is on screen, and keeps textures only near the view. The pictures render on the
/// host's jobs, which the test runs after each scroll step, so the renders for the view have finished when the next
/// frame uploads them.
#[test]
fn scrolling_a_big_table_fingerprints_only_pages_coming_into_view() {
let mut h = harness(big_table_doc(600, 8));
let (mut h, jobs) = harness(big_table_doc(400, 8));
h.run_steps(4);
let layout = h.state_mut().session.layout();
let pages = layout.pages.len();
@@ -63,21 +65,26 @@ fn scrolling_a_big_table_fingerprints_only_pages_coming_into_view() {
// Idle frames do no per-page work.
h.run_steps(3);
assert_eq!(h.state().canvas.page_keys.hashed, first, "idle frames fingerprint nothing");
// Scroll a long way down: each newly shown page is fingerprinted once.
assert!(jobs.waiting() > 0, "the pages in view render on the host's jobs");
// Scroll a long way down: each newly shown page is fingerprinted once. The renders a step asks for finish before
// the next step, whose frame uploads them.
let mut max_textures = 0;
for _ in 0..60 {
wheel(&mut h, -400.0);
for _ in 0..11 {
wheel(&mut h, -2000.0);
h.step();
max_textures = max_textures.max(h.state().canvas.resident_pictures);
jobs.run_all();
}
h.step();
let offset = h.state().canvas.view.offset.1;
assert!(offset > 20_000.0, "scrolled through many pages: {offset}");
let after = std::sync::Arc::clone(&h.state_mut().session.layout());
assert!(std::sync::Arc::ptr_eq(&layout, &after), "scrolling never lays the document out again");
let hashed = h.state().canvas.page_keys.hashed;
// 60 steps of 400 pt cross about 24'000 / 1'056 ≈ 23 pages (at 100%, 1.33 px a point).
// 11 steps of 2'000 pt cross about 22'000 / 1'056 ≈ 21 pages (at 100%, 1.33 px a point).
assert!(hashed < pages && hashed <= first + 30, "pages fingerprinted: {hashed} of {pages}");
// Textures stay bounded to the pages near the view.
max_textures = max_textures.max(h.state().canvas.resident_pictures);
assert!(max_textures <= 12, "textures kept while scrolling: {max_textures}");
assert!(h.state().canvas.resident_pictures >= 1, "the pages in view stay rendered");
}
+2 -16
View File
@@ -85,14 +85,7 @@ fn picking_a_wordart_style_hands_the_keyboard_back_to_the_page() {
use egui_kittest::kittest::{By, Queryable};
let mut a = app();
a.run("ui.tab", json!({"tab": "Insert"})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
h.run_steps(4);
// Insert › Decorative Text is the WordArt gallery's opener, under that name in production too.
h.get_by_role_and_label(egui::accesskit::Role::Button, "Decorative Text").click();
@@ -158,14 +151,7 @@ fn citations_provider_menu_has_zotero_checked() {
}
assert_eq!(a.session.undo_depth(), depth, "not an undo step");
a.run("ui.tab", json!({"tab": "Citations"})).unwrap();
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
crate::test_harness::driver_logic(&ctx, app);
app.ui(ui);
},
a,
);
let mut h = crate::test_harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_eframe(|_| a);
h.run_steps(4);
h.get_by_role_and_label(egui::accesskit::Role::Button, "Provider").click();
h.run_steps(3);