From cc6504e9b609f64f8d1a4432c252c57eedaa1b51 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Sun, 5 Apr 2026 14:05:33 -0700 Subject: [PATCH] test(import): add tests for label field import behavior Add two new tests for label field functionality: - label_fields_imported_as_label_category_coords: Verifies that high-cardinality fields (>20 distinct values) are classified as Label kind, default to accepted, and are stored as category coords - label_category_defaults_to_none_axis: Verifies that label categories default to Axis::None in the active view Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M) --- src/import/wizard.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/import/wizard.rs b/src/import/wizard.rs index 47bd906..24e8f3d 100644 --- a/src/import/wizard.rs +++ b/src/import/wizard.rs @@ -631,6 +631,46 @@ mod tests { assert!(model.category("Measure").is_some()); } + #[test] + fn label_fields_imported_as_label_category_coords() { + use crate::model::category::CategoryKind; + // 25 unique descriptions → classified as Label (> CATEGORY_THRESHOLD=20) + let records: Vec = (0..25) + .map(|i| json!({"region": "East", "desc": format!("row-{i}"), "revenue": i as f64})) + .collect(); + let raw = serde_json::Value::Array(records); + let p = ImportPipeline::new(raw); + let desc = p.proposals.iter().find(|p| p.field == "desc").unwrap(); + assert_eq!(desc.kind, FieldKind::Label); + assert!(desc.accepted, "labels should default to accepted"); + + let model = p.build_model().unwrap(); + // Label field exists as a category with Label kind + let cat = model.category("desc").expect("desc category exists"); + assert_eq!(cat.kind, CategoryKind::Label); + // Each record's cell key carries the desc label coord + use crate::model::cell::CellKey; + let k = CellKey::new(vec![ + ("Measure".to_string(), "revenue".to_string()), + ("desc".to_string(), "row-7".to_string()), + ("region".to_string(), "East".to_string()), + ]); + assert_eq!(model.get_cell(&k).and_then(|v| v.as_f64()), Some(7.0)); + } + + #[test] + fn label_category_defaults_to_none_axis() { + use crate::view::Axis; + let records: Vec = (0..25) + .map(|i| json!({"region": "East", "desc": format!("r{i}"), "n": 1.0})) + .collect(); + let raw = serde_json::Value::Array(records); + let p = ImportPipeline::new(raw); + let model = p.build_model().unwrap(); + let v = model.active_view(); + assert_eq!(v.axis_of("desc"), Axis::None); + } + #[test] fn build_model_cells_match_source_data() { let raw = json!([