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)
This commit is contained in:
@ -2962,14 +2962,15 @@ mod tests {
|
|||||||
view_panel_cursor: 0,
|
view_panel_cursor: 0,
|
||||||
tile_cat_idx: 0,
|
tile_cat_idx: 0,
|
||||||
buffers: &EMPTY_BUFFERS,
|
buffers: &EMPTY_BUFFERS,
|
||||||
none_cats: layout.none_cats.clone(),
|
view_back_stack: &[],
|
||||||
view_back_stack: Vec::new(),
|
view_forward_stack: &[],
|
||||||
view_forward_stack: Vec::new(),
|
display_value: {
|
||||||
records_col: None,
|
let key = layout.cell_key(sr, sc);
|
||||||
records_value: None,
|
key.as_ref()
|
||||||
cell_key: layout.cell_key(sr, sc),
|
.and_then(|k| model.get_cell(k).cloned())
|
||||||
row_count: layout.row_count(),
|
.map(|v| v.to_string())
|
||||||
col_count: layout.col_count(),
|
.unwrap_or_default()
|
||||||
|
},
|
||||||
visible_rows: 20,
|
visible_rows: 20,
|
||||||
visible_cols: 8,
|
visible_cols: 8,
|
||||||
expanded_cats: &EMPTY_EXPANDED,
|
expanded_cats: &EMPTY_EXPANDED,
|
||||||
@ -2991,7 +2992,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn move_selection_down_produces_set_selected() {
|
fn move_selection_down_produces_set_selected() {
|
||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let ctx = make_ctx(&m);
|
let layout = make_layout(&m);
|
||||||
|
let ctx = make_ctx(&m, &layout);
|
||||||
let cmd = MoveSelection {
|
let cmd = MoveSelection {
|
||||||
dr: 1,
|
dr: 1,
|
||||||
dc: 0,
|
dc: 0,
|
||||||
@ -3005,7 +3007,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn move_selection_clamps_to_bounds() {
|
fn move_selection_clamps_to_bounds() {
|
||||||
let m = two_cat_model();
|
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
|
// Try to move way past the end
|
||||||
let cmd = MoveSelection {
|
let cmd = MoveSelection {
|
||||||
dr: 100,
|
dr: 100,
|
||||||
@ -3021,7 +3024,8 @@ mod tests {
|
|||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let mut bufs = HashMap::new();
|
let mut bufs = HashMap::new();
|
||||||
bufs.insert("command".to_string(), "q".to_string());
|
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.dirty = true;
|
||||||
ctx.buffers = &bufs;
|
ctx.buffers = &bufs;
|
||||||
let cmd = ExecuteCommand;
|
let cmd = ExecuteCommand;
|
||||||
@ -3035,7 +3039,8 @@ mod tests {
|
|||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let mut bufs = HashMap::new();
|
let mut bufs = HashMap::new();
|
||||||
bufs.insert("command".to_string(), "q".to_string());
|
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;
|
ctx.buffers = &bufs;
|
||||||
let cmd = ExecuteCommand;
|
let cmd = ExecuteCommand;
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
@ -3054,9 +3059,10 @@ mod tests {
|
|||||||
("Month".to_string(), "Jan".to_string()),
|
("Month".to_string(), "Jan".to_string()),
|
||||||
]);
|
]);
|
||||||
m.set_cell(key, CellValue::Number(42.0));
|
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 {
|
let cmd = ClearCellCommand {
|
||||||
key: ctx.cell_key.clone().unwrap(),
|
key: ctx.cell_key().clone().unwrap(),
|
||||||
};
|
};
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
assert_eq!(effects.len(), 2); // ClearCell + MarkDirty
|
assert_eq!(effects.len(), 2); // ClearCell + MarkDirty
|
||||||
@ -3070,9 +3076,10 @@ mod tests {
|
|||||||
("Month".to_string(), "Jan".to_string()),
|
("Month".to_string(), "Jan".to_string()),
|
||||||
]);
|
]);
|
||||||
m.set_cell(key, CellValue::Number(99.0));
|
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 {
|
let cmd = YankCell {
|
||||||
key: ctx.cell_key.clone().unwrap(),
|
key: ctx.cell_key().clone().unwrap(),
|
||||||
};
|
};
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
assert_eq!(effects.len(), 2); // SetYanked + SetStatus
|
assert_eq!(effects.len(), 2); // SetYanked + SetStatus
|
||||||
@ -3081,7 +3088,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn toggle_panel_open_and_focus() {
|
fn toggle_panel_open_and_focus() {
|
||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let ctx = make_ctx(&m);
|
let layout = make_layout(&m);
|
||||||
|
let ctx = make_ctx(&m, &layout);
|
||||||
let cmd = TogglePanelAndFocus {
|
let cmd = TogglePanelAndFocus {
|
||||||
panel: effect::Panel::Formula,
|
panel: effect::Panel::Formula,
|
||||||
open: true,
|
open: true,
|
||||||
@ -3099,7 +3107,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn toggle_panel_close_and_unfocus() {
|
fn toggle_panel_close_and_unfocus() {
|
||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let ctx = make_ctx(&m);
|
let layout = make_layout(&m);
|
||||||
|
let ctx = make_ctx(&m, &layout);
|
||||||
let cmd = TogglePanelAndFocus {
|
let cmd = TogglePanelAndFocus {
|
||||||
panel: effect::Panel::Formula,
|
panel: effect::Panel::Formula,
|
||||||
open: false,
|
open: false,
|
||||||
@ -3112,7 +3121,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn enter_advance_moves_down() {
|
fn enter_advance_moves_down() {
|
||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let ctx = make_ctx(&m);
|
let layout = make_layout(&m);
|
||||||
|
let ctx = make_ctx(&m, &layout);
|
||||||
let cmd = EnterAdvance {
|
let cmd = EnterAdvance {
|
||||||
cursor: CursorState::from_ctx(&ctx),
|
cursor: CursorState::from_ctx(&ctx),
|
||||||
};
|
};
|
||||||
@ -3128,7 +3138,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn search_navigate_with_empty_query_returns_nothing() {
|
fn search_navigate_with_empty_query_returns_nothing() {
|
||||||
let m = two_cat_model();
|
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 cmd = SearchNavigate(true);
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
assert!(effects.is_empty());
|
assert!(effects.is_empty());
|
||||||
@ -3137,7 +3148,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn enter_edit_mode_produces_editing_mode() {
|
fn enter_edit_mode_produces_editing_mode() {
|
||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let ctx = make_ctx(&m);
|
let layout = make_layout(&m);
|
||||||
|
let ctx = make_ctx(&m, &layout);
|
||||||
let cmd = EnterEditMode {
|
let cmd = EnterEditMode {
|
||||||
initial_value: String::new(),
|
initial_value: String::new(),
|
||||||
};
|
};
|
||||||
@ -3150,7 +3162,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn enter_tile_select_with_categories() {
|
fn enter_tile_select_with_categories() {
|
||||||
let m = two_cat_model();
|
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 cmd = EnterTileSelect;
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
assert_eq!(effects.len(), 2); // SetTileCatIdx + ChangeMode
|
assert_eq!(effects.len(), 2); // SetTileCatIdx + ChangeMode
|
||||||
@ -3166,7 +3179,8 @@ mod tests {
|
|||||||
// Models always have virtual categories (_Index, _Dim), so tile
|
// Models always have virtual categories (_Index, _Dim), so tile
|
||||||
// select always has something to operate on.
|
// select always has something to operate on.
|
||||||
let m = Model::new("Empty");
|
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 cmd = EnterTileSelect;
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
assert_eq!(effects.len(), 2); // SetTileCatIdx + ChangeMode
|
assert_eq!(effects.len(), 2); // SetTileCatIdx + ChangeMode
|
||||||
@ -3175,7 +3189,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn toggle_group_under_cursor_returns_empty_without_groups() {
|
fn toggle_group_under_cursor_returns_empty_without_groups() {
|
||||||
let m = two_cat_model();
|
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 cmd = ToggleGroupUnderCursor;
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
// No groups defined, so nothing to toggle
|
// No groups defined, so nothing to toggle
|
||||||
@ -3185,7 +3200,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn search_or_category_add_without_query_opens_category_add() {
|
fn search_or_category_add_without_query_opens_category_add() {
|
||||||
let m = two_cat_model();
|
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 cmd = SearchOrCategoryAdd;
|
||||||
let effects = cmd.execute(&ctx);
|
let effects = cmd.execute(&ctx);
|
||||||
assert_eq!(effects.len(), 2); // SetPanelOpen + ChangeMode
|
assert_eq!(effects.len(), 2); // SetPanelOpen + ChangeMode
|
||||||
@ -3199,7 +3215,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cycle_panel_focus_with_no_panels_open() {
|
fn cycle_panel_focus_with_no_panels_open() {
|
||||||
let m = two_cat_model();
|
let m = two_cat_model();
|
||||||
let ctx = make_ctx(&m);
|
let layout = make_layout(&m);
|
||||||
|
let ctx = make_ctx(&m, &layout);
|
||||||
let cmd = CyclePanelFocus {
|
let cmd = CyclePanelFocus {
|
||||||
formula_open: false,
|
formula_open: false,
|
||||||
category_open: false,
|
category_open: false,
|
||||||
@ -3212,7 +3229,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cycle_panel_focus_with_formula_panel_open() {
|
fn cycle_panel_focus_with_formula_panel_open() {
|
||||||
let m = two_cat_model();
|
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;
|
ctx.formula_panel_open = true;
|
||||||
let cmd = CyclePanelFocus {
|
let cmd = CyclePanelFocus {
|
||||||
formula_open: true,
|
formula_open: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user