Description
Currently, test files contain hardcoded key strings like "gr", "h", "<ctrl+d>" scattered across multiple files. This makes tests fragile and harder to maintain - if a keybinding changes, multiple test locations need updating.
Current usage (17 hardcoded key strings in tests)
src/tests/mod.rs
- "h" - help menu (line 49)
- "gr" - refresh (lines 315, 369, 446, 458, 474, 489)
- "jjsj" - test navigation (line 365)
- "<ctrl+d><ctrl+d>" - half page down (line 674)
src/tests/commit.rs
- "grjjjjjcF" - refresh + commit (line 22)
- "grjjjjjjjjjcF" - refresh + commit (line 41)
src/tests/editor.rs
- "jjjjkk" - editor navigation (line 19)
- "<ctrl+d>" - half page down (line 26)
- "<ctrl+d><ctrl+d><ctrl+d>" - half page down (line 33)
- "<alt+k><alt+k>" - move prev section (line 40)
- "<alt+j>" - move next section (line 47)
- "<alt+j><alt+h>" - move next + parent section (line 54)
Proposed solution
Create a new module src/tests/keys.rs with constants matching the default keybindings from default_config.toml:
// Root menu bindings
pub const HELP: &str = "h";
pub const REFRESH: &str = "gr";
pub const MOVE_UP: &str = "k";
pub const MOVE_DOWN: &str = "j";
pub const MOVE_PREV_SECTION: &str = "<alt+k>";
pub const MOVE_NEXT_SECTION: &str = "<alt+j>";
pub const MOVE_PARENT_SECTION: &str = "<alt+h>";
pub const HALF_PAGE_DOWN: &str = "<ctrl+d>";
pub const TOGGLE_SECTION: &str = "<tab>";
// Test-specific sequences (not in default bindings)
pub const NAVIGATE_DOWN_4X: &str = "jjjj";
Then update test files to use these constants:
// Before
ctx.update(&mut app, keys("gr"));
// After
ctx.update(&mut app, keys(REFRESH));
Benefits
- Maintainability - If a keybinding changes, only update one place
- Readability - Constants have meaningful names explaining their purpose
- Discoverability - All test key strings are in one documented location
- Type safety - Easier to catch typos via constant name changes
Description
Currently, test files contain hardcoded key strings like "gr", "h", "<ctrl+d>" scattered across multiple files. This makes tests fragile and harder to maintain - if a keybinding changes, multiple test locations need updating.
Current usage (17 hardcoded key strings in tests)
src/tests/mod.rs
src/tests/commit.rs
src/tests/editor.rs
Proposed solution
Create a new module
src/tests/keys.rswith constants matching the default keybindings fromdefault_config.toml:Then update test files to use these constants:
Benefits