1
2
3
4
5
6
7
8
9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#![cfg(unix)]
use insta::assert_snapshot;
use zellij_integration_tests::{
claim_first_terminal_and_wait_for_prompt, col, keys, normalized,
split_right_and_wait_for_prompt, Size, TestRunner, PROMPT, TERMINAL_SIZE,
};
const CHANGED_KEYS_CONFIG: &str = r#"
keybinds clear-defaults=true {
normal {
bind "F1" { SwitchToMode "Locked"; }
bind "F2" { SwitchToMode "Pane"; }
bind "F3" { SwitchToMode "Tab"; }
bind "F4" { SwitchToMode "Resize"; }
bind "F5" { SwitchToMode "Move"; }
bind "F6" { SwitchToMode "Scroll"; }
bind "Alt F7" { SwitchToMode "Session"; }
bind "Ctrl F8" { Quit; }
}
}
"#;
#[test]
fn exit_zellij() {
let zellij = TestRunner::new(TERMINAL_SIZE).start();
claim_first_terminal_and_wait_for_prompt(&zellij);
zellij.send_stdin(&keys::ctrl('q'));
zellij.wait_until("zellij said goodbye", |grid_snapshot| {
!grid_snapshot.status_bar_appears() && grid_snapshot.contains("Bye from Zellij!")
});
}
#[test]
fn resize_terminal_window() {
let mut zellij = TestRunner::new(TERMINAL_SIZE).start();
let first_terminal = claim_first_terminal_and_wait_for_prompt(&zellij);
let right_terminal = split_right_and_wait_for_prompt(&zellij);
zellij.resize(Size {
cols: 100,
rows: 24,
});
right_terminal.wait_for_size("right terminal reacted to window resize", |cols, _| {
cols < (TERMINAL_SIZE.cols / 2) as u16
});
first_terminal.wait_for_size("left terminal reacted to window resize", |cols, _| {
cols < (TERMINAL_SIZE.cols / 2) as u16
});
let grid_snapshot =
zellij.wait_until("app re-rendered at the new window size", |grid_snapshot| {
grid_snapshot.contains("Ctrl +")
&& grid_snapshot.tab_bar_appears()
&& grid_snapshot.cursor_is_at(col(52).row(2))
});
assert_snapshot!(normalized(&grid_snapshot));
zellij.quit();
}
#[test]
fn resize_re_queries_pixel_sizes() {
let mut zellij = TestRunner::new(TERMINAL_SIZE).start();
claim_first_terminal_and_wait_for_prompt(&zellij);
zellij.wait_until_raw_output("startup pixel size query", |bytes| {
count_pixel_size_queries(bytes) == 1
});
zellij.resize(Size {
cols: 100,
rows: 24,
});
zellij.wait_until_raw_output("pixel size re-query after resize", |bytes| {
count_pixel_size_queries(bytes) >= 2
});
zellij.quit();
}
fn count_pixel_size_queries(client_stdout_bytes: &[u8]) -> usize {
let pixel_size_query = b"\x1b[14t\x1b[16t";
client_stdout_bytes
.windows(pixel_size_query.len())
.filter(|window| window == pixel_size_query)
.count()
}
#[test]
fn status_bar_loads_custom_keybindings() {
let zellij = TestRunner::new(TERMINAL_SIZE)
.with_config(CHANGED_KEYS_CONFIG)
.start();
let terminal = zellij.expect_pty_spawn();
terminal.output(PROMPT);
let grid_snapshot = zellij.wait_until(
"status bar reflects the custom keybindings",
|grid_snapshot| grid_snapshot.cursor_is_at(col(2).row(1)) && grid_snapshot.contains("LOCK"),
);
assert_snapshot!(normalized(&grid_snapshot));
}
#[test]
fn use_custom_layout_with_relative_path() {
let layout_dir = format!(
"{}/../src/tests/fixtures/config-dirs/e2e-upside-down/layouts",
env!("CARGO_MANIFEST_DIR")
);
let config = format!(
"layout_dir \"{}\"\ndefault_layout \"upside-down\"\n",
layout_dir
);
let mut zellij = TestRunner::new(TERMINAL_SIZE).with_config(&config).start();
let terminal = zellij.expect_pty_spawn();
terminal.output(PROMPT);
let grid_snapshot = zellij.wait_until("upside-down layout loaded from disk", |grid_snapshot| {
grid_snapshot.tab_bar_appears()
&& grid_snapshot.status_bar_appears()
&& grid_snapshot.contains("Zellij (test")
&& grid_snapshot.cursor.is_some()
});
assert_snapshot!(normalized(&grid_snapshot));
zellij.quit();
}
#[test]
fn edit_scrollback() {
let mut zellij = TestRunner::new(TERMINAL_SIZE).start();
let terminal = claim_first_terminal_and_wait_for_prompt(&zellij);
terminal.output(b"SCROLLBACK_MARKER_ONE\r\nSCROLLBACK_MARKER_TWO\r\n");
zellij.wait_until("scrollback content rendered", |grid_snapshot| {
grid_snapshot.contains("SCROLLBACK_MARKER_TWO")
});
zellij.send_stdin(&keys::ctrl('s'));
zellij.send_stdin(&keys::key('e'));
zellij.expect_pty_spawn();
let grid_snapshot = zellij.wait_until("scrollback editor pane open", |grid_snapshot| {
grid_snapshot.contains("EDITING SCROLLBACK")
&& grid_snapshot.contains("SCROLLBACK_MARKER_ONE")
&& grid_snapshot.contains("SCROLLBACK_MARKER_TWO")
&& grid_snapshot.status_bar_appears()
});
assert_snapshot!(normalized(&grid_snapshot));
zellij.quit();
}
|