Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tests/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ctrl+d>"));
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("<ctrl+d><ctrl+d><ctrl+d>"));
ctx.update(&mut app, keys(&format!("{HALF_PAGE_DOWN}{HALF_PAGE_DOWN}{HALF_PAGE_DOWN}")));
insta::assert_snapshot!(ctx.redact_buffer());
}

Expand Down
14 changes: 14 additions & 0 deletions src/tests/keys.rs
Original file line number Diff line number Diff line change
@@ -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 `<alt+k>` etc.

pub const HELP: &str = "h";
pub const REFRESH: &str = "gr";
pub const HALF_PAGE_DOWN: &str = "<ctrl+d>";
pub const TOGGLE_SECTION: &str = "<tab>";
19 changes: 11 additions & 8 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod commit;
mod discard;
mod editor;
mod fetch;
mod keys;
mod log;
mod merge;
mod pull;
Expand All @@ -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;
Expand All @@ -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());
}

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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("<ctrl+d><ctrl+d>"));
ctx.update(&mut app, keys(&format!("{HALF_PAGE_DOWN}{HALF_PAGE_DOWN}")));

ctx.update(
&mut app,
Expand Down
Loading