mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 21:58:36 +00:00
Tests: the selection-move rebuild count holds the font and plug-in catalogs steady
a_selection_move_rebuilds_the_menus_for_its_press_and_release_only counts the menus' rebuilds in each frame. A font or plug-in that a test running alongside adds, or the installed fonts' scan ending, also rebuilds the menus, and the exact count then failed. The test now holds the fonts and plug-ins steady for the whole run, and runs the move again on a new app, at most 20 times, until the script and proof-setup revisions held still through it. It asserts the same counts.
This commit is contained in:
@@ -104,6 +104,7 @@ vectorcraft-testkit = { workspace = true }
|
||||
vectorcraft-tools = { workspace = true, features = ["testing"] }
|
||||
# A variable font built in code (no font file is committed).
|
||||
vectorcraft-text = { workspace = true, features = ["test-fonts"] }
|
||||
vectorcraft-plugins = { workspace = true, features = ["test-steady"] }
|
||||
wat = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -867,29 +867,52 @@ fn the_move_of_a_releasing_frame_counts_for_the_tool_drag() {
|
||||
|
||||
/// A Selection tool move builds the menus' states again twice, in the frame of its press and in the frame of its
|
||||
/// release, which commits the move. The frame the move begins in and the frames of its previews, which change the
|
||||
/// document's revision, keep them.
|
||||
/// document's revision, keep them. The menus are also built again when a process-wide catalog changes, so the fonts
|
||||
/// and plug-ins are held steady against tests running alongside for the whole run, and the move runs again on a new
|
||||
/// app, at most 20 times, until the other catalogs held still through it.
|
||||
#[test]
|
||||
fn a_selection_move_rebuilds_the_menus_for_its_press_and_release_only() {
|
||||
let (mut app, ctx, xf) = rectangle_tool();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 60, "height": 30})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool("selection");
|
||||
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
|
||||
let (from, to) = (xf.to_screen(Point::new(130.0, 115.0)), xf.to_screen(Point::new(170.0, 135.0)));
|
||||
app_step(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
for _ in 0..2 {
|
||||
app_step(&mut app, &ctx, vec![]);
|
||||
}
|
||||
let none = egui::Modifiers::NONE;
|
||||
let mut steps = vec![vec![primary(from, true, none)]];
|
||||
steps.extend((1..=8).map(|i| vec![egui::Event::PointerMoved(from.lerp(to, i as f32 / 8.0))]));
|
||||
steps.push(vec![primary(to, false, none)]);
|
||||
steps.extend([vec![], vec![], vec![]]);
|
||||
let mut rebuilt = vec![];
|
||||
for events in steps {
|
||||
let before = app.menus.rebuilds;
|
||||
app_step(&mut app, &ctx, events);
|
||||
rebuilt.push(app.menus.rebuilds - before);
|
||||
}
|
||||
let fonts = vectorcraft_text::FontDb::global();
|
||||
let _steady = (vectorcraft_text::test_fonts::steady_fonts(fonts), vectorcraft_plugins::steady::steady_plugins());
|
||||
let catalogs = || {
|
||||
(
|
||||
crate::menus::plugin_revision(),
|
||||
fonts.generation(),
|
||||
fonts.installed_fonts_ready(),
|
||||
crate::scripts_menu::revision(),
|
||||
crate::dialogs::proof_setup::saved_revision(),
|
||||
)
|
||||
};
|
||||
let run = || {
|
||||
let (mut app, ctx, xf) = rectangle_tool();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 60, "height": 30})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool("selection");
|
||||
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
|
||||
let (from, to) = (xf.to_screen(Point::new(130.0, 115.0)), xf.to_screen(Point::new(170.0, 135.0)));
|
||||
app_step(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
for _ in 0..2 {
|
||||
app_step(&mut app, &ctx, vec![]);
|
||||
}
|
||||
let none = egui::Modifiers::NONE;
|
||||
let mut steps = vec![vec![primary(from, true, none)]];
|
||||
steps.extend((1..=8).map(|i| vec![egui::Event::PointerMoved(from.lerp(to, i as f32 / 8.0))]));
|
||||
steps.push(vec![primary(to, false, none)]);
|
||||
steps.extend([vec![], vec![], vec![]]);
|
||||
let mut rebuilt = vec![];
|
||||
for events in steps {
|
||||
let before = app.menus.rebuilds;
|
||||
app_step(&mut app, &ctx, events);
|
||||
rebuilt.push(app.menus.rebuilds - before);
|
||||
}
|
||||
(app, rebuilt)
|
||||
};
|
||||
let (app, rebuilt) = (0..20)
|
||||
.find_map(|_| {
|
||||
let before = catalogs();
|
||||
let out = run();
|
||||
(catalogs() == before).then_some(out)
|
||||
})
|
||||
.unwrap_or_else(|| panic!("tests running alongside kept changing the font and plug-in catalogs"));
|
||||
assert_eq!(drawn_paths(&app), vec![Rect::new(140.0, 120.0, 200.0, 150.0)], "the drag moves the rectangle");
|
||||
assert_eq!(rebuilt, [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], "rebuilds in each frame: press, 8 moves, release, 3 idle");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user