Skip to content

Commit

Permalink
tests/e2e: Add test for custom bindings
Browse files Browse the repository at this point in the history
in the status bar. Makes sure that the modified bindings from a custom
configuration file are read and applied to the UI.
  • Loading branch information
har7an committed Jul 27, 2022
1 parent dc7ed86 commit e2544bd
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tests/e2e/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,41 @@ pub fn accepts_basic_layout() {
assert_snapshot!(last_snapshot);
}

#[test]
#[ignore]
pub fn status_bar_loads_custom_keybindings() {
let fake_win_size = Size {
cols: 120,
rows: 24,
};
let config_file_name = "changed_keys.yaml";
let mut test_attempts = 10;
let last_snapshot = loop {
RemoteRunner::kill_running_sessions(fake_win_size);
let mut runner = RemoteRunner::new_with_config(fake_win_size, config_file_name);
runner.run_all_steps();
let last_snapshot = runner.take_snapshot_after(Step {
name: "Wait for app to load",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(3, 1)
&& remote_terminal.snapshot_contains("$ █ ││$")
&& remote_terminal.snapshot_contains("$ ") {
step_is_complete = true;
}
step_is_complete
},
});
if runner.test_timed_out && test_attempts > 0 {
test_attempts -= 1;
continue;
} else {
break last_snapshot;
}
};
assert_snapshot!(last_snapshot);
}

#[test]
#[ignore]
fn focus_pane_with_mouse() {
Expand Down
56 changes: 56 additions & 0 deletions src/tests/e2e/remote_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::rc::Rc;
const ZELLIJ_EXECUTABLE_LOCATION: &str = "/usr/src/zellij/x86_64-unknown-linux-musl/release/zellij";
const SET_ENV_VARIABLES: &str = "EDITOR=/usr/bin/vi";
const ZELLIJ_LAYOUT_PATH: &str = "/usr/src/zellij/fixtures/layouts";
const ZELLIJ_CONFIG_PATH: &str = "/usr/src/zellij/fixtures/configs";
const ZELLIJ_DATA_DIR: &str = "/usr/src/zellij/e2e-data";
const ZELLIJ_FIXTURE_PATH: &str = "/usr/src/zellij/fixtures";
const CONNECTION_STRING: &str = "127.0.0.1:2222";
Expand Down Expand Up @@ -163,6 +164,25 @@ fn start_zellij_with_layout(channel: &mut ssh2::Channel, layout_path: &str) {
std::thread::sleep(std::time::Duration::from_secs(1)); // wait until Zellij stops parsing startup ANSI codes from the terminal STDIN
}

fn start_zellij_with_config(channel: &mut ssh2::Channel, config_path: &str) {
stop_zellij(channel);
channel
.write_all(
format!(
"{} {} --config {} --session {} --data-dir {}\n",
SET_ENV_VARIABLES,
ZELLIJ_EXECUTABLE_LOCATION,
config_path,
SESSION_NAME,
ZELLIJ_DATA_DIR
)
.as_bytes(),
)
.unwrap();
channel.flush().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1)); // wait until Zellij stops parsing startup ANSI codes from the terminal STDIN
}

fn read_from_channel(
channel: &Arc<Mutex<ssh2::Channel>>,
last_snapshot: &Arc<Mutex<String>>,
Expand Down Expand Up @@ -587,6 +607,42 @@ impl RemoteRunner {
reader_thread,
}
}
pub fn new_with_config(win_size: Size, config_file_name: &'static str) -> Self {
let remote_path = Path::new(ZELLIJ_CONFIG_PATH).join(config_file_name);
let sess = ssh_connect();
let mut channel = sess.channel_session().unwrap();
let mut rows = Dimension::fixed(win_size.rows);
let mut cols = Dimension::fixed(win_size.cols);
rows.set_inner(win_size.rows);
cols.set_inner(win_size.cols);
let pane_geom = PaneGeom {
x: 0,
y: 0,
rows,
cols,
};
setup_remote_environment(&mut channel, win_size);
start_zellij_with_config(&mut channel, &remote_path.to_string_lossy());
let channel = Arc::new(Mutex::new(channel));
let last_snapshot = Arc::new(Mutex::new(String::new()));
let cursor_coordinates = Arc::new(Mutex::new((0, 0)));
sess.set_blocking(false);
let reader_thread =
read_from_channel(&channel, &last_snapshot, &cursor_coordinates, &pane_geom);
RemoteRunner {
steps: vec![],
channel,
currently_running_step: None,
current_step_index: 0,
retries_left: RETRIES,
retry_pause_ms: 100,
test_timed_out: false,
panic_on_no_retries_left: true,
last_snapshot,
cursor_coordinates,
reader_thread,
}
}
pub fn dont_panic(mut self) -> Self {
self.panic_on_no_retries_left = false;
self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 398
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1
Pane #1 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
$ █ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
<F1> LOCK  <F2> PANE  <F3> TAB  <F4> RESIZE  <F5> MOVE  <F6> SEARCH  <F7> SESSION  <F8> QUIT 
Tip: UNBOUND => open new pane. UNBOUND => navigate between panes. UNBOUND => increase/decrease pane size.
26 changes: 26 additions & 0 deletions src/tests/fixtures/configs/changed_keys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# Configuration for zellij.

# In order to troubleshoot your configuration try using the following command:
# `zellij setup --check`
# It should show current config locations and features that are enabled.

keybinds:
unbind: true
normal:
- action: [SwitchToMode: Locked,]
key: [F: 1]
- action: [SwitchToMode: Pane,]
key: [F: 2]
- action: [SwitchToMode: Tab,]
key: [F: 3]
- action: [SwitchToMode: Resize,]
key: [F: 4]
- action: [SwitchToMode: Move,]
key: [F: 5]
- action: [SwitchToMode: Scroll,]
key: [F: 6]
- action: [SwitchToMode: Session,]
key: [F: 7]
- action: [Quit,]
key: [F: 8]

0 comments on commit e2544bd

Please sign in to comment.