From 00499fc2bf84bba1b90bc20d6c85c412fd771e87 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Tue, 7 Apr 2026 09:16:25 -0700 Subject: [PATCH] test(cmd): update tests for layout refactor Updated unit tests in src/command/cmd.rs to use the new GridLayout-based CmdContext and layout accessors. Tests now construct CmdContext with a layout argument and verify behavior of navigation and selection commands under the refactored layout logic. No functional changes to command logic; only test updates. Co-Authored-By: fiddlerwoaroof/git-smart-commit (bartowski/nvidia_Nemotron-Cascade-2-30B-A3B-GGUF) --- src/command/cmd.rs | 72 +++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/command/cmd.rs b/src/command/cmd.rs index a2b6838..fff927f 100644 --- a/src/command/cmd.rs +++ b/src/command/cmd.rs @@ -2962,14 +2962,15 @@ mod tests { view_panel_cursor: 0, tile_cat_idx: 0, buffers: &EMPTY_BUFFERS, - none_cats: layout.none_cats.clone(), - view_back_stack: Vec::new(), - view_forward_stack: Vec::new(), - records_col: None, - records_value: None, - cell_key: layout.cell_key(sr, sc), - row_count: layout.row_count(), - col_count: layout.col_count(), + view_back_stack: &[], + view_forward_stack: &[], + display_value: { + let key = layout.cell_key(sr, sc); + key.as_ref() + .and_then(|k| model.get_cell(k).cloned()) + .map(|v| v.to_string()) + .unwrap_or_default() + }, visible_rows: 20, visible_cols: 8, expanded_cats: &EMPTY_EXPANDED, @@ -2991,7 +2992,8 @@ mod tests { #[test] fn move_selection_down_produces_set_selected() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = MoveSelection { dr: 1, dc: 0, @@ -3005,7 +3007,8 @@ mod tests { #[test] fn move_selection_clamps_to_bounds() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); // Try to move way past the end let cmd = MoveSelection { dr: 100, @@ -3021,7 +3024,8 @@ mod tests { let m = two_cat_model(); let mut bufs = HashMap::new(); bufs.insert("command".to_string(), "q".to_string()); - let mut ctx = make_ctx(&m); + let layout = make_layout(&m); + let mut ctx = make_ctx(&m, &layout); ctx.dirty = true; ctx.buffers = &bufs; let cmd = ExecuteCommand; @@ -3035,7 +3039,8 @@ mod tests { let m = two_cat_model(); let mut bufs = HashMap::new(); bufs.insert("command".to_string(), "q".to_string()); - let mut ctx = make_ctx(&m); + let layout = make_layout(&m); + let mut ctx = make_ctx(&m, &layout); ctx.buffers = &bufs; let cmd = ExecuteCommand; let effects = cmd.execute(&ctx); @@ -3054,9 +3059,10 @@ mod tests { ("Month".to_string(), "Jan".to_string()), ]); m.set_cell(key, CellValue::Number(42.0)); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = ClearCellCommand { - key: ctx.cell_key.clone().unwrap(), + key: ctx.cell_key().clone().unwrap(), }; let effects = cmd.execute(&ctx); assert_eq!(effects.len(), 2); // ClearCell + MarkDirty @@ -3070,9 +3076,10 @@ mod tests { ("Month".to_string(), "Jan".to_string()), ]); m.set_cell(key, CellValue::Number(99.0)); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = YankCell { - key: ctx.cell_key.clone().unwrap(), + key: ctx.cell_key().clone().unwrap(), }; let effects = cmd.execute(&ctx); assert_eq!(effects.len(), 2); // SetYanked + SetStatus @@ -3081,7 +3088,8 @@ mod tests { #[test] fn toggle_panel_open_and_focus() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = TogglePanelAndFocus { panel: effect::Panel::Formula, open: true, @@ -3099,7 +3107,8 @@ mod tests { #[test] fn toggle_panel_close_and_unfocus() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = TogglePanelAndFocus { panel: effect::Panel::Formula, open: false, @@ -3112,7 +3121,8 @@ mod tests { #[test] fn enter_advance_moves_down() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = EnterAdvance { cursor: CursorState::from_ctx(&ctx), }; @@ -3128,7 +3138,8 @@ mod tests { #[test] fn search_navigate_with_empty_query_returns_nothing() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = SearchNavigate(true); let effects = cmd.execute(&ctx); assert!(effects.is_empty()); @@ -3137,7 +3148,8 @@ mod tests { #[test] fn enter_edit_mode_produces_editing_mode() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = EnterEditMode { initial_value: String::new(), }; @@ -3150,7 +3162,8 @@ mod tests { #[test] fn enter_tile_select_with_categories() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = EnterTileSelect; let effects = cmd.execute(&ctx); assert_eq!(effects.len(), 2); // SetTileCatIdx + ChangeMode @@ -3166,7 +3179,8 @@ mod tests { // Models always have virtual categories (_Index, _Dim), so tile // select always has something to operate on. let m = Model::new("Empty"); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = EnterTileSelect; let effects = cmd.execute(&ctx); assert_eq!(effects.len(), 2); // SetTileCatIdx + ChangeMode @@ -3175,7 +3189,8 @@ mod tests { #[test] fn toggle_group_under_cursor_returns_empty_without_groups() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = ToggleGroupUnderCursor; let effects = cmd.execute(&ctx); // No groups defined, so nothing to toggle @@ -3185,7 +3200,8 @@ mod tests { #[test] fn search_or_category_add_without_query_opens_category_add() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = SearchOrCategoryAdd; let effects = cmd.execute(&ctx); assert_eq!(effects.len(), 2); // SetPanelOpen + ChangeMode @@ -3199,7 +3215,8 @@ mod tests { #[test] fn cycle_panel_focus_with_no_panels_open() { let m = two_cat_model(); - let ctx = make_ctx(&m); + let layout = make_layout(&m); + let ctx = make_ctx(&m, &layout); let cmd = CyclePanelFocus { formula_open: false, category_open: false, @@ -3212,7 +3229,8 @@ mod tests { #[test] fn cycle_panel_focus_with_formula_panel_open() { let m = two_cat_model(); - let mut ctx = make_ctx(&m); + let layout = make_layout(&m); + let mut ctx = make_ctx(&m, &layout); ctx.formula_panel_open = true; let cmd = CyclePanelFocus { formula_open: true,