aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-10-11 16:45:46 +0200
committerGitHub <noreply@github.com>2022-10-11 16:45:46 +0200
commitc64bf5207a0d1b79b305f11a3d73c9da77092b6e (patch)
tree2f5c0efc7c41bc10d96b398c9861d5c7903d2ba8 /src/tests
parentchangelog: Add PR 1775 (diff)
downloadsl0ppij-c64bf5207a0d1b79b305f11a3d73c9da77092b6e.tar.gz
sl0ppij-c64bf5207a0d1b79b305f11a3d73c9da77092b6e.tar.xz
sl0ppij-c64bf5207a0d1b79b305f11a3d73c9da77092b6e.zip
feat(ux): rerun command pane (#1787)
* chore(config): default kdl keybindings config * tests * work * refactor(config): move stuff around * work * tab merge layout * work * work * layouts working * work * layout tests * work * work * feat(parsing): kdl layouts without config * refactor(kdl): move stuff around * work * tests(layout): add cases and fix bugs * work * fix(kdl): various bugs * chore(layouts): move all layouts to kdl * feat(kdl): shared keybidns * fix(layout): do not count fixed panes toward percentile * fix(keybinds): missing keybinds and actions * fix(config): adjust default tips * refactor(config): move stuff around * fix(tests): make e2e tests pass * fix(kdl): add verbose parsing errors * fix(kdl): focused tab * fix(layout): corret default_tab_template behavior * style(code): fix compile warnings * feat(cli): send actions through the cli * fix(cli): exit only when action is done * fix(cli): open embedded pane from floating pane * fix(cli): send actions to other sessions * feat(cli): command alias * feat(converter): convert old config * feat(converter): convert old layout and theme files * feat(kdl): pretty errors * feat(client): convert old YAML files on startup * fix: various bugs and styling issues * fix: e2e tests * fix(screen): propagate errors after merge * style(clippy): lower clippy level * fix(tests): own session_name variable * style(fmt): rustfmt * fix(cli): various action fixes * style(fmt): rustfmt * fix(themes): loading of theme files * style(fmt): rustfmt * fix(tests): theme fixtures * fix(layouts): better errors on unknown nodes * fix(kdl): clarify valid node terminator error * fix(e2e): adjust close tab test * fix(e2e): adjust close tab test again * style(code): cleanup some comments * get command panes not to exit on command exit * separate terminal pane_ids from raw_fds * render frame according to exit status * re-run command on enter and close pane on ctrl-c * proper error when command is not found * make ui nicer * initial pane title for command panes * fix pane override bug * reap terminal_ids from os_input_output on pane close * bool floating flag * some ui tweaks * fix tests * make rustfmt happy * e2e test for command pane * fix various concurrency issues * rename command to run in the cli * rustfmt * style(fmt): rustfmt * fix(e2e): command => run * fix(e2e): command => run in snapshot too!
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/e2e/cases.rs91
-rw-r--r--src/tests/e2e/remote_runner.rs13
-rw-r--r--src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap29
-rwxr-xr-xsrc/tests/fixtures/append-echo-script.sh2
4 files changed, 135 insertions, 0 deletions
diff --git a/src/tests/e2e/cases.rs b/src/tests/e2e/cases.rs
index 63e2d677..44551d99 100644
--- a/src/tests/e2e/cases.rs
+++ b/src/tests/e2e/cases.rs
@@ -13,6 +13,7 @@ use super::remote_runner::{RemoteRunner, RemoteTerminal, Step};
pub const QUIT: [u8; 1] = [17]; // ctrl-q
pub const ESC: [u8; 1] = [27];
pub const ENTER: [u8; 1] = [10]; // char '\n'
+pub const SPACE: [u8; 1] = [32];
pub const LOCK_MODE: [u8; 1] = [7]; // ctrl-g
pub const MOVE_FOCUS_LEFT_IN_NORMAL_MODE: [u8; 2] = [27, 104]; // alt-h
@@ -1876,3 +1877,93 @@ pub fn undo_rename_pane() {
};
assert_snapshot!(last_snapshot);
}
+
+#[test]
+#[ignore]
+pub fn send_command_through_the_cli() {
+ // here we test the following flow:
+ // - send a command through the cli to run a bash script in a temporary folder
+ // - have it open a "command pane" that can be re-run with Enter
+ // - press Enter in the command pane to re-run the script
+ //
+ // the script appends the word "foo" to a temporary file and then `cat`s that file,
+ // so when we press "Enter", it will run again and we'll see two "foo"s one after the other,
+ // that's how we know the whole flow is working
+ let fake_win_size = Size {
+ cols: 120,
+ rows: 24,
+ };
+ let mut test_attempts = 10;
+ let last_snapshot = loop {
+ RemoteRunner::kill_running_sessions(fake_win_size);
+ let mut runner = RemoteRunner::new(fake_win_size)
+ .add_step(Step {
+ name: "Run command through the cli",
+ instruction: |mut remote_terminal: RemoteTerminal| -> bool {
+ let mut step_is_complete = false;
+ if remote_terminal.status_bar_appears()
+ && remote_terminal.cursor_position_is(3, 2)
+ {
+ let fixture_folder = remote_terminal.path_to_fixture_folder();
+ remote_terminal.send_command_through_the_cli(&format!(
+ "{}/append-echo-script.sh",
+ fixture_folder
+ ));
+ step_is_complete = true;
+ }
+ step_is_complete
+ },
+ })
+ .add_step(Step {
+ name: "Wait for command to run",
+ instruction: |mut remote_terminal: RemoteTerminal| -> bool {
+ let mut step_is_complete = false;
+ if remote_terminal.snapshot_contains("<Ctrl-c>")
+ && remote_terminal.cursor_position_is(61, 3)
+ {
+ remote_terminal.send_key(&SPACE); // re-run script - here we use SPACE
+ // instead of the default ENTER because
+ // sending ENTER over SSH can be a little
+ // problematic (read: I couldn't get it
+ // to pass consistently)
+ step_is_complete = true
+ }
+ step_is_complete
+ },
+ })
+ .add_step(Step {
+ name: "Wait for script to run again",
+ instruction: |mut remote_terminal: RemoteTerminal| -> bool {
+ let mut step_is_complete = false;
+ if remote_terminal.snapshot_contains("<Ctrl-c>")
+ && remote_terminal.cursor_position_is(61, 4)
+ {
+ step_is_complete = true
+ }
+ step_is_complete
+ },
+ });
+ runner.run_all_steps();
+
+ let last_snapshot = runner.take_snapshot_after(Step {
+ name: "Wait for script to run twice",
+ instruction: |remote_terminal: RemoteTerminal| -> bool {
+ let mut step_is_complete = false;
+ if remote_terminal.snapshot_contains("foo")
+ && remote_terminal.cursor_position_is(61, 4)
+ {
+ 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);
+}
diff --git a/src/tests/e2e/remote_runner.rs b/src/tests/e2e/remote_runner.rs
index b0bde1db..b500149f 100644
--- a/src/tests/e2e/remote_runner.rs
+++ b/src/tests/e2e/remote_runner.rs
@@ -64,6 +64,8 @@ fn stop_zellij(channel: &mut ssh2::Channel) {
.write_all(b"find /tmp | grep status-bar-tips | xargs rm\n")
.unwrap();
channel.write_all(b"killall -KILL zellij\n").unwrap();
+ channel.write_all(b"rm -rf /tmp/*\n").unwrap(); // remove temporary artifacts from previous
+ // tests
}
fn start_zellij(channel: &mut ssh2::Channel) {
@@ -198,6 +200,7 @@ fn read_from_channel(
sixel_image_store,
Rc::new(RefCell::new(Palette::default())),
Rc::new(RefCell::new(HashMap::new())),
+ None,
); // 0 is the pane index
loop {
if !should_keep_running.load(Ordering::SeqCst) {
@@ -339,6 +342,16 @@ impl RemoteTerminal {
channel.flush().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1)); // wait until Zellij stops parsing startup ANSI codes from the terminal STDIN
}
+ pub fn send_command_through_the_cli(&mut self, command: &str) {
+ let mut channel = self.channel.lock().unwrap();
+ channel
+ .write_all(format!("{} run \"{}\"\n", ZELLIJ_EXECUTABLE_LOCATION, command).as_bytes())
+ .unwrap();
+ channel.flush().unwrap();
+ }
+ pub fn path_to_fixture_folder(&self) -> String {
+ ZELLIJ_FIXTURE_PATH.to_string()
+ }
pub fn load_fixture(&mut self, name: &str) {
let mut channel = self.channel.lock().unwrap();
channel
diff --git a/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap
new file mode 100644
index 00000000..8f1e58cc
--- /dev/null
+++ b/src/tests/e2e/snapshots/zellij__tests__e2e__cases__send_command_through_the_cli.snap
@@ -0,0 +1,29 @@
+---
+source: src/tests/e2e/cases.rs
+assertion_line: 1968
+expression: last_snapshot
+---
+ Zellij (e2e-test)  Tab #1 
+┌ Pane #1 ─────────────────────────────────────────────────┐┌ /usr/src/zellij/fixtures/append-echo-script.sh ──────────┐
+│$ /usr/src/zellij/x86_64-unknown-linux-musl/release/zellij││foo │
+│ run "/usr/src/zellij/fixtures/append-echo-script.sh" ││foo │
+│$ ││█ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+│ ││ │
+└──────────────────────────────────────────────────────────┘└ [ EXIT CODE: 0 ] <ENTER> to re-run, <Ctrl-c> to exit ────┘
+ Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
+ Tip: Alt + <n> => new pane. Alt + <←↓↑→> or Alt + <hjkl> => navigate. Alt + <+|-> => resize pane.
diff --git a/src/tests/fixtures/append-echo-script.sh b/src/tests/fixtures/append-echo-script.sh
new file mode 100755
index 00000000..d6b900cb
--- /dev/null
+++ b/src/tests/fixtures/append-echo-script.sh
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+echo foo >> /tmp/foo && cat /tmp/foo