From dade44393cc603f59366fa42dda02463b37b0811 Mon Sep 17 00:00:00 2001 From: ColonelBucket8 Date: Thu, 30 Jul 2026 10:26:13 +0800 Subject: [PATCH] chore: add constant key --- src/tests/editor.rs | 4 ++-- src/tests/keys.rs | 14 ++++++++++++++ src/tests/mod.rs | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/tests/keys.rs diff --git a/src/tests/editor.rs b/src/tests/editor.rs index 7481df8d6d..c8868e80e6 100644 --- a/src/tests/editor.rs +++ b/src/tests/editor.rs @@ -23,14 +23,14 @@ fn setup_scroll(mut ctx: TestContext) -> (TestContext, crate::app::App) { #[test] fn scroll_down() { let (mut ctx, mut app) = setup_scroll(setup_clone!()); - ctx.update(&mut app, keys("")); + ctx.update(&mut app, keys(HALF_PAGE_DOWN)); insta::assert_snapshot!(ctx.redact_buffer()); } #[test] fn scroll_past_selection() { let (mut ctx, mut app) = setup_scroll(setup_clone!()); - ctx.update(&mut app, keys("")); + ctx.update(&mut app, keys(&format!("{HALF_PAGE_DOWN}{HALF_PAGE_DOWN}{HALF_PAGE_DOWN}"))); insta::assert_snapshot!(ctx.redact_buffer()); } diff --git a/src/tests/keys.rs b/src/tests/keys.rs new file mode 100644 index 0000000000..6ca1c1f9d5 --- /dev/null +++ b/src/tests/keys.rs @@ -0,0 +1,14 @@ +//! Key constants used in integration tests. +//! +//! These mirror the default bindings in `src/default_config.toml`. When a +//! keybinding changes, update both the default config and the matching +//! constant here. +//! +//! `MOVE_*` bindings are intentionally omitted: single-character move keys +//! (`k`/`j`) are used as building blocks in many sequences, and keeping them +//! inline reads more naturally than introducing constants for `` etc. + +pub const HELP: &str = "h"; +pub const REFRESH: &str = "gr"; +pub const HALF_PAGE_DOWN: &str = ""; +pub const TOGGLE_SECTION: &str = ""; \ No newline at end of file diff --git a/src/tests/mod.rs b/src/tests/mod.rs index e5a66ac7a4..92f333f1ba 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -21,6 +21,7 @@ mod commit; mod discard; mod editor; mod fetch; +mod keys; mod log; mod merge; mod pull; @@ -34,6 +35,8 @@ mod stage; mod stash; mod unstage; +pub use keys::*; + use crossterm::event::MouseButton; use helpers::{TestContext, clone_and_commit, commit, keys, mouse_event, mouse_scroll_event, run}; use stdext::function_name; @@ -46,7 +49,7 @@ fn help_menu() { let mut ctx = setup_clone!(); let mut app = ctx.init_app(); - ctx.update(&mut app, keys("h")); + ctx.update(&mut app, keys(HELP)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -312,7 +315,7 @@ fn hide_untracked() { // Git expects "no|normal|all" here; "off" can error on some versions and break `git status`. config.set_str("status.showUntrackedFiles", "no").unwrap(); - ctx.update(&mut app, keys("gr")); + ctx.update(&mut app, keys(REFRESH)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -366,7 +369,7 @@ fn updated_externally() { fs::write(ctx.dir.join("a"), "test\n").unwrap(); - ctx.update(&mut app, keys("gr")); + ctx.update(&mut app, keys(REFRESH)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -443,7 +446,7 @@ fn crlf_diff() { commit(&ctx.dir, "crlf.txt", "unchanged\r\nunchanged\r\n"); fs::write(ctx.dir.join("crlf.txt"), "unchanged\r\nchanged\r\n").unwrap(); - ctx.update(&mut app, keys("gr")); + ctx.update(&mut app, keys(REFRESH)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -455,7 +458,7 @@ fn tab_diff() { commit(&ctx.dir, "tab.txt", "this has no tab prefixed\n"); fs::write(ctx.dir.join("tab.txt"), "\tthis has a tab prefixed\n").unwrap(); - ctx.update(&mut app, keys("gr")); + ctx.update(&mut app, keys(REFRESH)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -471,7 +474,7 @@ fn non_utf8_diff() { b"File with invalid UTF-8: \xff\xfe\n", ) .unwrap(); - ctx.update(&mut app, keys("gr")); + ctx.update(&mut app, keys(REFRESH)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -486,7 +489,7 @@ fn ext_diff() { run(&ctx.dir, &["git", "add", "-N", "unstaged.txt"]); run(&ctx.dir, &["git", "add", "staged.txt"]); run(&ctx.dir, &["git", "config", "diff.external", "/dev/null"]); - ctx.update(&mut app, keys("gr")); + ctx.update(&mut app, keys(REFRESH)); insta::assert_snapshot!(ctx.redact_buffer()); } @@ -671,7 +674,7 @@ fn mouse_wheel_scroll_up() { let mut app = ctx.init_app(); // Scroll down a bit to be able to scroll up. - ctx.update(&mut app, keys("")); + ctx.update(&mut app, keys(&format!("{HALF_PAGE_DOWN}{HALF_PAGE_DOWN}"))); ctx.update( &mut app,