test: make the records smoke test self-contained (improvise-c5v)

It read a .improv fixture, but *.improv is gitignored, so the fixture never
made it into the commit and the test would have failed on a clean checkout.
It now builds the model in-process — CSV, import, save, load — which also
covers more of the path than the fixture did.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V69PGQfMJuGRmtSWpfVAqn
This commit is contained in:
Edward Langley
2026-08-29 12:31:06 -07:00
parent 22964f99be
commit f47decffdd
+24 -7
View File
@@ -1,13 +1,30 @@
//! End-to-end check that a real imported model renders records mode in
//! wide format (improvise-c5v).
//! End-to-end check that a real imported model renders records mode in wide
//! format: CSV → import → save → load → records grid (improvise-c5v).
use improvise::import::wizard::ImportPipeline;
use improvise::persistence;
use improvise::view::{Axis, GridLayout};
/// Import a two-record CSV, round-trip it through `.improv`, and read the
/// records grid off the loaded model.
#[test]
fn imported_model_shows_one_row_per_record_with_measure_columns() {
let path =
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/wide_records.improv");
let mut wb = persistence::load(&path).expect("fixture loads");
let dir = tempfile::tempdir().expect("tempdir");
let csv = dir.path().join("w.csv");
std::fs::write(
&csv,
"region,product,revenue,cost\nEast,Shirts,100,40\nWest,Pants,200,80\n",
)
.expect("write csv");
let records = improvise::import::csv_parser::parse_csv(&csv).expect("csv parses");
let pipeline = ImportPipeline::new(serde_json::Value::Array(records));
let workbook = pipeline.build_model().expect("model builds");
let saved = dir.path().join("w.improv");
persistence::save(&workbook, &saved).expect("saves");
let mut wb = persistence::load(&saved).expect("loads");
let v = wb.active_view_mut();
v.set_axis("_Index", Axis::Row);
v.set_axis("_Dim", Axis::Column);
@@ -23,9 +40,9 @@ fn imported_model_shows_one_row_per_record_with_measure_columns() {
assert_eq!(
cols,
vec!["product", "region", "cost", "revenue", "+"],
"got {cols:?}"
"categories, then one column per measure, then the new-measure column"
);
assert_eq!(layout.row_count(), 2, "two source rows, not four cells");
assert_eq!(layout.row_count(), 2, "two source records, not four cells");
// Row order follows the store; the contract under test is that each
// source record is one row carrying both its measures side by side.