diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 8930142be6..88c2e04540 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -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()); diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index 4a8158364a..ed4147744e 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -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();