Compare commits

..
Author SHA1 Message Date
Dylan M. Taylor c6fff6d3e2 ci: use artcraft-k8s-trusted runner on main 2026-11-21 22:55:17 -05:00
11 changed files with 214 additions and 103 deletions
+1
View File
@@ -21,6 +21,7 @@ jobs:
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
with:
os: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && '["artcraft-k8s-trusted"]' || '["ubuntu-24.04"]' }}
# Same craft-fonts commit as release.yml.
craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
packages: >-
Generated
-1
View File
@@ -9328,7 +9328,6 @@ dependencies = [
"craft-fonts-build",
"craft-ui-test-kit",
"craft-zip",
"eframe",
"egui",
"egui_extras",
"egui_kittest",
+1 -6
View File
@@ -65,15 +65,10 @@ 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", "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"] }
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
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"] }
+8 -1
View File
@@ -699,7 +699,14 @@ 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_eframe(|_| app)
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,
)
}
/// Confirms the dialog `id` as OK does and runs the passes it takes to file the held OK and finish: the held OK
+2 -16
View File
@@ -875,9 +875,7 @@ impl StackDialog for AddLanguage {
let endonym = shown(&pack.name, MAX_BAR_NAME);
let detail = if endonym == *name { pack.locale.clone() } else { format!("{endonym} · {}", pack.locale) };
let wants = &wants;
// The licence is the row's wrapped secondary text: `below` components share one line, and the error
// notice (or the progress bar while installing) needs the row's width there.
let mut row = ListRow::new(format!("{name} · {detail}")).lines(licence_hover(pack));
let mut row = ListRow::new(format!("{name} · {detail}"));
match progress(&pack.locale) {
Some((done, total)) => {
let locale = pack.locale.clone();
@@ -899,6 +897,7 @@ impl StackDialog for AddLanguage {
});
}
}
row = row.below(Text::new(licence_hover(pack)).shade(Shade::Faint), |_| {});
if let Some(e) = error_in(errors, &pack.locale) {
row = row.below(Notice::new(Tone::Bad, e).id_salt(("row_error", at)), |_| {});
}
@@ -1633,19 +1632,6 @@ mod tests {
assert!(a.packs_rt.errors.values().any(|e| e.contains("Only you")), "{:?}", a.packs_rt.errors);
let tree = settled(&mut a, &ctx);
assert!(labels(&tree).iter().any(|l| l.contains("Only you")), "the row says why: {:?}", labels(&tree));
// The reason has room to be read: it is at least as wide as Install and within the list's width (the row may sit
// partly below the list's visible edge).
let rect = |pick: &dyn Fn(&egui::accesskit::Node) -> bool| {
tree.nodes.iter().filter(|(_, n)| pick(n)).filter_map(|(_, n)| n.bounds()).collect::<Vec<_>>()
};
let list = rect(&|n| n.role() == egui::accesskit::Role::List && n.label() == Some("Languages"));
let button = rect(&|n| n.label().is_some_and(|l| l.starts_with("Install (")));
let why = rect(&|n| n.label().is_some_and(|l| l.contains("Only you")));
let (list, button) = (list.first().expect("the list"), button.first().expect("an Install button"));
assert!(
why.iter().any(|w| w.width() >= button.width() && w.x0 >= list.x0 && w.x1 <= list.x1 && w.y0 < list.y1),
"the reason is as wide as Install and within the list's width: {why:?}, Install {button:?}, list {list:?}"
);
// The person's own click on the same row turns it on.
let install = spot(&tree, "Install").expect("the row still offers Install");
user_click(&mut a, &ctx, install);
+38 -25
View File
@@ -10,10 +10,6 @@
//! 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;
@@ -37,12 +33,37 @@ 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
@@ -62,12 +83,11 @@ pub(crate) fn context_with(spec: impl FnOnce() -> InstallSpec) -> egui::Context
ctx
}
/// 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.
/// 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.
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));
@@ -133,21 +153,14 @@ pub(crate) fn logic(ctx: &egui::Context, app: &mut crate::WordApp) {
craft::ui::shell::embed::logic(ctx, || app.close_decision());
}
/// 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);
}
/// [`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);
}
/// One frame of `app` on a bare context from [`context`], as the app's driver runs it: the runtime is handed the
+104 -20
View File
@@ -80,12 +80,10 @@ 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 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.
/// One key press with `modifiers`, then a frame.
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.
@@ -182,6 +180,9 @@ 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");
@@ -270,14 +271,13 @@ 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.event(egui::Event::Key { key: egui::Key::Num0, physical_key: Some(egui::Key::Num0), pressed: true, repeat: false, modifiers: chord });
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();
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 before the next pass (`raw_input_hook`).
// The chord fires its command in that pass; the app runs it when the next pass begins (`driver_logic`).
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,7 +490,14 @@ 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_eframe(|_| app());
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(),
);
h.run_steps(3);
assert!(h.state().has_document(), "the window opened on a document");
assert!(!h.state().quit_requested);
@@ -626,7 +633,14 @@ 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_eframe(|_| a)
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,
)
}
/// #1908: with no document open the Home ribbon's split buttons grey out like the plain
@@ -1525,7 +1539,14 @@ 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_eframe(|_| typed());
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(),
);
for _ in 0..6 {
h.step();
}
@@ -1988,7 +2009,14 @@ 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_eframe(|_| a);
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,
);
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.
@@ -2041,7 +2069,14 @@ 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_eframe(|_| a);
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,
);
for _ in 0..6 {
h.step();
}
@@ -2057,7 +2092,14 @@ 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_eframe(|_| typed());
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(),
);
for _ in 0..6 {
h.step();
}
@@ -2066,7 +2108,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 before the next pass (`raw_input_hook`).
// The click fires the button's command in that pass; the app runs it when the next pass begins (`driver_logic`).
h.step();
h.step();
@@ -2106,7 +2148,14 @@ 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_eframe(|_| typed());
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(),
);
for _ in 0..6 {
h.step();
}
@@ -3305,14 +3354,21 @@ 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_eframe(|_| a);
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,
);
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 before the next pass (`raw_input_hook`).
// The chord fires its command in that pass; the app runs it when the next pass begins (`driver_logic`).
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 };
@@ -3325,7 +3381,14 @@ 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_eframe(|_| app());
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(),
);
for _ in 0..6 {
h.step();
}
@@ -3369,7 +3432,14 @@ 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_eframe(|_| app());
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(),
);
for _ in 0..6 {
h.step();
}
@@ -3508,7 +3578,14 @@ 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_eframe(|_| a);
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,
);
for _ in 0..6 {
h.step();
}
@@ -3770,7 +3847,14 @@ 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_eframe(|_| app());
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(),
);
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 before the next pass (`raw_input_hook`).
// The chord fires the command in that pass; the app runs it when the next pass begins (`driver_logic`).
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");
+24 -3
View File
@@ -69,7 +69,14 @@ 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_eframe(|_| a);
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,
);
for _ in 0..4 {
h.step();
}
@@ -298,7 +305,14 @@ 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_eframe(|_| a);
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,
);
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");
@@ -422,7 +436,14 @@ 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_eframe(|_| app());
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(),
);
for _ in 0..6 {
h.step();
}
+19 -28
View File
@@ -1,8 +1,5 @@
//! 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};
@@ -23,13 +20,16 @@ pub(crate) fn big_table_doc(rows: usize, cols: usize) -> Document {
d
}
/// 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)
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,
)
}
/// Queues a pointer move to (720, 500) and a vertical point-unit wheel event that scrolls the view `dy` points.
@@ -50,43 +50,34 @@ 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. 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.
/// per layout and only when it is on screen, and keeps textures only near the view.
#[test]
fn scrolling_a_big_table_fingerprints_only_pages_coming_into_view() {
let (mut h, jobs) = harness(big_table_doc(400, 8));
let mut h = harness(big_table_doc(600, 8));
h.run_steps(4);
let layout = h.state_mut().session.layout();
let pages = layout.pages.len();
// The scroll below crosses about 17 pages; the table runs well past that on every platform's fonts (29 pages on
// macOS, more elsewhere), so the view never reaches its end.
assert!(pages > 25, "the table runs over many pages ({pages})");
assert!(pages > 30, "the table runs over many pages ({pages})");
let first = h.state().canvas.page_keys.hashed;
assert!(first > 0 && first < 6, "only the pages on screen are fingerprinted, not all {pages}: {first}");
// Idle frames do no per-page work.
h.run_steps(3);
assert_eq!(h.state().canvas.page_keys.hashed, first, "idle frames fingerprint nothing");
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.
// Scroll a long way down: each newly shown page is fingerprinted once.
let mut max_textures = 0;
for _ in 0..9 {
wheel(&mut h, -2000.0);
for _ in 0..60 {
wheel(&mut h, -400.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 > 16_000.0, "scrolled through many pages: {offset}");
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;
// 9 steps of 2'000 pt cross about 18'000 / 1'056 ≈ 17 pages (at 100%, 1.33 px a point).
assert!(hashed < pages && hashed <= first + 26, "pages fingerprinted: {hashed} of {pages}");
// 60 steps of 400 pt cross about 24'000 / 1'056 ≈ 23 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");
}
+16 -2
View File
@@ -85,7 +85,14 @@ 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_eframe(|_| a);
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,
);
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();
@@ -151,7 +158,14 @@ 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_eframe(|_| a);
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,
);
h.run_steps(4);
h.get_by_role_and_label(egui::accesskit::Role::Button, "Provider").click();
h.run_steps(3);