Skip to content

Commit de695e9

Browse files
committed
Simulate key press in snapshot test
1 parent 749d561 commit de695e9

File tree

3 files changed

+131
-7
lines changed

3 files changed

+131
-7
lines changed

src/main.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,22 @@ fn set_panic_handlers() -> Result<()> {
403403

404404
#[cfg(test)]
405405
mod tests {
406-
use std::{cell::RefCell, path::PathBuf};
406+
use std::{
407+
cell::RefCell, path::PathBuf, thread::sleep, time::Duration,
408+
};
407409

408-
use asyncgit::sync::RepoPath;
410+
use asyncgit::{sync::RepoPath, AsyncGitNotification};
409411
use crossbeam_channel::unbounded;
410412
use git2_testing::repo_init;
411413
use insta::assert_snapshot;
412414
use ratatui::{backend::TestBackend, Terminal};
413415

414416
use crate::{
415417
app::App, draw, input::Input, keys::KeyConfig,
416-
ui::style::Theme,
418+
ui::style::Theme, AsyncNotification,
417419
};
418420

419-
// Macro recommended by: https://insta.rs/docs/cmd/
421+
// Macro adapted from: https://insta.rs/docs/cmd/
420422
macro_rules! apply_common_filters {
421423
{} => {
422424
let mut settings = insta::Settings::clone_current();
@@ -426,6 +428,8 @@ mod tests {
426428
settings.add_filter(r" */tmp/\.tmp\S+", "[TEMP_FILE]");
427429
// Windows Temp folder
428430
settings.add_filter(r" *\[…\].*/Local/Temp/\S+", "[TEMP_FILE]");
431+
// Commit ids that follow a vertical bar
432+
settings.add_filter(r"│[a-z0-9]{7} ", "│[AAAAA] ");
429433
let _bound = settings.bind_to_scope();
430434
}
431435
}
@@ -447,21 +451,51 @@ mod tests {
447451
.map_err(|e| eprintln!("KeyConfig loading error: {e}"))
448452
.unwrap_or_default();
449453

450-
let app = App::new(
454+
let mut app = App::new(
451455
RefCell::new(path),
452456
tx_git,
453457
tx_app,
454458
input.clone(),
455459
theme,
456-
key_config,
460+
key_config.clone(),
457461
)
458462
.unwrap();
459463

460464
let mut terminal =
461465
Terminal::new(TestBackend::new(120, 40)).unwrap();
462466

463-
let _ = draw(&mut terminal, &app);
467+
draw(&mut terminal, &app).unwrap();
464468

465469
assert_snapshot!(terminal.backend());
470+
471+
let event =
472+
AsyncNotification::Git(AsyncGitNotification::Status);
473+
app.update_async(event).unwrap();
474+
475+
sleep(Duration::from_millis(5));
476+
477+
draw(&mut terminal, &app).unwrap();
478+
479+
assert_snapshot!("app_loading_finished", terminal.backend());
480+
481+
let event = crossterm::event::KeyEvent::new(
482+
key_config.keys.tab_log.code,
483+
key_config.keys.tab_log.modifiers,
484+
);
485+
app.event(crate::input::InputEvent::Input(
486+
crossterm::event::Event::Key(event),
487+
))
488+
.unwrap();
489+
490+
sleep(Duration::from_millis(5));
491+
492+
app.update().unwrap();
493+
494+
draw(&mut terminal, &app).unwrap();
495+
496+
assert_snapshot!(
497+
"app_log_tab_showing_one_commit",
498+
terminal.backend()
499+
);
466500
}
467501
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
source: src/main.rs
3+
expression: terminal.backend()
4+
snapshot_kind: text
5+
---
6+
" Status [1] | Log [2] | Files [3] | Stashing [4] | Stashes [5][TEMP_FILE] "
7+
" ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── "
8+
"┌Unstaged Changes──────────────────────────────────────────┐┌Diff: ────────────────────────────────────────────────────┐"
9+
"│ ││ │"
10+
"│ ││ │"
11+
"│ ││ │"
12+
"│ ││ │"
13+
"│ ││ │"
14+
"│ ││ │"
15+
"│ ││ │"
16+
"│ ││ │"
17+
"│ ││ │"
18+
"│ ││ │"
19+
"│ ││ │"
20+
"│ ││ │"
21+
"│ ││ │"
22+
"│ ││ │"
23+
"│ ││ │"
24+
"│ ││ │"
25+
"│ ││ │"
26+
"│ ││ │"
27+
"│ ││ │"
28+
"│ ││ │"
29+
"└──────────────────────────────────────────────────{master}┘│ │"
30+
"┌Staged Changes────────────────────────────────────────────┐│ │"
31+
"│ ││ │"
32+
"│ ││ │"
33+
"│ ││ │"
34+
"│ ││ │"
35+
"│ ││ │"
36+
"│ ││ │"
37+
"│ ││ │"
38+
"│ ││ │"
39+
"│ ││ │"
40+
"│ ││ │"
41+
"│ ││ │"
42+
"│ ││ │"
43+
"│ ││ │"
44+
"└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘"
45+
"Branches [b] Push [p] Fetch [⇧F] Pull [f] Undo Commit [⇧U] Submodules [⇧S] Nav [kjlh] Diff [l] To stage [w] more [.]"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
source: src/main.rs
3+
expression: terminal.backend()
4+
snapshot_kind: text
5+
---
6+
" Status [1] | Log [2] | Files [3] | Stashing [4] | Stashes [5][TEMP_FILE] "
7+
" ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── "
8+
"┌Commit 1/1────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"
9+
"│[AAAAA] <1m ago name initial █"
10+
"│ ║"
11+
"│ ║"
12+
"│ ║"
13+
"│ ║"
14+
"│ ║"
15+
"│ ║"
16+
"│ ║"
17+
"│ ║"
18+
"│ ║"
19+
"│ ║"
20+
"│ ║"
21+
"│ ║"
22+
"│ ║"
23+
"│ ║"
24+
"│ ║"
25+
"│ ║"
26+
"│ ║"
27+
"│ ║"
28+
"│ ║"
29+
"│ ║"
30+
"│ ║"
31+
"│ ║"
32+
"│ ║"
33+
"│ ║"
34+
"│ ║"
35+
"│ ║"
36+
"│ ║"
37+
"│ ║"
38+
"│ ║"
39+
"│ ║"
40+
"│ ║"
41+
"│ ║"
42+
"│ ║"
43+
"│ ║"
44+
"└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘"
45+
"Scroll [kj] Mark [˽] Details [⏎] Branches [b] Compare [⇧C] Copy Hash [y] Tag [t] Checkout [⇧S] Tags [⇧T] more [.]"

0 commit comments

Comments
 (0)