mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-01 22:19:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d78e534cf7 |
@@ -84,6 +84,14 @@ fn texts(shape: &egui::Shape, out: &mut Vec<String>) {
|
||||
/// Run a frame per entry of `steps` (its events), then a few quiet ones, and return every text
|
||||
/// drawn in the last.
|
||||
fn frames(ctx: &egui::Context, app: &mut WordApp, steps: Vec<Vec<egui::Event>>) -> Vec<String> {
|
||||
let mut drawn = Vec::new();
|
||||
for shape in draw_frames(ctx, app, steps) {
|
||||
texts(&shape.shape, &mut drawn);
|
||||
}
|
||||
drawn
|
||||
}
|
||||
|
||||
fn draw_frames(ctx: &egui::Context, app: &mut WordApp, steps: Vec<Vec<egui::Event>>) -> Vec<egui::epaint::ClippedShape> {
|
||||
// Wide enough that no ribbon tab overflows behind its scroll arrows.
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(2560.0, 900.0));
|
||||
let mut drawn = Vec::new();
|
||||
@@ -101,11 +109,9 @@ fn frames(ctx: &egui::Context, app: &mut WordApp, steps: Vec<Vec<egui::Event>>)
|
||||
app.ui(ui);
|
||||
});
|
||||
note_global_names();
|
||||
drawn.clear();
|
||||
for s in &out.shapes {
|
||||
texts(&s.shape, &mut drawn);
|
||||
}
|
||||
// The audit reads shapes without rendering textures. Discard these deltas deliberately.
|
||||
out.textures_delta.clear();
|
||||
drawn = out.shapes;
|
||||
}
|
||||
drawn
|
||||
}
|
||||
@@ -375,11 +381,27 @@ fn runtime_data_is_exempt_and_wording_is_not() {
|
||||
assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 1, "the check went through the stub, not GitHub");
|
||||
}
|
||||
|
||||
/// Locate the pointer target from the visible face, not from a fixed pixel or command dispatch.
|
||||
fn painted_control(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
|
||||
fn find(shape: &egui::Shape, clip: egui::Rect, label: &str) -> Option<egui::Pos2> {
|
||||
match shape {
|
||||
egui::Shape::Text(text) if text.galley.text() == label => {
|
||||
let bounds = text.visual_bounding_rect().intersect(clip);
|
||||
bounds.is_positive().then(|| bounds.center())
|
||||
}
|
||||
egui::Shape::Vec(children) => children.iter().find_map(|s| find(s, clip, label)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
shapes.iter().find_map(|s| find(&s.shape, s.clip_rect, label)).unwrap_or_else(|| panic!("ribbon face {label:?} is not painted"))
|
||||
}
|
||||
|
||||
/// Fails on interface text drawn without going through the catalog, listed per UI state, and
|
||||
/// prints the missing-translation report (`report_catalog_gaps`). `cargo xtask i18n-report` runs it
|
||||
/// with `--nocapture`; `cargo xtask test` and `ci` run it that way instead of in the main test run.
|
||||
/// It can also run with the other tests: input is synthetic and timed by `TIME`, Read Aloud never
|
||||
/// starts a speech thread, and process-wide names other tests change are gathered every frame.
|
||||
/// The daily audit also hovers and clicks every ribbon control.
|
||||
#[test]
|
||||
fn untranslated_interface_text() {
|
||||
let ctx = crate::test_harness::context();
|
||||
@@ -496,8 +518,39 @@ fn untranslated_interface_text() {
|
||||
let _ = app.run("ui.tab", json!({"tab": "Equation"}));
|
||||
let drawn = frame(&ctx, &mut app);
|
||||
record(&app, "tab Equation", drawn);
|
||||
// Every ribbon control on every tab, and whatever menu or dialog it opens. A fresh app per
|
||||
// tab keeps one tab's commands from changing the next.
|
||||
// A composed ribbon face, a separately translated tooltip, and menu rows reached by a real click.
|
||||
// Start clean so a preceding contextual tab or dialog can't cover the pointer target.
|
||||
let ctx = crate::test_harness::context();
|
||||
super::embedded_host(&ctx);
|
||||
let mut app = pseudo_app(&ctx);
|
||||
app.run("ui.tab", json!({"tab": "References"})).unwrap();
|
||||
let title = crate::i18n::fmt(super::tr(super::Lang::PSEUDO, "Style: {style}"), &[("style", &app.session.bib_style)]);
|
||||
let shapes = draw_frames(&ctx, &mut app, Vec::new());
|
||||
let at = painted_control(&shapes, &title);
|
||||
let mut hover = vec![vec![egui::Event::PointerMoved(at)]];
|
||||
hover.resize_with(6, Vec::new);
|
||||
let hovered = frames(&ctx, &mut app, hover);
|
||||
assert!(hovered.iter().any(|t| t == "⟦Citation Style⟧"), "Citation Style tooltip was not translated");
|
||||
record(&app, "References › Citation Style hover", hovered);
|
||||
let drawn = frames(&ctx, &mut app, click(at, egui::PointerButton::Primary));
|
||||
assert!(drawn.iter().any(|t| t == "⟦Harvard (Anglia)⟧"), "click did not open the translated Citation Style menu");
|
||||
record(&app, "References › Citation Style click", drawn);
|
||||
if crate::test_harness::full_locale_audit() {
|
||||
audit_ribbon_controls(&tabs, &mut record);
|
||||
}
|
||||
super::apply_language(super::Lang::EN);
|
||||
let mut report = String::new();
|
||||
for (text, states) in &found {
|
||||
let mut states = states.clone();
|
||||
states.sort();
|
||||
states.dedup();
|
||||
report.push_str(&format!("{:?} [{}]\n", unmarked(text), states.join(", ")));
|
||||
}
|
||||
report_catalog_gaps(super::I18N.looked_up());
|
||||
assert!(found.is_empty(), "{} interface texts skip translation (wrap them in tl!):\n{report}", found.len());
|
||||
}
|
||||
|
||||
fn audit_ribbon_controls(tabs: &[&str], mut record: impl FnMut(&WordApp, &str, Vec<String>)) {
|
||||
// A fresh app per control, set up the same way, so no click changes what the next one hits
|
||||
// (Escape, for one, leaves an equation and takes the Equation tab with it).
|
||||
let contextual = ["Table Design", "Table Layout", "Equation", "Chart Design", "SmartArt Design"];
|
||||
@@ -527,16 +580,6 @@ fn untranslated_interface_text() {
|
||||
record(&app, &format!("{tab} › click"), drawn);
|
||||
}
|
||||
}
|
||||
super::apply_language(super::Lang::EN);
|
||||
let mut report = String::new();
|
||||
for (text, states) in &found {
|
||||
let mut states = states.clone();
|
||||
states.sort();
|
||||
states.dedup();
|
||||
report.push_str(&format!("{:?} [{}]\n", unmarked(text), states.join(", ")));
|
||||
}
|
||||
report_catalog_gaps(super::I18N.looked_up());
|
||||
assert!(found.is_empty(), "{} interface texts skip translation (wrap them in tl!):\n{report}", found.len());
|
||||
}
|
||||
|
||||
/// The missing-translation report (craft-i18n's S3; `cargo xtask i18n-report`, part of `cargo xtask
|
||||
@@ -764,16 +807,15 @@ fn frame_at(ctx: &egui::Context, app: &mut WordApp, width: f32) -> Vec<(String,
|
||||
drawn
|
||||
}
|
||||
|
||||
/// The Arabic interface is mirrored: reading starts at the right. And nothing in it can panic:
|
||||
/// every tab (wide, and narrow enough to scroll), File page, dialog, pane, context menu and
|
||||
/// ribbon control is laid out right to left.
|
||||
/// The Arabic interface is mirrored: reading starts at the right. The daily audit also renders
|
||||
/// every tab at several widths, every File page, dialog and pane, and exercises the context menu
|
||||
/// and ribbon controls right to left.
|
||||
#[test]
|
||||
fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
// Arabic comes from the craft-i18n catalogs: a build without them (English only) has nothing to mirror.
|
||||
let Some(ar) = super::Lang::from_code("ar") else {
|
||||
eprintln!("skipped: built without the craft-i18n Arabic catalog (set CRAFT_I18N_DIR to a checkout)");
|
||||
let Some(ar) = crate::test_harness::locale_for_audit("ar") else {
|
||||
return;
|
||||
};
|
||||
let full = crate::test_harness::full_locale_audit();
|
||||
let start = |ctx: &egui::Context| {
|
||||
let mut app = fresh_app(ctx);
|
||||
app.ui.language = "ar".into();
|
||||
@@ -791,6 +833,7 @@ fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
drawn.iter().find(|(t, _)| t == label).map(|(_, x)| *x).unwrap_or_else(|| panic!("{english} is not drawn"))
|
||||
};
|
||||
// Tabs run from the right: File, Home, Insert … and the Share button is at the far left.
|
||||
assert_ne!(super::tr(ar, "Home"), "Home", "exercise a translated tab, not just English fallback");
|
||||
let drawn = frame_at(&ctx, &mut app, 1600.0);
|
||||
let (file, home, insert, share) = (x_of(&drawn, "File"), x_of(&drawn, "Home"), x_of(&drawn, "Insert"), x_of(&drawn, "Share"));
|
||||
assert!(file > home && home > insert && insert > 800.0, "tabs: {file} {home} {insert}");
|
||||
@@ -822,15 +865,20 @@ fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
assert_eq!(app.root_env().direction, craft::i18n::Direction::Ltr);
|
||||
super::apply_language(ar);
|
||||
}
|
||||
// Everything else: no panic at any width.
|
||||
// #910: also exercise Layout's dense Paragraph grid at the narrowest RTL width on PRs.
|
||||
let tabs: Vec<&str> = crate::ribbon::TABS.iter().copied().filter(|t| *t != "File").collect();
|
||||
for tab in &tabs {
|
||||
let _ = app.run("ui.tab", json!({"tab": tab}));
|
||||
for width in [2560.0, 1100.0, 420.0] {
|
||||
frame_at(&ctx, &mut app, width);
|
||||
if full {
|
||||
for tab in &tabs {
|
||||
app.run("ui.tab", json!({"tab": tab})).unwrap();
|
||||
for width in [2560.0, 1100.0, 420.0] {
|
||||
frame_at(&ctx, &mut app, width);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
app.run("ui.tab", json!({"tab": "Layout"})).unwrap();
|
||||
frame_at(&ctx, &mut app, 420.0);
|
||||
}
|
||||
let _ = app.run("ui.tab", json!({"tab": "Home"}));
|
||||
app.run("ui.tab", json!({"tab": "Home"})).unwrap();
|
||||
// Reading Mode's toolbar is mirrored too: its far-side button ("Edit Document") is at the left.
|
||||
let _ = app.run("view.readMode", json!({}));
|
||||
let drawn = frame_at(&ctx, &mut app, 1600.0);
|
||||
@@ -848,10 +896,12 @@ fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
assert!(preview < f32::MAX, "the preview's page indicator is drawn");
|
||||
assert!(preview + 100.0 < settings, "print page at {width}: settings {settings}, preview {preview}");
|
||||
}
|
||||
for page in ["home", "new", "open", "info", "export", "print", "options"] {
|
||||
let _ = app.run("ui.backstage", json!({"value": true, "page": page}));
|
||||
frame(&ctx, &mut app);
|
||||
frame_at(&ctx, &mut app, 500.0);
|
||||
if full {
|
||||
for page in ["home", "new", "open", "info", "export", "print", "options"] {
|
||||
let _ = app.run("ui.backstage", json!({"value": true, "page": page}));
|
||||
frame(&ctx, &mut app);
|
||||
frame_at(&ctx, &mut app, 500.0);
|
||||
}
|
||||
}
|
||||
let _ = app.run("ui.backstage", json!({"value": false}));
|
||||
// A dialog's columns start at the right too. Main's Go To set its list of targets beside its page number box; the
|
||||
@@ -862,6 +912,13 @@ fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
let (targets, buttons) = (x_of(&drawn, "Go to what:"), x_of(&drawn, "Next"));
|
||||
assert!(targets > buttons, "Go To: targets {targets}, buttons {buttons}");
|
||||
crate::dialogs::host::close_all(&mut app, &ctx);
|
||||
if full {
|
||||
audit_arabic_states(&ctx, &mut app, &tabs, start);
|
||||
}
|
||||
super::apply_language(super::Lang::EN);
|
||||
}
|
||||
|
||||
fn audit_arabic_states(ctx: &egui::Context, app: &mut WordApp, tabs: &[&str], start: impl Fn(&egui::Context) -> WordApp) {
|
||||
let dialogs = [
|
||||
"font",
|
||||
"paragraph",
|
||||
@@ -926,28 +983,28 @@ fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
];
|
||||
for name in dialogs {
|
||||
let _ = app.run("ui.dialog", json!({"name": name}));
|
||||
frame(&ctx, &mut app);
|
||||
crate::dialogs::host::close_all(&mut app, &ctx);
|
||||
frame(ctx, app);
|
||||
crate::dialogs::host::close_all(app, ctx);
|
||||
}
|
||||
let panes: Vec<String> =
|
||||
app.session.registry.all().iter().map(|c| c.id.to_string()).filter(|id| id.starts_with("view.") && id.ends_with("Pane")).collect();
|
||||
for pane in &panes {
|
||||
let _ = app.run(pane, json!({"value": true}));
|
||||
frame(&ctx, &mut app);
|
||||
frame_at(&ctx, &mut app, 600.0);
|
||||
frame(ctx, app);
|
||||
frame_at(ctx, app, 600.0);
|
||||
let _ = app.run(pane, json!({"value": false}));
|
||||
}
|
||||
frames(&ctx, &mut app, click(egui::pos2(1280.0, 520.0), egui::PointerButton::Secondary));
|
||||
frames(&ctx, &mut app, escape());
|
||||
frames(ctx, app, click(egui::pos2(1280.0, 520.0), egui::PointerButton::Secondary));
|
||||
frames(ctx, app, escape());
|
||||
let _ = app.run("insert.table", json!({"rows": 2, "cols": 2}));
|
||||
for tab in ["Table Design", "Table Layout"] {
|
||||
let _ = app.run("ui.tab", json!({"tab": tab}));
|
||||
frame(&ctx, &mut app);
|
||||
frame_at(&ctx, &mut app, 600.0);
|
||||
frame(ctx, app);
|
||||
frame_at(ctx, app, 600.0);
|
||||
}
|
||||
let _ = app.run("insert.equation", json!({}));
|
||||
let _ = app.run("ui.tab", json!({"tab": "Equation"}));
|
||||
frame(&ctx, &mut app);
|
||||
frame(ctx, app);
|
||||
// Every ribbon control on every tab, hovered and clicked: its tooltip, menu or dialog.
|
||||
let contextual = ["Table Design", "Table Layout", "Equation"];
|
||||
let open = |tab: &str| {
|
||||
@@ -975,5 +1032,4 @@ fn the_arabic_interface_is_mirrored_and_never_panics() {
|
||||
}
|
||||
}
|
||||
}
|
||||
super::apply_language(super::Lang::EN);
|
||||
}
|
||||
|
||||
@@ -408,11 +408,13 @@ fn smart_art_design_layouts_are_one_strip_and_size_is_labelled() {
|
||||
}
|
||||
}
|
||||
|
||||
/// No group's content runs into its label: View › Show stacked four check boxes in a column
|
||||
/// made for three, so "Hide White Space" was drawn under "Show". Every tab, every language: each
|
||||
/// control lies inside its group's access node.
|
||||
/// No group's content runs into its label. Keep the #910 View, Developer and Layout regressions,
|
||||
/// including long German and RTL Arabic labels; the daily run checks every tab in every locale.
|
||||
#[test]
|
||||
fn ribbon_groups_fit_above_their_labels() {
|
||||
use crate::i18n::{Lang, tr};
|
||||
use egui::accesskit::Role;
|
||||
|
||||
fn rects(node: &egui_kittest::Node<'_>, out: &mut Vec<egui::Rect>) {
|
||||
for child in node.children() {
|
||||
// The framework's parts (a split button's arrow, a field's adornments) can be nodes with no
|
||||
@@ -438,16 +440,53 @@ fn ribbon_groups_fit_above_their_labels() {
|
||||
// Menu and popup bodies the framework measures in a hidden layer below the window carry access nodes under the
|
||||
// app's groups; they are never drawn, so they cannot run into a label. Only what lies on screen is checked.
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(2560.0, 900.0));
|
||||
for lang in crate::i18n::Lang::all() {
|
||||
let full = crate::test_harness::full_locale_audit();
|
||||
let german = crate::test_harness::locale_for_audit("de");
|
||||
let arabic = crate::test_harness::locale_for_audit("ar");
|
||||
let all_tabs = super::TABS.iter().copied().filter(|&t| t != "File").collect::<Vec<_>>();
|
||||
for lang in Lang::all() {
|
||||
let smoke: &[&str] = if lang == Lang::EN {
|
||||
&["View", "Developer", "Layout"]
|
||||
} else if Some(lang) == german {
|
||||
&["View", "Layout"]
|
||||
} else if Some(lang) == arabic {
|
||||
&["View", "Home"]
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
let tabs = if full || lang == Lang::EN { all_tabs.as_slice() } else { smoke };
|
||||
if tabs.is_empty() {
|
||||
continue;
|
||||
}
|
||||
h.state_mut().run("ui.language", json!({"value": lang.code()})).unwrap();
|
||||
for tab in super::TABS.iter().filter(|t| **t != "File") {
|
||||
for &tab in tabs {
|
||||
h.state_mut().run("ui.tab", json!({"tab": tab})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
if smoke.contains(&tab) {
|
||||
let group = match tab {
|
||||
"View" => "Show",
|
||||
"Developer" => "Controls",
|
||||
"Layout" => "Paragraph",
|
||||
"Home" => "Clipboard",
|
||||
_ => unreachable!("every smoke tab has a group witness"),
|
||||
};
|
||||
let bounds = h.get_by_role_and_label(Role::Group, tr(lang, group)).rect();
|
||||
assert!(bounds.is_positive() && screen.intersects(bounds), "{lang:?} {tab}: {group} must be on screen");
|
||||
if tab == "View" {
|
||||
let label = tr(lang, "Hide White Space");
|
||||
if lang != Lang::EN {
|
||||
assert_ne!(label, "Hide White Space", "{lang:?}: exercise translated checkbox text");
|
||||
}
|
||||
let hide = h.get_by_role_and_label(Role::CheckBox, label).rect();
|
||||
let last = h.get_by_role_and_label(Role::CheckBox, tr(lang, "Navigation Pane")).rect();
|
||||
assert!(hide.bottom() <= last.bottom() + 1.0, "{lang:?}: Hide White Space runs below the third row: {hide:?}, {last:?}");
|
||||
}
|
||||
}
|
||||
// The ribbon's groups: every labelled container is a group node (the document, its page text, the task
|
||||
// pane area), and those below the ribbon are not what this checks.
|
||||
let ribbon_bottom = h.state().canvas.canvas_rect().map_or(f32::INFINITY, |c| c.top());
|
||||
let groups = h
|
||||
.query_all(By::new().role(egui::accesskit::Role::Group))
|
||||
.query_all(By::new().role(Role::Group))
|
||||
.filter(|g| g.accesskit_node().raw_bounds().is_some() && g.rect().bottom() <= ribbon_bottom + 1.0);
|
||||
for group in groups {
|
||||
let frame = group.rect();
|
||||
|
||||
@@ -20,6 +20,34 @@ use egui_kittest::HarnessBuilder;
|
||||
|
||||
use crate::i18n::Lang;
|
||||
|
||||
/// The daily FreeBSD workspace test run opts in, as can local runs of these same tests.
|
||||
pub(crate) fn full_locale_audit() -> bool {
|
||||
match std::env::var("WORDCRAFT_FULL_LOCALE_AUDIT").as_deref() {
|
||||
Ok("1") => true,
|
||||
Ok("") | Err(std::env::VarError::NotPresent) => false,
|
||||
value => panic!("WORDCRAFT_FULL_LOCALE_AUDIT must be unset, empty or 1, got {value:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// These layout tests need real catalogs in CI. An explicitly English-only local build can
|
||||
/// still run other tests; a partial catalog set or a provisioned lane must never skip a case.
|
||||
pub(crate) fn locale_for_audit(code: &str) -> Option<Lang> {
|
||||
let required = match std::env::var("CRAFT_I18N_REQUIRED").as_deref() {
|
||||
Ok("1") => true,
|
||||
Ok("") | Err(std::env::VarError::NotPresent) => false,
|
||||
value => panic!("CRAFT_I18N_REQUIRED must be unset, empty or 1, got {value:?}"),
|
||||
};
|
||||
if let Some(lang) = Lang::from_code(code) {
|
||||
return Some(lang);
|
||||
}
|
||||
assert!(
|
||||
!required && option_env!("CRAFT_I18N_REQUIRED") != Some("1") && !full_locale_audit() && crate::i18n::CRAFT_I18N.is_empty(),
|
||||
"missing embedded {code} catalog: set CRAFT_I18N_DIR to the checkout pinned in craft-i18n.rev"
|
||||
);
|
||||
eprintln!("skipped {code} layout: this local build is English only (set CRAFT_I18N_DIR)");
|
||||
None
|
||||
}
|
||||
|
||||
/// The install spec the app's tests run on: the framework's test spec (the running build's shell, no OS windows or
|
||||
/// services) without the gallery stories' command sets. `craft::ui::testing::install_spec` loads those sets
|
||||
/// (`InstallSpec::stories`), and their default chords then hold app chords in every test window: the palette story's
|
||||
|
||||
@@ -114,9 +114,14 @@ region's language is Spanish (`es-UY` on a Uruguayan system, `es-MX` on a Mexica
|
||||
Spain's `es-ES` (#3360).
|
||||
|
||||
**Interface audit (runs in CI).** `cargo xtask i18n-report` runs `untranslated_interface_text`,
|
||||
which lays the app out in a pseudo-language (every tab, File page, dialog, pane, the right-click
|
||||
menu, and a hover and a click on every ribbon control) and fails on visible text that skipped the
|
||||
catalog. It then prints the missing-translation report described above, which never fails. Proper names (citation styles such as APA or
|
||||
which lays the app out in a pseudo-language (tabs, File pages, dialogs, panes, the right-click
|
||||
menu, and a real hover and click on the Citation Style ribbon menu) and fails on visible text that
|
||||
skipped the catalog. It then prints the missing-translation report described above, which never fails.
|
||||
PR checks also retain the Arabic placement checks and the ribbon overlap cases in English, German and
|
||||
Arabic. The daily FreeBSD x86_64 workspace test run sets `WORDCRAFT_FULL_LOCALE_AUDIT=1` to also
|
||||
crawl every ribbon control in the original audit, run the full Arabic width/state sweep and check every
|
||||
offered locale on every ordinary ribbon tab. Set that same variable with the pinned catalogs to run
|
||||
the full sweep locally. Proper names (citation styles such as APA or
|
||||
GOST, LaTeX, Unicode) and `bad parameters:` errors, which name a command's JSON parameters for
|
||||
scripts and MCP, stay English. Size labels (Envelopes, Labels, Layout › Size) are translated
|
||||
patterns (`{name} {height} × {width} in`) with the region's decimal separator; paper names
|
||||
|
||||
Reference in New Issue
Block a user