Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Tests: Graph Data's full-size sheet test counts the cells it draws instead of timing them

dotCooCoocb631ae6351a
diff --git a/crates/ui-egui/src/dialogs/graph_data.rs b/crates/ui-egui/src/dialogs/graph_data.rs
index fa9f5e65e..33227897c 100644
--- a/crates/ui-egui/src/dialogs/graph_data.rs
+++ b/crates/ui-egui/src/dialogs/graph_data.rs
@@ -593,21 +593,26 @@ mod tests {
assert_eq!(sel(app.ui.dialog.as_ref().unwrap()), (0, 1), "Up");
}
- #[test]
- fn a_full_size_sheet_draws_only_what_is_in_view() {
- let rows: Vec<Vec<f64>> = (0..MAX_GRAPH_CATEGORIES).map(|i| vec![i as f64; 256]).collect();
+ /// How many buttons (the sheet's cells and the window's own) Graph Data draws in the second of two
+ /// frames in a 1280 × 900 window, for a graph of `categories` rows of `series` values.
+ fn buttons_drawn(categories: usize, series: usize) -> usize {
+ let rows: Vec<Vec<f64>> = (0..categories).map(|i| vec![i as f64; series]).collect();
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.run("graph.create", json!({"type": "column", "x": 0, "y": 0, "width": 200, "height": 150, "rows": rows})).unwrap();
open(&mut app).unwrap();
- let ctx = egui::Context::default();
- crate::theme::install_fonts(&ctx);
- let t = std::time::Instant::now();
- for _ in 0..3 {
- let mut out = ctx.run_ui(egui::RawInput::default(), |ui| super::super::show(&mut app, ui.ctx()));
- out.textures_delta.clear();
- }
- assert!(t.elapsed() < std::time::Duration::from_secs(20), "{:?}", t.elapsed());
+ let tree = crate::widgets::accessibility_tests::tree(|ui| super::super::show(&mut app, ui.ctx()));
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(KIND));
+ tree.iter().filter(|n| n.role() == egui::accesskit::Role::Button).count()
+ }
+
+ #[test]
+ fn a_full_size_sheet_draws_only_what_is_in_view() {
+ // 40 categories of 40 values fill 41 × 41 cells of a 42 × 42 sheet, larger than the view both ways: it
+ // draws some cells, but fewer than the data fill.
+ let some = buttons_drawn(40, 40);
+ assert!(some > 20 && some < 41 * 41, "{some} buttons");
+ // A full-size sheet draws the same cells in view, and none more.
+ assert_eq!(buttons_drawn(MAX_GRAPH_CATEGORIES, MAX_GRAPH_SERIES), some);
}
}