use television::tui::TESTING_ENV_VAR;
use super::super::common::*;
#[test]
fn test_layout_landscape() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--layout", "landscape"],
)
.start()
.unwrap();
s.wait()
.text("╭───────────────────────── files ──────────────────────────╮╭─")
.until()
.unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_layout_portrait() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--layout", "portrait"],
)
.start()
.unwrap();
s.wait()
.text("╭─────────────────────────────────────────────────────── files ────────────────────────────────────────────────────────╮")
.until()
.unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_toggle_layout() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&[
"files",
"--layout",
"portrait",
"--keybindings",
"ctrl-l='toggle_layout'",
],
)
.start()
.unwrap();
s.wait()
.text("╭─────────────────────────────────────────────────────── files ────────────────────────────────────────────────────────╮")
.until()
.unwrap();
s.send().key("ctrl-l").unwrap();
s.wait()
.text("╭───────────────────────── files ──────────────────────────╮╭─")
.until()
.unwrap();
s.send().key("ctrl-l").unwrap();
s.wait()
.text("╭─────────────────────────────────────────────────────── files ────────────────────────────────────────────────────────╮")
.until()
.unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_input_header_in_channel_mode() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--input-header", "UNIQUE16CHARID"],
)
.start()
.unwrap();
s.wait()
.text("UNIQUE16CHARID")
.text("CHANNEL files")
.until()
.unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_input_header_in_adhoc_mode() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["--source-command", "ls", "--input-header", "UNIQUE16CHARID"],
)
.start()
.unwrap();
s.wait()
.text("UNIQUE16CHARID")
.text("CHANNEL Custom")
.until()
.unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_input_prompt_in_channel_mode() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--input-prompt", "❯ "],
)
.start()
.unwrap();
s.wait().text("❯ ").text("CHANNEL files").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_input_prompt_in_adhoc_mode() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["--source-command", "ls", "--input-prompt", "→ "],
)
.start()
.unwrap();
s.wait().text("→ ").text("CHANNEL Custom").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_default_input_prompt() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(&pt, &["files"])
.start()
.unwrap();
s.wait().text("> ").text("CHANNEL files").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_ui_scale() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--ui-scale", "80"],
)
.start()
.unwrap();
s.wait()
.text("╭─────────────────── files ────────────────────╮╭─")
.until()
.unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_no_remote_hides_remote_panel() {
let pt = phantom();
let s =
tv_local_config_and_cable_with_args(&pt, &["files", "--no-remote"])
.start()
.unwrap();
s.wait().text("CHANNEL files").until().unwrap();
assert_frame_not_contains(&s, "── Channels ──");
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_hide_status_bar_flag_hides_status_bar() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-status-bar"],
)
.start()
.unwrap();
s.wait().text("── files ──").until().unwrap();
assert_frame_not_contains(&s, "CHANNEL files");
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_show_remote_flag_shows_remote_panel() {
let pt = phantom();
let s =
tv_local_config_and_cable_with_args(&pt, &["files", "--show-remote"])
.start()
.unwrap();
s.wait().text("(1) (2) (3)").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().text_absent("(1) (2) (3)").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_hide_remote_flag_hides_remote_panel() {
let pt = phantom();
let s =
tv_local_config_and_cable_with_args(&pt, &["files", "--hide-remote"])
.start()
.unwrap();
s.wait().text("── files ──").until().unwrap();
assert_frame_not_contains_any(&s, &["(1) (2) (3)", "── Channels ──"]);
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_hide_remote_conflicts_with_no_remote() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-remote", "--no-remote"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
fn test_hide_and_show_remote_conflict_errors() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-remote", "--show-remote"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
fn test_no_help_panel_disables_help_panel() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--no-help-panel"],
)
.start()
.unwrap();
s.wait().text("── files ──").until().unwrap();
s.send().key("ctrl-h").unwrap();
assert_frame_not_contains(&s, "───── Help ─────");
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_hide_help_panel_starts_with_help_hidden() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-help-panel"],
)
.start()
.unwrap();
s.wait().text("── files ──").until().unwrap();
s.send().key("ctrl-h").unwrap();
s.wait().text("───── Help ─────").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_show_help_panel_starts_with_help_visible() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--show-help-panel"],
)
.start()
.unwrap();
s.wait().text("───── Help ─────").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_hide_help_panel_conflicts_with_no_help_panel() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-help-panel", "--no-help-panel"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
fn test_hide_and_show_help_panel_conflict_errors() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-help-panel", "--show-help-panel"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
fn test_no_help_panel_conflicts_with_show_help_panel() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--no-help-panel", "--show-help-panel"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
fn test_tui_with_height_and_width() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--height", "20", "--width", "80"],
)
.env(TESTING_ENV_VAR, "1")
.start()
.unwrap();
s.wait().text("CHANNEL files").until().unwrap();
let frame = stable_frame(&s);
let trimmed_lines: Vec<&str> = frame.lines().map(str::trim_end).collect();
let non_empty_lines: Vec<&str> = trimmed_lines
.iter()
.copied()
.filter(|l| !l.is_empty())
.collect();
assert_eq!(
non_empty_lines.len(),
20,
"Expected 20 rows, got {}",
non_empty_lines.len()
);
let max_width = non_empty_lines
.iter()
.map(|l| l.chars().count())
.max()
.unwrap_or(0);
assert_eq!(max_width, 80, "Expected 80 columns, got {}", max_width);
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_no_preview_disables_preview_panel() {
let pt = phantom();
let s =
tv_local_config_and_cable_with_args(&pt, &["files", "--no-preview"])
.start()
.unwrap();
s.wait().text("── files ──").until().unwrap();
s.send().type_text("o").unwrap();
assert_frame_not_contains_any(&s, &["───╮╭───", "Show Preview"]);
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_show_preview_starts_with_preview_visible() {
let pt = phantom();
let s =
tv_local_config_and_cable_with_args(&pt, &["files", "--show-preview"])
.start()
.unwrap();
s.wait().text("───╮╭───").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_no_status_bar_disables_status_bar() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--no-status-bar"],
)
.start()
.unwrap();
s.wait().text("── files ──").until().unwrap();
assert_frame_not_contains(&s, "CHANNEL files");
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_show_status_bar_starts_with_status_visible() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--show-status-bar"],
)
.start()
.unwrap();
s.wait().text("CHANNEL files").until().unwrap();
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_hide_preview_scrollbar_hides_scrollbar() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--hide-preview-scrollbar"],
)
.start()
.unwrap();
s.wait().text("───╮╭───").until().unwrap();
assert_frame_not_contains(&s, "▲");
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}
#[test]
fn test_no_preview_conflicts_with_preview_flags() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--no-preview", "--preview-command", "cat {}"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
fn test_no_status_bar_conflicts_with_status_bar_flags() {
let pt = phantom();
let s = tv_local_config_and_cable_with_args(
&pt,
&["files", "--no-status-bar", "--show-status-bar"],
)
.start()
.unwrap();
s.wait().text("cannot be used with").until().unwrap();
}
#[test]
#[ignore = "needs https://github.com/crossterm-rs/crossterm/pull/957"]
fn test_tui_with_height_only() {
let pt = phantom();
let s =
tv_local_config_and_cable_with_args(&pt, &["files", "--height", "15"])
.env(TESTING_ENV_VAR, "1")
.start()
.unwrap();
s.wait().text("CHANNEL files").until().unwrap();
let frame = stable_frame(&s);
let non_empty_lines: Vec<&str> = frame
.lines()
.map(str::trim_end)
.filter(|l| !l.is_empty())
.collect();
assert_eq!(
non_empty_lines.len(),
15,
"Expected 15 rows, got {}",
non_empty_lines.len()
);
s.send().key("ctrl-c").unwrap();
s.wait().exit_code(0).until().unwrap();
}