#2641: address review coverage and menu scan cost

This commit is contained in:
TheRenegadeDev
2026-10-26 13:40:03 -05:00
parent a7a708d0f6
commit 1fcaffe7b7
5 changed files with 40 additions and 6 deletions
@@ -33,7 +33,7 @@ fn choices_use_the_same_custom_and_statistical_criteria_as_filtering() {
s.execute("data.filterBy", params).unwrap();
let actual: Vec<_> = filter_values(&s.doc().unwrap().wb, 0, 0).into_iter().map(|(v, _)| v).collect();
assert_eq!(actual, expected, "{criterion}");
// Statistics still come from the whole range even with another column filtered.
// The current column's own criterion must not narrow its alternatives.
s.execute("data.filterBy", json!({"column": "A", "values": ["mid"]})).unwrap();
let actual: Vec<_> = filter_values(&s.doc().unwrap().wb, 0, 0).into_iter().map(|(v, _)| v).collect();
assert_eq!(actual, expected, "{criterion}, with the current column filtered");
@@ -45,6 +45,36 @@ fn choices_use_the_same_custom_and_statistical_criteria_as_filtering() {
}
}
#[test]
fn statistical_thresholds_use_the_original_range_not_other_columns_subset() {
for (criterion, names, expected) in [
(json!({"top": {"count": 2}}), vec!["low", "mid", "upper"], vec!["upper"]),
(json!({"top": {"count": 50, "percent": true}}), vec!["low", "mid", "upper"], vec!["upper"]),
(json!({"top": {"count": 2, "bottom": true}}), vec!["mid", "upper", "high"], vec!["mid"]),
(json!({"top": {"count": 50, "percent": true, "bottom": true}}), vec!["mid", "upper", "high"], vec!["mid"]),
(json!({"aboveAverage": true}), vec!["low", "mid", "upper"], vec![]),
(json!({"aboveAverage": false}), vec!["low", "mid", "upper"], vec!["low", "mid", "upper"]),
] {
let mut s = Session::new();
s.new_workbook();
s.execute(
"range.setValues",
json!({"range": "A1", "values": [
["Name", "Amount", "Job"], ["low", 10, "low"], ["mid", 20, "mid"], ["upper", 30, "upper"], ["high", 100, "high"]
]}),
)
.unwrap();
s.execute("data.filter", json!({"range": "A1:C5"})).unwrap();
s.execute("data.filterBy", json!({"column": "A", "values": names})).unwrap();
let mut params = criterion.clone();
params["column"] = json!("B");
s.execute("data.filterBy", params).unwrap();
// A and B both remain active when enumerating C. Subset statistics produce different jobs.
let actual: Vec<_> = filter_values(&s.doc().unwrap().wb, 0, 2).into_iter().map(|(v, _)| v).collect();
assert_eq!(actual, expected, "{criterion}");
}
}
#[test]
fn choices_match_other_columns_but_keep_the_current_columns_unchecked_values() {
let mut s = Session::new();
@@ -176,7 +206,8 @@ fn choices_are_bounded_at_the_last_sheet_row_and_empty_for_missing_data() {
s.new_workbook();
assert!(filter_values(&s.doc().unwrap().wb, 0, 0).is_empty());
assert!(filter_values(&s.doc().unwrap().wb, 99, 0).is_empty());
s.execute("range.setValues", json!({"range": "B1048574", "values": [["Company", "Job"], ["East", "Last East"], ["West", "Last West"]]})).unwrap();
s.execute("range.setValues", json!({"range": "B1048574", "values": [["Company", "Job"], ["West", "Before last"], ["East", "Last East"]]}))
.unwrap();
s.execute("data.filter", json!({"range": "B1048574:C1048576"})).unwrap();
s.execute("data.filterBy", json!({"column": "B", "values": ["East"]})).unwrap();
assert_eq!(filter_values(&s.doc().unwrap().wb, 0, 2), vec![("Last East".into(), true)]);
+1
View File
@@ -1,6 +1,7 @@
//! The crate's integration tests, one module per file, built as one test binary.
mod autofit_filter_buttons;
mod cascading_filter_values;
mod cf_formula_validate;
mod chart_area_stacked100;
mod chart_workbook_names;
+4 -2
View File
@@ -3326,7 +3326,6 @@ fn filter_menu(app: &mut SheetApp, ui: &mut egui::Ui, geo: &Geo, was_open: bool)
}
}
let wb = app.session.active().map(|d| d.wb.clone()).unwrap_or(wb);
let values = gridcraft_engine::cmd::data::filter_values(&wb, si, col);
let key = egui::Id::unique(("filter_sel", col));
let search_key = egui::Id::unique(("filter_search", col));
let buttons_key = egui::Id::unique(("filter_buttons", col));
@@ -3352,7 +3351,10 @@ fn filter_menu(app: &mut SheetApp, ui: &mut egui::Ui, geo: &Geo, was_open: bool)
}
ui.separator();
ui.label(egui::RichText::new("Filter").strong());
let mut checks: Vec<(String, bool)> = ui.ctx().data_mut(|d| d.get_temp::<Vec<(String, bool)>>(key)).unwrap_or(values.clone());
let mut checks: Vec<(String, bool)> = ui
.ctx()
.data_mut(|d| d.get_temp::<Vec<(String, bool)>>(key))
.unwrap_or_else(|| gridcraft_engine::cmd::data::filter_values(&wb, si, col));
// A search narrows the list; Select All and Apply then only cover the matches.
let mut search: String = ui.ctx().data_mut(|d| d.get_temp(search_key)).unwrap_or_default();
let field = ui.add(egui::TextEdit::singleline(&mut search).hint_text("Search").desired_width(f32::INFINITY));
@@ -1,5 +1,4 @@
#[path = "common/mod.rs"]
mod common;
use crate::common;
use egui::{Event, Key, Modifiers};
use egui_kittest::kittest::Queryable;
+1
View File
@@ -11,6 +11,7 @@ mod advanced_filter;
mod argument_names;
mod autosave_persist;
mod borders;
mod cascading_filter_values;
mod cell_editor_caret;
mod cell_pictures;
mod cf_rule_pick;