diff --git a/crates/improvise-command/src/ui/app.rs b/crates/improvise-command/src/ui/app.rs index fa398792..60fd36f1 100644 --- a/crates/improvise-command/src/ui/app.rs +++ b/crates/improvise-command/src/ui/app.rs @@ -5617,6 +5617,47 @@ mod non_item_key_tests { assert_eq!(app.view_state.status_msg, refusal("Mars")); } + #[test] + fn a_refused_wire_write_names_the_displays_it_shows() { + const REGION: &str = "Sales territory of the whole company"; + const PROFIT: &str = "Operating profit after all costs"; + let mut app = paged_app("East"); + let stray = CellKey::new(vec![ + ("Month".into(), "Jan".into()), + ("Region".into(), "Mars".into()), + ("_Measure".into(), "Revenue".into()), + ]); + let model = &mut app.model_state.workbook.model; + model.set_cell(stray.clone(), CellValue::Number(2.0)); + model.category_mut("Region").unwrap().set_display(REGION); + model.add_formula( + crate::formula::parse_formula("Profit = Revenue - 1", "_Measure").unwrap(), + ); + let measure = model.category_mut("_Measure").unwrap(); + measure.add_item("Profit"); + measure.set_item_display("Profit", PROFIT); + let refused = |key: &CellKey, measure: &str| { + let cell = RecordCell { + record: RecordHash::of(key), + measure: Some(measure.into()), + }; + app.unwritable(app.view_name(), &cell) + }; + let why = refused(&stray, "Revenue").expect("a non-item is refused"); + assert!(why.contains(REGION), "{why}"); + assert!( + why.starts_with("Mars "), + "the stray coordinate is a key: {why}" + ); + let profit = CellKey::new(vec![ + ("Month".into(), "Jan".into()), + ("Region".into(), "East".into()), + ("_Measure".into(), "Profit".into()), + ]); + let why = refused(&profit, "Profit").expect("a formula's result is refused"); + assert!(why.starts_with(PROFIT), "{why}"); + } + #[test] fn a_non_item_refusal_names_the_categorys_display() { let mut app = paged_app("Mars"); @@ -5631,6 +5672,18 @@ mod non_item_key_tests { app.view_state.status_msg, improvise_protocol::non_item_refusal("Sales territory of the whole company", "Mars"), ); + app.view_state.yanked = Some(CellValue::Number(7.0)); + press(&mut app, "p"); + assert!( + app.view_state + .status_msg + .ends_with(&improvise_protocol::non_item_refusal( + "Sales territory of the whole company", + "Mars" + )), + "{}", + app.view_state.status_msg + ); } /// improvise-yc9r: `p` on a non-item cell writes no orphan. Evidence file.