Tests: menu and Quick Actions rebuild counts run in a process of their own

The menus' key (`state_key`, crates/ui-egui/src/menus/model.rs) holds the
installed plug-ins' revision and the fonts' generation. Both are the whole
process's. In a parallel `cargo test` run, a plug-in that another test
installs moves the revision, the menus are rebuilt, and the new catalog
makes the window build a new keymap, whose address is also in the key, so
the next pass rebuilds them again. `a_key_press_rebuilds_the_menus_once`
then counted those rebuilds on its idle frames ("idle frames keep the
menus", left 4 to 7, right 3 to 5) in 6 of 6 runs of
`cargo test -p vectorcraft-ui-egui --lib -- addons menus i18n`, and
`quick_actions_are_listed_again_only_after_a_change`, whose key holds the
menus' key, failed in the same way in 2 of 2 runs.

In the app these values change only when a plug-in is installed or removed
or the fonts change, and the menus list both, so the rebuild is kept.

- Both tests run through `testing::in_own_process`, as the tests that load
  color profiles do, and wait for the installed fonts' scan, whose end
  moves the fonts' generation, before their first frames.
- `a_new_font_rebuilds_the_menus` adds a font and checks that the menus are
  rebuilt with no input, that Type › Font lists it, and that idle frames
  after that keep the menus.
This commit is contained in:
dotCooCoo committed 2026-11-29 19:37:36 -08:00
1 parent cdc14eb007
commit 03dd80a887
2 files changed
+47 -4

No files matched your search

+39 -3
View File
@@ -164,15 +164,29 @@ fn snapping_menu_clicks_toggle_view_state_and_painted_checkmarks() {
assert_eq!(menu.toggled("Pixel Snapping Options…"), None);
}
/// A key press builds the menus' states again once: the frames after it, with no press, keep them.
#[test]
fn a_key_press_rebuilds_the_menus_once() {
/// An app with a new document whose installed fonts are cataloged, after the frames that build its first menus and the
/// window's keymap. It runs in a process of its own ([`crate::testing::in_own_process`]): the menus' key holds the
/// installed plug-ins' revision and the fonts' generation, which are the whole process's, so a plug-in that another test
/// installs, or a font it adds, rebuilds this app's menus. `None` in the parent process.
fn settled_app(test: &str) -> Option<(VectorcraftApp, egui::Context)> {
if !crate::testing::in_own_process(test) {
return None;
}
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
// The scan of the installed fonts, which the app starts, changes the fonts' generation when it ends: wait for it.
vectorcraft_text::FontDb::global().family_list();
app.run("file.new", json!({})).unwrap();
let ctx = crate::testing::ui_context();
for _ in 0..3 {
app_frame(&mut app, &ctx, vec![]);
}
Some((app, ctx))
}
/// A key press builds the menus' states again once: the frames after it, with no press, keep them.
#[test]
fn a_key_press_rebuilds_the_menus_once() {
let Some((mut app, ctx)) = settled_app("menus::tests::a_key_press_rebuilds_the_menus_once") else { return };
let before = app.menus.rebuilds;
for _ in 0..3 {
app_frame(&mut app, &ctx, vec![]);
@@ -187,6 +201,28 @@ fn a_key_press_rebuilds_the_menus_once() {
assert_eq!(app.menus.rebuilds, before + 1);
}
/// A font added to the fonts the whole process shares builds the menus again with no input, Type › Font then lists it,
/// and the idle frames after that keep the menus.
#[test]
fn a_new_font_rebuilds_the_menus() {
const FAMILY: &str = "Menurebuild Sans";
let Some((mut app, ctx)) = settled_app("menus::tests::a_new_font_rebuilds_the_menus") else { return };
let lists =
|app: &VectorcraftApp| app.menus.bar.items().into_iter().any(|it| it.command.id == "text.setStyle" && it.command.params["font"] == FAMILY);
assert!(!lists(&app));
let font = vectorcraft_text::test_fonts::named_copy(false, (FAMILY, "Regular", "Version 1.000", "MenurebuildSans-Regular"));
let before = app.menus.rebuilds;
assert_eq!(vectorcraft_text::FontDb::global().add_font(font.expect("the test font builds")), 1);
app_frame(&mut app, &ctx, vec![]);
assert!(app.menus.rebuilds > before, "the new font rebuilds the menus");
assert!(lists(&app), "Type › Font lists {FAMILY}");
let after = app.menus.rebuilds;
for _ in 0..3 {
app_frame(&mut app, &ctx, vec![]);
}
assert_eq!(app.menus.rebuilds, after, "idle frames keep the menus");
}
#[test]
fn help_f1_opens_discover_without_a_document() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
@@ -1084,10 +1084,17 @@ fn quick_actions_follow_the_selection() {
}
}
/// The panel lists the Quick Actions once per change of what they depend on, not in every frame.
/// The panel lists the Quick Actions once per change of what they depend on, not in every frame. It runs in a process
/// of its own ([`crate::testing::in_own_process`]): what they depend on holds the menus' key, with the installed
/// plug-ins' revision and the fonts' generation, which are the whole process's.
#[test]
fn quick_actions_are_listed_again_only_after_a_change() {
if !crate::testing::in_own_process("panels::properties::tests::quick_actions_are_listed_again_only_after_a_change") {
return;
}
let mut app = new_app();
// The scan of the installed fonts, which the app starts, changes the fonts' generation when it ends: wait for it.
vectorcraft_text::FontDb::global().family_list();
rect(&mut app, 10.0, 10.0, 40.0, 40.0);
rect(&mut app, 80.0, 10.0, 40.0, 40.0);
let ctx = crate::testing::ui_context();