use super::*;
#[test]
fn the_panel_tab_strip_still_paints_once_there_is_room() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(100, 2)).unwrap();
term.draw(|f| app.render(f)).unwrap();
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(100, 30)).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let rows: Vec<String> = (0..30)
.map(|y| (0..100).map(|x| buf[(x, y)].symbol().to_string()).collect())
.collect();
assert!(
rows.iter()
.any(|r| r.contains("PROBLEMS") && r.contains("TERMINAL")),
"{rows:#?}"
);
}
#[test]
fn splitting_the_editor_in_a_narrow_window_renders_without_panicking() {
let tmp = tempfile::tempdir().unwrap();
let draw = |app: &mut App, w: u16, h: u16| {
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(w, h)).unwrap();
term.draw(|f| app.render(f)).unwrap();
};
let mut app = app_with_open_file(tmp.path(), "api.py", "def f():\n pass\n");
draw(&mut app, 80, 24);
for _ in 0..4 {
app.split_editor();
draw(&mut app, 80, 24);
}
assert_eq!(app.editor_layout.leaf_count(), 5);
draw(&mut app, 60, 20);
draw(&mut app, 22, 8);
let mut two = app_with_open_file(tmp.path(), "b.py", "x = 1\n");
two.split_editor();
draw(&mut two, 22, 8);
draw(&mut two, 20, 8);
}
#[test]
fn a_secondary_side_bar_in_a_narrow_window_renders_without_panicking() {
let tmp = tempfile::tempdir().unwrap();
let src: String = (0..80)
.map(|i| format!("def f{i}():\n pass\n"))
.collect();
let mut app = app_with_open_file(tmp.path(), "sessions.py", &src);
app.toggle_secondary_side_bar();
for (w, h) in [(120, 35), (30, 9), (30, 24), (12, 9)] {
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(w, h)).unwrap();
term.draw(|f| app.render(f)).unwrap();
}
}
#[test]
fn resting_on_an_activity_icon_arms_its_button_hint() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let icon = app.sidebar_areas.activity_icons[ActivityIcon::Search];
let (cx, cy) = (icon.x + icon.width / 2, icon.y);
app.on_mouse_moved(cx, cy, false);
assert_eq!(
app.ui_tooltip_label.as_deref(),
Some("Search"),
"hovering the Search activity-bar icon arms its hint label"
);
app.on_mouse_moved(cx, icon.y + 200, false);
assert_eq!(app.ui_tooltip_label, None);
}
#[test]
fn chrome_tooltip_paints_in_the_sidebar_not_clamped_into_the_editor() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.ui_tooltip = Some(crate::widgets::hover_popup::HoverPopup::new_compact(
"Search".into(),
(2, 6),
));
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let popup_bg = app.theme.ui(Color::Rgb(0x1e, 0x21, 0x2a));
let painted = (0..20).any(|x| (0..12).any(|y| buf[(x, y)].bg == popup_bg));
assert!(
painted,
"the chrome tooltip must paint near its sidebar anchor, not be clamped into the editor"
);
let over_bar = (0..ACTIVITY_BAR_WIDTH).any(|x| (0..50).any(|y| buf[(x, y)].bg == popup_bg));
assert!(
!over_bar,
"the tooltip must be shifted clear of the activity-bar image column"
);
}
#[test]
fn sidebar_header_actions_are_tooltipped_per_view() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let cell = |x| Rect {
x,
y: 1,
width: 2,
height: 1,
};
app.sidebar_view = SidebarView::Explorer;
app.tree.header_new_file_btn = cell(20);
app.tree.header_new_folder_btn = cell(23);
app.tree.header_refresh_btn = cell(26);
app.tree.header_collapse_btn = cell(29);
app.tree.header_views_btn = cell(32);
assert_eq!(app.ui_tooltip_at(20, 1), Some("New File"));
assert_eq!(app.ui_tooltip_at(23, 1), Some("New Folder"));
assert_eq!(app.ui_tooltip_at(26, 1), Some("Refresh Explorer"));
assert_eq!(
app.ui_tooltip_at(29, 1),
Some("Collapse Folders in Explorer")
);
assert_eq!(app.ui_tooltip_at(32, 1), Some("Views and More Actions"));
app.sidebar_view = SidebarView::Remote;
app.remote.header_add_btn = cell(20);
app.remote.header_refresh_btn = cell(23);
assert_eq!(
app.ui_tooltip_at(20, 1),
Some("Open SSH Configuration File")
);
assert_eq!(app.ui_tooltip_at(23, 1), Some("Refresh"));
app.sidebar_view = SidebarView::SourceControl;
app.source_control.header_refresh_btn = cell(20);
assert_eq!(app.ui_tooltip_at(20, 1), Some("Refresh"));
app.sidebar_view = SidebarView::Explorer;
assert_eq!(app.ui_tooltip_at(23, 1), Some("New Folder"));
}
#[test]
fn a_second_tap_on_the_same_cell_rearms_the_dwell() {
use crossterm::event::{MouseButton, MouseEventKind};
let (mut app, _tmp, col, row) = app_with_open_file_and_editor_cell();
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), col, row));
app.hover.dwell.mark_fired();
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), col, row));
assert!(
app.hover
.dwell
.due(std::time::Instant::now() + HOVER_DELAY, HOVER_DELAY),
"a fresh tap must restart the dwell even on the same cell, else a \
dismissed popup could never be re-summoned by tapping again"
);
}
#[test]
fn a_panel_open_still_replaces_the_preview_tab() {
let (_tmp, mut app, mc, main, mh) = preview_nav_fixture();
app.editor.open_preview(&main).unwrap();
app.open_at(&mh, 1, 0).unwrap();
assert_eq!(open_tab_paths(&app), vec![mc, mh]);
}
#[test]
fn ctrl_j_clears_maximize_when_hiding_terminal() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let max_chord = key(
KeyCode::Char('J'),
KeyModifiers::CONTROL | KeyModifiers::SHIFT,
);
let toggle_chord = key(KeyCode::Char('j'), KeyModifiers::CONTROL);
app.handle_key(max_chord).unwrap();
assert!(app.terminal_maximized);
app.handle_key(toggle_chord).unwrap();
assert!(!app.show_terminal, "Ctrl+J hides the terminal");
assert!(
!app.terminal_maximized,
"hiding the terminal also clears maximize"
);
app.handle_key(toggle_chord).unwrap();
assert!(app.show_terminal, "Ctrl+J reshows the terminal");
assert!(
!app.terminal_maximized,
"reopened terminal stays in normal split, not maximized"
);
}
#[test]
fn status_bar_shows_document_facts_not_a_keyboard_cheat_sheet() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.path = Some(std::path::PathBuf::from("x.rs"));
app.editor
.set_language(Some(crate::highlight::LangKind::Rust));
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let last_y = buf.area.height - 1;
let row: String = (0..buf.area.width)
.map(|x| buf[(x, last_y)].symbol())
.collect();
assert!(
row.contains("Ln 1, Col 1"),
"status bar shows cursor position: {row:?}"
);
assert!(
row.contains("Rust"),
"status bar shows language mode: {row:?}"
);
assert!(
!row.contains("Cycle pane") && !row.contains("Quit"),
"the keyboard cheat-sheet must be gone: {row:?}"
);
}
#[test]
fn status_bar_indent_menu_action_pins_the_editor_indent_style() {
use crate::widgets::editor::IndentStyle;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.dispatch_menu_action(
MenuAction::SetIndentStyle(IndentStyle {
width: 4,
use_spaces: false,
}),
tmp.path().to_path_buf(),
);
assert_eq!(
app.editor.indent_style(),
IndentStyle {
width: 4,
use_spaces: false,
}
);
assert_eq!(app.editor.indent_style().label(), "Tab Size: 4");
}
#[cfg(not(target_os = "macos"))]
#[test]
fn ctrl_k_leads_from_the_panel_while_it_shows_problems() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.bottom_panel_tab = BottomPanelTab::Problems;
app.focus_pane(Pane::Terminal);
app.handle_key(key(KeyCode::Char('k'), KeyModifiers::CONTROL))
.unwrap();
assert!(app.cmd_k_leader.is_some());
}
fn kitty_chrome_bake_input() -> ChromeBakeInput {
ChromeBakeInput {
protocol: crate::iterm2_inline::InlineImageProtocol::Kitty,
cell: (8, 16),
is_tmux: false,
icon_bg: ::image::Rgba([0x1e, 0x1e, 0x1e, 0xff]),
icon_ink: crate::iterm2_inline::IconInk::default(),
sponsor_ink: crate::iterm2_inline::IconInk::default(),
}
}
#[test]
fn the_activity_bar_icons_bake_off_the_ui_thread() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.inline_protocol = crate::iterm2_inline::InlineImageProtocol::Kitty;
app.cell_pixel = Some((8, 16));
app.start_chrome_bake(kitty_chrome_bake_input());
assert!(
!app.overlays.activity.has_images(),
"the caller waited for the icon bake"
);
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(100, 40)).unwrap();
term.draw(|f| app.render(f)).unwrap();
let bar: String = (0..40)
.flat_map(|y| (0..ACTIVITY_BAR_WIDTH).map(move |x| (x, y)))
.map(|(x, y)| term.backend().buffer()[(x, y)].symbol().to_string())
.collect();
assert!(
bar.contains(crate::icons::ACTIVITY_EXPLORER),
"the bar must draw its glyphs while the icons bake: {bar:?}"
);
crate::test_budget::await_spawned(
std::time::Duration::from_secs(3),
"the activity-bar icon bake to land",
|| app.poll_chrome_bake(),
);
assert!(app.overlays.activity.has_images());
assert!(app.overlays.activity.dirty(), "the icons are due on screen");
assert!(app.overlays.run_debug.has_image());
assert!(app.overlays.ssh.has_image());
}
#[test]
fn a_newer_icon_bake_replaces_one_still_running() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.start_chrome_bake(kitty_chrome_bake_input());
app.start_chrome_bake(kitty_chrome_bake_input());
crate::test_budget::await_spawned(
std::time::Duration::from_secs(3),
"the activity-bar icon bake to land",
|| app.poll_chrome_bake(),
);
assert!(app.overlays.activity.has_images());
assert!(!app.poll_chrome_bake(), "a second set of icons went up");
}
fn bake_chrome_and_wait(app: &mut App, input: ChromeBakeInput) {
app.start_chrome_bake(input);
crate::test_budget::await_spawned(
std::time::Duration::from_secs(3),
"the activity-bar icon bake to land",
|| app.poll_chrome_bake(),
);
}
#[test]
fn a_theme_switch_takes_the_old_themes_icons_down_while_the_new_ones_bake() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
bake_chrome_and_wait(&mut app, kitty_chrome_bake_input());
let _ = app.consume_activity_image_clear();
let light = ChromeBakeInput {
icon_bg: ::image::Rgba([0xf3, 0xf3, 0xf3, 0xff]),
..kitty_chrome_bake_input()
};
app.start_chrome_bake(light);
assert!(
!app.overlays.activity.has_images(),
"the old theme's icons stayed up while the new ones baked"
);
assert!(!app.overlays.run_debug.has_image());
assert!(
app.consume_activity_image_clear(),
"the old icons must be evicted from the screen, not just forgotten"
);
crate::test_budget::await_spawned(
std::time::Duration::from_secs(3),
"the new theme's icons to land",
|| app.poll_chrome_bake(),
);
assert!(app.overlays.activity.has_images());
}
#[test]
fn a_cell_size_change_takes_icons_down_only_on_sixel() {
for (protocol, stays) in [
(crate::iterm2_inline::InlineImageProtocol::Kitty, true),
(crate::iterm2_inline::InlineImageProtocol::Sixel, false),
] {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let input = ChromeBakeInput {
protocol,
..kitty_chrome_bake_input()
};
bake_chrome_and_wait(&mut app, input);
app.start_chrome_bake(ChromeBakeInput {
cell: (10, 20),
..input
});
assert_eq!(
app.overlays.activity.has_images(),
stays,
"{protocol:?}: icons {} while the new cell size baked",
if stays { "came down" } else { "stayed up" }
);
}
}
#[test]
fn resize_arms_a_one_shot_terminal_clear_to_evict_stale_activity_icons() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.overlays.activity.set_images(empty_activity_images());
app.on_resize();
assert!(
app.consume_activity_image_clear(),
"a pane resize must arm exactly one terminal.clear() so iTerm2 evicts the stale OSC-1337 activity-bar image layer",
);
assert!(
!app.consume_activity_image_clear(),
"the clear request must be one-shot — consuming twice in a row returns false",
);
assert!(
app.overlays.activity.dirty(),
"resize must also re-mark the icons dirty so the post-draw flush re-emits them after the clear",
);
}
#[test]
fn activity_bar_icons_moving_within_the_flush_arms_a_one_shot_terminal_clear() {
use ratatui::layout::Rect;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.overlays.activity.set_images(empty_activity_images());
let place = |app: &mut App, base: u16| {
app.sidebar_areas.activity_icons[ActivityIcon::Explorer] = Rect::new(0, base, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Search] = Rect::new(0, base + 2, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::SourceControl] =
Rect::new(0, base + 4, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Remote] = Rect::new(0, base + 6, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::RunDebug] = Rect::new(0, base + 8, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Extensions] = Rect::new(0, base + 10, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Testing] = Rect::new(0, base + 12, 2, 1);
};
place(&mut app, 2);
app.overlays.activity.mark_dirty();
app.flush_activity_image_overlays(&[]);
assert!(
!app.consume_activity_image_clear(),
"the first emit has no prior positions to compare, so it must not arm a clear",
);
place(&mut app, 3);
app.overlays.activity.mark_dirty();
app.flush_activity_image_overlays(&[]);
assert!(
app.consume_activity_image_clear(),
"icons that moved since the last emit must arm one terminal.clear() to evict the stale image layer",
);
assert!(
!app.consume_activity_image_clear(),
"the clear request must be one-shot",
);
}
#[test]
fn the_status_bar_names_the_operation_in_progress() {
let tmp = diverged_repo();
let p = tmp.path();
assert!(!git_succeeds(p, &["merge", "feat"]));
let status = crate::git::query(p);
let text: String = git_status_spans(&status, crate::theme::Theme::default())
.iter()
.map(|s| s.content.to_string())
.collect();
assert!(text.contains("main") && text.contains("MERGING"), "{text}");
assert!(git_succeeds(p, &["merge", "--abort"]));
assert!(git_succeeds(p, &["checkout", "-q", "feat"]));
assert!(!git_succeeds(p, &["rebase", "main"]));
let status = crate::git::query(p);
let text: String = git_status_spans(&status, crate::theme::Theme::default())
.iter()
.map(|s| s.content.to_string())
.collect();
assert!(text.contains("REBASING 1/1"), "{text}");
}
#[test]
fn activity_icons_stay_visible_beside_the_centered_shortcuts_modal() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.overlays.activity.set_images(dummy_activity_images());
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let before = app.pending_activity_image_overlays().len();
assert_eq!(
before, 12,
"precondition: seven view icons (CodeQL's is added, not built in) + the sponsor heart + the settings gear + the three layout toolbar icons emit"
);
app.handle_key(key(KeyCode::F(1), KeyModifiers::NONE))
.unwrap();
term.draw(|f| app.render(f)).unwrap();
let during = app.pending_activity_image_overlays().len();
assert_eq!(
during, before,
"the shortcuts modal is centered over the editor column, so the far-left activity-bar icons it does not cover must keep re-emitting — otherwise the terminal.clear() armed by F1 wipes iTerm2's cached cells and the icons vanish for the whole time the modal is up; saw {before} icons before opening"
);
}
#[test]
fn activity_icons_behind_a_modal_that_reaches_the_left_edge_are_suppressed() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.overlays.activity.set_images(dummy_activity_images());
let backend = ratatui::backend::TestBackend::new(40, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let before = app.pending_activity_image_overlays().len();
app.handle_key(key(KeyCode::F(1), KeyModifiers::NONE))
.unwrap();
term.draw(|f| app.render(f)).unwrap();
let during = app.pending_activity_image_overlays().len();
assert!(
during < before || before == 0,
"on a terminal narrow enough that the centered modal reaches column 0, icons whose blocks intersect the modal must be suppressed so they don't ghost over the modal text; saw {before} icons before, {during} during"
);
}
#[test]
fn the_selected_activity_icon_is_visible_on_the_light_theme() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let light = crate::theme::Theme::from_id("light");
app.apply_theme(light);
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|frame| app.render(frame)).unwrap();
let buf = term.backend().buffer();
let cell_of = |glyph: char| {
(0..40u16)
.flat_map(|y| (0..4u16).map(move |x| (x, y)))
.find(|&(x, y)| buf[(x, y)].symbol() == glyph.to_string())
.map(|(x, y)| buf[(x, y)].clone())
.unwrap_or_else(|| panic!("the activity bar must paint {glyph:?}"))
};
let selected = cell_of(crate::icons::ACTIVITY_EXPLORER);
let resting = cell_of(crate::icons::ACTIVITY_SEARCH);
assert_eq!(
selected.fg,
light.activity_icon_active(),
"the selected icon wears activityBar.foreground, not the white that vanishes on a light bar"
);
assert_eq!(resting.fg, light.activity_icon_inactive());
assert_ne!(
selected.fg, resting.fg,
"selection must be readable from the icon itself, not only from the pill"
);
assert_ne!(
selected.fg, selected.bg,
"the selected glyph must not be painted in the bar's own background"
);
}
#[test]
fn croft_loch_activity_icons_rest_muted_hover_to_text_and_tint_their_badge() {
let tmp = tempfile::tempdir().unwrap();
let (mut app, _) = app_with_unsaved_file(tmp.path());
let t = crate::theme::tones(app.theme).expect("Croft Loch is the default");
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|frame| app.render(frame)).unwrap();
let search = app.sidebar_areas.activity_icons[ActivityIcon::Search];
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Moved,
column: search.x + 1,
row: search.y,
modifiers: KeyModifiers::NONE,
});
term.draw(|frame| app.render(frame)).unwrap();
let buf = term.backend().buffer();
let cell_of = |glyph: char| {
(0..40u16)
.flat_map(|y| (0..4u16).map(move |x| (x, y)))
.find(|&(x, y)| buf[(x, y)].symbol() == glyph.to_string())
.map(|(x, y)| ((x, y), buf[(x, y)].clone()))
.unwrap_or_else(|| panic!("the activity bar must paint {glyph:?}"))
};
let ((ex, ey), selected) = cell_of(crate::icons::ACTIVITY_EXPLORER);
let (_, hovered) = cell_of(crate::icons::ACTIVITY_SEARCH);
let (_, resting) = cell_of(crate::icons::ACTIVITY_EXTENSIONS);
assert_eq!(selected.fg, t.strong());
assert_eq!(hovered.fg, t.text());
assert_eq!(resting.fg, t.muted());
for cell in [&selected, &hovered, &resting] {
assert!(!cell.modifier.contains(Modifier::BOLD), "no bold glyphs");
}
let pill = &buf[(0, ey)];
assert_eq!((pill.symbol(), pill.fg), ("\u{258e}", t.accent()));
let badge = &buf[(ex + 1, ey + 1)];
assert_eq!(badge.symbol(), "1");
let fill = crate::gradient::rgb_color(crate::gradient::lerp_rgb(t.chrome, t.accent, 0.22));
assert_eq!(badge.bg, fill, "a tint of the accent, not the accent");
assert!(!badge.modifier.contains(Modifier::BOLD));
}
#[test]
fn croft_loch_paints_surfaces_on_croft_blacks_layout() {
let render = |id: &str| {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.apply_theme(crate::theme::Theme::from_id(id));
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|frame| app.render(frame)).unwrap();
let buf = term.backend().buffer().clone();
let side = app.last_sidebar_area.expect("the side bar is shown");
let panel = app.terminals[0].last_area;
(side, app.tree.last_inner, panel, buf)
};
let (side, tree, panel, black) = render("black");
let (loch_side, loch_tree, loch_panel, buf) = render("loch");
assert_eq!((loch_side, loch_tree, loch_panel), (side, tree, panel));
assert!(!panel.is_empty(), "the terminal panel is painted");
let boxed = |r: ratatui::layout::Rect, b: &ratatui::buffer::Buffer| {
(r.top()..r.bottom())
.flat_map(|y| (r.left()..r.right()).map(move |x| (x, y)))
.filter(|&(x, y)| {
"\u{250c}\u{2510}\u{2500}\u{2502}\u{2501}\u{2503}\u{256d}\u{256e}\u{2570}\u{256f}"
.contains(b[(x, y)].symbol())
})
.count()
};
assert!(boxed(side, &black) > 0 && boxed(panel, &black) > 0);
assert_eq!(boxed(side, &buf), 0, "no box in Croft Loch's side bar");
assert_eq!(boxed(panel, &buf), 0, "no box around Croft Loch's terminal");
let s = crate::theme::Theme::from_id("loch").surfaces().unwrap();
let seam = (side.top()..side.bottom())
.map(|y| &buf[(side.right() - 1, y)])
.filter(|c| c.symbol() == "\u{2595}" && c.fg == s.hairline())
.count();
assert!(
seam > side.height as usize / 2,
"a hairline down the side bar's edge"
);
assert_eq!(buf[(side.x + 2, side.bottom() - 2)].bg, s.chrome());
assert_eq!(buf[(60, 39)].bg, s.chrome(), "the status bar is chrome");
}
#[test]
fn croft_loch_leaves_the_sponsor_hearts_rows_to_its_baked_image() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.apply_theme(crate::theme::Theme::from_id("loch"));
app.overlays
.activity
.set_images(ActivityBarImages::default());
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|frame| app.render(frame)).unwrap();
let buf = term.backend().buffer();
let chrome = crate::theme::Theme::from_id("loch")
.surfaces()
.unwrap()
.chrome();
let heart = app.sidebar_areas.activity_icons[ActivityIcon::Sponsor];
assert!(!heart.is_empty(), "a 40-row bar has room for the heart");
for y in heart.top()..heart.bottom() {
assert_ne!(
buf[(heart.x, y)].bg,
chrome,
"heart row {y} left to its image"
);
}
let above = heart.top() - 1;
let last_view = app.sidebar_areas.activity_icons[ActivityIcon::Testing].bottom();
assert!(
above >= last_view.max(app.sidebar_areas.activity_icons[ActivityIcon::CodeQL].bottom())
);
assert_eq!(
buf[(heart.x, above)].bg,
chrome,
"the gap above the heart is chrome"
);
}
#[test]
fn cmd_b_and_ctrl_b_toggle_the_primary_side_bar() {
let mut app = editor_app_with_lines(&["x"]);
assert!(app.show_tree, "sidebar starts visible");
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::SUPER))
.unwrap();
assert!(!app.show_tree, "Cmd+B hides the side bar");
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::SUPER))
.unwrap();
assert!(app.show_tree, "Cmd+B again shows it");
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::CONTROL))
.unwrap();
assert!(!app.show_tree, "Ctrl+B toggles the same state");
}
#[test]
fn dragging_sidebar_splitter_resizes_sidebar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_splitter_x = Some(36); app.last_content_width = 60;
app.last_content_height = 20;
app.sidebar_width = 32;
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Down(crossterm::event::MouseButton::Left),
column: 36,
row: 5,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.gesture, Some(Gesture::Splitter(SplitterDrag::Sidebar)));
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Drag(crossterm::event::MouseButton::Left),
column: 46,
row: 5,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.sidebar_width, 42);
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Up(crossterm::event::MouseButton::Left),
column: 46,
row: 5,
modifiers: KeyModifiers::NONE,
});
assert!(!matches!(app.gesture, Some(Gesture::Splitter(_))));
}
#[test]
fn a_press_after_a_lost_release_starts_a_new_gesture() {
use crossterm::event::{MouseButton, MouseEventKind};
let (mut app, _tmp, _f) = app_with_painted_file("alpha beta gamma delta\nsecond line\n");
let seam = app
.sidebar_splitter_x
.expect("the side bar is shown, so its splitter is drawn");
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), seam, 5));
assert_eq!(app.gesture, Some(Gesture::Splitter(SplitterDrag::Sidebar)));
let width = app.sidebar_width;
let x = app.editor.last_inner.x + app.editor.last_gutter_width + 1;
let y = app.editor.last_inner.y;
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), x, y));
app.handle_mouse(mouse(MouseEventKind::Drag(MouseButton::Left), x + 6, y));
assert_eq!(
app.sidebar_width, width,
"the drag after a new press is the new press's, not the lost splitter drag's"
);
assert!(
app.editor.selection.is_some(),
"the drag in the text selects text"
);
app.handle_mouse(mouse(MouseEventKind::Up(MouseButton::Left), x + 6, y));
assert!(!matches!(app.gesture, Some(Gesture::Splitter(_))));
}
#[test]
fn sidebar_drag_grabs_one_column_left_of_seam() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_splitter_x = Some(36);
app.last_content_width = 60;
app.last_content_height = 20;
app.sidebar_width = 32;
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Down(crossterm::event::MouseButton::Left),
column: 35,
row: 5,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.gesture, Some(Gesture::Splitter(SplitterDrag::Sidebar)));
}
#[test]
fn sidebar_drag_clamps_to_minimum() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_splitter_x = Some(36);
app.last_content_width = 60;
app.last_content_height = 20;
app.sidebar_width = 32;
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Down(crossterm::event::MouseButton::Left),
column: 36,
row: 5,
modifiers: KeyModifiers::NONE,
});
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Drag(crossterm::event::MouseButton::Left),
column: 5,
row: 5,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.sidebar_width, SIDEBAR_WIDTH_MIN);
}
#[test]
fn the_maximize_gesture_also_drops_a_hidden_panes_last_inner() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.split_terminal().unwrap();
let backend = ratatui::backend::TestBackend::new(180, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let active = app.active_terminal;
let hidden = (0..app.terminals.len()).find(|i| *i != active).unwrap();
assert!(app.terminals[hidden].last_inner.width > 0, "precondition");
app.toggle_terminal_pane_maximize();
term.draw(|f| app.render(f)).unwrap();
assert_eq!(
app.terminals[hidden].last_inner,
Rect::default(),
"the gesture, not just the flag, must drop the hidden pane's rect"
);
}
#[test]
fn reordering_a_maximized_pane_keeps_its_rect_with_the_terminal() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.split_terminal().unwrap();
app.split_terminal().unwrap();
for (i, t) in app.terminals.iter_mut().enumerate() {
t.set_manual_name(Some(format!("pane{i}")));
}
app.terminal_pane_maximized = true;
let backend = ratatui::backend::TestBackend::new(180, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
assert_eq!(app.active_terminal, 2);
let pane = app.terminals[2].last_area;
assert!(
pane.width > 100,
"the maximized pane owns the panel's width"
);
let press = app.panel_hits.rail_rows[0];
let target = app.panel_hits.rail_rows[2];
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Down(crossterm::event::MouseButton::Left),
column: press.x + 1,
row: press.y,
modifiers: KeyModifiers::NONE,
});
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Drag(crossterm::event::MouseButton::Left),
column: target.x + 1,
row: target.y,
modifiers: KeyModifiers::NONE,
});
assert_eq!(
app.terminals[2].label(),
"pane0",
"the dragged terminal must have moved from slot 0 to slot 2"
);
assert_eq!(app.active_terminal, 2, "the dragged terminal stays active");
assert_eq!(
app.terminals[2].last_area, pane,
"the live pane rect follows the pane the drag leaves active"
);
assert!(
app.terminals[..2].iter().all(|t| t.last_area.width == 0),
"the hidden panes keep empty rects"
);
assert_eq!(
app.terminal_at_pos(pane.x + pane.width / 2, pane.y + pane.height / 2),
Some(2),
"a hit inside the maximized pane names the active terminal"
);
}
#[test]
fn activity_bar_render_lays_out_run_debug_between_source_control_and_remote() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let bar = Rect {
x: 0,
y: 0,
width: ACTIVITY_BAR_WIDTH,
height: 30,
};
let backend = ratatui::backend::TestBackend::new(40, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render_activity_bar(f, bar)).unwrap();
let scm = app.sidebar_areas.activity_icons[ActivityIcon::SourceControl];
let run = app.sidebar_areas.activity_icons[ActivityIcon::RunDebug];
let rem = app.sidebar_areas.activity_icons[ActivityIcon::Remote];
assert!(run.height > 0, "run-debug icon must claim a non-zero block");
assert!(
run.y > scm.y,
"run-debug must sit BELOW source-control (scm.y={}, run.y={})",
scm.y,
run.y
);
assert!(
run.y < rem.y,
"run-debug must sit ABOVE remote (run.y={}, rem.y={}) — VS Code's activity-bar order",
run.y,
rem.y
);
}
#[test]
fn clicking_the_status_bar_update_pill_starts_the_rebuild() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.local_drift = Some(String::from("def456"));
let backend = ratatui::backend::TestBackend::new(200, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let pill = app.status_hits.update;
assert!(pill.width > 0, "the drift pill is a click target");
let bar: String = (0..200)
.map(|x| term.backend().buffer()[(x, pill.y)].symbol().to_string())
.collect();
assert!(
bar.contains(&format!("{} to rebuild", super::UPDATE_CROFT_CHORD)),
"{bar}"
);
left_click(&mut app, pill.x + 1, pill.y);
assert!(app.self_install.is_some(), "a click starts the rebuild");
}
#[test]
fn switching_sidebar_view_closes_the_open_commit_dropdown() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.set_sidebar_view(SidebarView::SourceControl);
app.open_commit_actions_menu(false);
assert!(app.context_menu.is_some());
app.set_sidebar_view(SidebarView::RunDebug);
assert!(
app.context_menu.is_none(),
"the commit dropdown must close when the sidebar view changes"
);
}
#[test]
fn new_window_is_refused_for_an_unsaved_buffer() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.copy_into_new_window(0);
assert!(
app.status.contains("save the file first"),
"the refusal is explained: {}",
app.status
);
assert_eq!(app.editor.tab_count(), 1, "nothing was spawned or removed");
}
#[test]
fn new_window_is_refused_over_ssh_and_leaves_the_tab_in_place() {
let tmp = tempfile::tempdir().unwrap();
let mut app = app_with_open_file(tmp.path(), "a.txt", "hello");
app.session.is_remote = true;
let before = app.editor.tab_count();
app.move_into_new_window(app.editor.active_index());
assert!(
app.status.contains("not available over SSH"),
"the refusal is explained: {}",
app.status
);
assert_eq!(
app.editor.tab_count(),
before,
"Move is a no-op when it can't spawn — the file stays here"
);
assert!(app.editor.path.is_some());
}
#[cfg(target_os = "macos")]
#[test]
fn ghostty_open_argv_suppresses_the_stray_default_window() {
use std::ffi::OsStr;
let exe = std::path::Path::new("/usr/local/bin/croft");
let root = std::path::Path::new("/home/me/project");
let file = std::path::Path::new("/home/me/project/src/main.rs");
let argv = ghostty_open_argv(exe, root, file);
let argv: Vec<&OsStr> = argv.iter().map(|s| s.as_os_str()).collect();
assert_eq!(
argv,
[
OsStr::new("-na"),
OsStr::new("Ghostty"),
OsStr::new("--args"),
OsStr::new("--initial-window=false"),
OsStr::new("--quit-after-last-window-closed=true"),
OsStr::new("-e"),
OsStr::new("/usr/local/bin/croft"),
OsStr::new("/home/me/project"),
OsStr::new("--open-file"),
OsStr::new("/home/me/project/src/main.rs"),
OsStr::new("--zen"),
],
"one Ghostty window, focused on the file, no stray default window"
);
}
#[cfg(target_os = "macos")]
#[test]
fn new_window_targets_the_host_terminal() {
assert_eq!(
detect_host_terminal(Some("iTerm.app"), None),
HostTerminal::ITerm2
);
assert_eq!(
detect_host_terminal(Some("ghostty"), None),
HostTerminal::Ghostty
);
assert_eq!(
detect_host_terminal(Some("Apple_Terminal"), None),
HostTerminal::AppleTerminal
);
assert_eq!(
detect_host_terminal(None, Some("xterm-ghostty")),
HostTerminal::Ghostty
);
assert_eq!(
detect_host_terminal(Some("WezTerm"), None),
HostTerminal::Unknown("WezTerm".to_string())
);
}
#[test]
fn zen_layout_collapses_explorer_and_terminal_and_survives_opening_a_file() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("hi.rs");
std::fs::write(&file, "fn main() {}").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
assert!(app.show_tree, "explorer visible by default");
assert!(app.show_terminal, "terminal visible by default");
app.show_tree = false;
app.show_terminal = false;
app.open_file_at_launch(&file);
assert!(!app.show_tree, "--zen keeps the explorer collapsed");
assert!(!app.show_terminal, "--zen keeps the terminal collapsed");
assert_eq!(app.editor.path.as_deref(), Some(file.as_path()));
}
#[test]
fn cmd_active_treats_ctrl_as_command_only_on_termux() {
assert!(!cmd_active(KeyModifiers::CONTROL, false));
assert!(cmd_active(KeyModifiers::CONTROL, true));
}
#[test]
fn the_output_view_renders_a_pushed_channel_line() {
use crate::output::OutputLevel;
let ch = "app-output-render-test";
crate::output::push(ch, OutputLevel::Error, "boom-from-server");
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.bottom_panel_tab = BottomPanelTab::Output;
app.output.sync();
assert!(
app.output.select_by_name(ch),
"the pushed channel is present in the bus",
);
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let mut text = String::new();
for y in 0..50 {
for x in 0..140 {
text.push_str(buf[(x, y)].symbol());
}
}
assert!(
text.contains("boom-from-server"),
"the OUTPUT view renders the channel's line",
);
}
#[test]
fn clicking_output_clear_empties_the_shown_log() {
use crossterm::event::{MouseButton, MouseEventKind};
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let channel = "Clear 2861";
for i in 0..3 {
crate::output::push(
channel,
crate::output::OutputLevel::Info,
&format!("cleared line {i}"),
);
}
app.output.sync();
assert!(app.output.select_by_name(channel));
app.bottom_panel_tab = BottomPanelTab::Output;
let mut term = ratatui::Terminal::new(ratatui::backend::TestBackend::new(140, 50)).unwrap();
term.draw(|f| app.render(f)).unwrap();
let area = app.output.last_area;
let shown = |term: &ratatui::Terminal<ratatui::backend::TestBackend>| {
let buf = term.backend().buffer();
(area.y..area.bottom())
.flat_map(|y| (area.x..area.right()).map(move |x| (x, y)))
.map(|(x, y)| buf[(x, y)].symbol().to_string())
.collect::<String>()
};
assert!(shown(&term).contains("cleared line 2"), "{}", shown(&term));
let header: Vec<String> = {
let buf = term.backend().buffer();
(area.x..area.right())
.map(|x| buf[(x, area.y)].symbol().to_string())
.collect()
};
let at = (0..header.len().saturating_sub(5))
.find(|&i| header[i..i + 5].concat() == "clear")
.expect("the toolbar draws its clear button") as u16;
let (x, y) = (area.x + at + 1, area.y);
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), x, y));
app.handle_mouse(mouse(MouseEventKind::Up(MouseButton::Left), x, y));
term.draw(|f| app.render(f)).unwrap();
assert!(
!shown(&term).contains("cleared line"),
"clear empties the shown log: {}",
shown(&term)
);
}
#[test]
fn the_active_panel_tab_is_underlined() {
use ratatui::style::Modifier;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let t = app.panel_hits.terminal_tab;
let buf = term.backend().buffer();
let underlined = (t.x..t.x + t.width)
.filter(|&x| buf[(x, t.y)].modifier.contains(Modifier::UNDERLINED))
.count();
assert_eq!(
underlined,
"TERMINAL".len(),
"underline spans only the word"
);
assert!(
!buf[(t.x, t.y)].modifier.contains(Modifier::UNDERLINED),
"the leading pad space is not underlined",
);
assert!(
!buf[(t.x + t.width - 1, t.y)]
.modifier
.contains(Modifier::UNDERLINED),
"the trailing pad space is not underlined",
);
}
#[test]
fn croft_loch_panel_tabs_step_from_muted_to_text_to_strong() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let t = crate::theme::tones(app.theme).expect("Croft Loch is the default");
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let out = app.panel_hits.output_tab;
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Moved,
column: out.x + 2,
row: out.y,
modifiers: KeyModifiers::NONE,
});
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer();
let word = |r: ratatui::layout::Rect| {
(r.x..r.right())
.map(|x| &buf[(x, r.y)])
.find(|c| c.symbol() != " ")
.unwrap()
.clone()
};
let active = word(app.panel_hits.terminal_tab);
assert_eq!(active.fg, t.strong());
assert!(!active.modifier.contains(Modifier::BOLD));
assert!(active.modifier.contains(Modifier::UNDERLINED));
assert_eq!(active.underline_color, t.accent());
assert_eq!(
word(app.panel_hits.output_tab).fg,
t.text(),
"hover is body text"
);
assert_eq!(word(app.panel_hits.ports_tab).fg, t.muted());
let first = app.panel_hits.problems_tab;
assert_eq!(buf[(first.x, first.y)].symbol(), "P", "no leading pad");
let inner = app.terminals[0].last_inner;
assert_eq!(first.x, inner.x, "the first title lines up with the shell");
}
#[test]
fn croft_loch_palette_scrim_sinks_the_active_tabs_underline() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let t = crate::theme::tones(app.theme).expect("Croft Loch is the default");
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
app.open_command_palette();
app.command_palette
.as_mut()
.unwrap()
.set_query("toggle terminal");
term.draw(|f| app.render(f)).unwrap();
let card = app.command_palette.as_ref().unwrap().last_rect;
let tab = app.panel_hits.terminal_tab;
assert!(
card.intersection(tab).is_empty(),
"the tab is behind the scrim: {card:?} / {tab:?}"
);
let buf = term.backend().buffer();
let word = (tab.x..tab.right())
.map(|x| &buf[(x, tab.y)])
.find(|c| c.symbol() != " ")
.unwrap();
assert!(word.modifier.contains(Modifier::UNDERLINED));
assert_ne!(word.underline_color, t.accent(), "no full-strength teal");
let ratatui::style::Color::Rgb(r, g, b) = word.bg else {
panic!("the scrim leaves an RGB fill: {:?}", word.bg);
};
let sunk = crate::gradient::lerp_rgb(t.accent, (r, g, b), 0.58);
assert_eq!(
word.underline_color,
crate::gradient::rgb_color(sunk),
"the underline sinks as far as the title's ink does"
);
}
#[test]
fn croft_loch_panel_panes_draw_a_hairline_or_the_lip_on_their_top_edge() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let t = crate::theme::tones(app.theme).expect("Croft Loch is the default");
app.focus_pane(Pane::Editor);
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let pane = app.terminals[0].last_area;
let top = |term: &ratatui::Terminal<ratatui::backend::TestBackend>, x: u16, y: u16| {
let c = &term.backend().buffer()[(x, y)];
(c.symbol().to_string(), c.fg)
};
assert_eq!(
top(&term, pane.x + 4, pane.y),
("\u{2594}".to_string(), t.hairline()),
"an unfocused pane's top edge is the hairline"
);
app.focus_pane(Pane::Terminal);
term.draw(|f| app.render(f)).unwrap();
assert_eq!(
top(&term, pane.x, pane.y),
("\u{2594}".to_string(), t.accent()),
"the focused pane's lip starts in the accent"
);
app.set_bottom_panel_tab(BottomPanelTab::Problems);
app.focus_pane(Pane::Editor);
term.draw(|f| app.render(f)).unwrap();
let view = app.problems.last_area;
assert_eq!(
top(&term, view.x, view.y),
("\u{2594}".to_string(), t.hairline()),
"PROBLEMS draws the same edge"
);
}
#[test]
fn osk_auto_shows_on_terminal_tap_and_only_when_armed() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk_auto = true;
draw(&mut app, 80, 40);
let t = app.terminals[0].last_area;
assert!(t.width > 0 && t.height > 0, "terminal pane must be visible");
left_click(&mut app, t.x + t.width / 2, t.y + t.height / 2);
assert!(
app.osk.is_some(),
"a tap in the terminal must raise the on-screen keyboard on Termux"
);
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk_auto = false;
draw(&mut app, 80, 40);
let t = app.terminals[0].last_area;
left_click(&mut app, t.x + t.width / 2, t.y + t.height / 2);
assert!(app.osk.is_none());
}
#[test]
fn osk_auto_shows_on_editor_tap() {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("notes.txt");
std::fs::write(&path, "hello\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk_auto = true;
app.editor.open_preview(&path).unwrap();
app.focus_pane(Pane::Editor);
draw(&mut app, 80, 40);
let e = app.editor.last_area;
left_click(&mut app, e.x + e.width / 2, e.y + e.height / 2);
assert!(
app.osk.is_some(),
"a tap in the editor text area must raise the on-screen keyboard"
);
}
#[test]
fn osk_reserves_bottom_band_above_status_bar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk = Some(crate::widgets::osk::Osk::new());
draw(&mut app, 80, 40);
let band = app.osk.as_ref().unwrap().last_area;
assert_eq!(
band.height,
crate::widgets::osk::band_height(40),
"band height scales with the frame for thumb-sized keys"
);
assert_eq!(
band.y + band.height,
40 - 1,
"keyboard docks directly above the status bar"
);
assert_eq!(band.width, 80, "keyboard spans the full frame width");
assert_eq!(
app.terminals[0].last_area,
Rect::default(),
"non-focused terminal must fold away (and not phantom-hit-test) while the keyboard is up"
);
}
#[test]
fn osk_with_editor_focus_hides_terminal_and_keeps_editor() {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("notes.txt");
std::fs::write(&path, "hello\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_preview(&path).unwrap();
app.focus_pane(Pane::Editor);
app.osk = Some(crate::widgets::osk::Osk::new());
draw(&mut app, 80, 40);
let band = app.osk.as_ref().unwrap().last_area;
assert!(band.height > 0);
assert_eq!(app.terminals[0].last_area, Rect::default());
let e = app.editor.last_full_area;
assert!(
e.height > 0,
"the editor must stay visible while typing into it"
);
assert!(
e.y + e.height <= band.y,
"editor must end above the keyboard band"
);
}
#[test]
fn osk_with_terminal_focus_bumps_terminal_above_keyboard() {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("notes.txt");
std::fs::write(&path, "hello\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.editor.open_preview(&path).unwrap();
app.focus_pane(Pane::Terminal);
app.osk = Some(crate::widgets::osk::Osk::new());
draw(&mut app, 80, 40);
let band = app.osk.as_ref().unwrap().last_area;
let t = app.terminals[0].last_area;
assert!(
t.height > 0,
"the terminal must stay visible while typing into it"
);
assert_eq!(
t.y + t.height,
band.y,
"terminal rides directly on top of the keyboard"
);
assert_eq!(
t.y, 1,
"the panel group claims the editor's space from the top; the terminal \
body sits one row down, under the panel tab strip (PROBLEMS / TERMINAL)",
);
assert_eq!(
app.editor.last_area.height, 0,
"the open editor folds away while typing into the terminal"
);
}
#[test]
fn osk_tap_types_into_focused_editor() {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("notes.txt");
std::fs::write(&path, "").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk_auto = true;
app.editor.open_preview(&path).unwrap();
app.focus_pane(Pane::Editor);
draw(&mut app, 80, 40);
let e = app.editor.last_area;
left_click(&mut app, e.x + 1, e.y + 1);
assert!(app.osk.is_some());
draw(&mut app, 80, 40);
let r = app
.osk
.as_ref()
.unwrap()
.rect_for(crate::widgets::osk::OskKey::Char('a'))
.expect("lower layer exposes the letter a");
left_click(&mut app, r.x + r.width / 2, r.y);
assert_eq!(
app.editor.lines[0], "a",
"an OSK letter tap must reach the editor buffer like a keystroke"
);
}
#[test]
fn osk_hide_key_dismisses_the_band() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk = Some(crate::widgets::osk::Osk::new());
draw(&mut app, 80, 40);
let r = app
.osk
.as_ref()
.unwrap()
.rect_for(crate::widgets::osk::OskKey::Hide)
.expect("hide key is always present");
left_click(&mut app, r.x + r.width / 2, r.y);
assert!(app.osk.is_none(), "the hide key must dismiss the keyboard");
}
#[test]
fn osk_tap_types_into_file_finder_query() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.osk = Some(crate::widgets::osk::Osk::new());
app.open_file_finder();
draw(&mut app, 80, 40);
let r = app
.osk
.as_ref()
.unwrap()
.rect_for(crate::widgets::osk::OskKey::Char('a'))
.unwrap();
left_click(&mut app, r.x + r.width / 2, r.y);
assert_eq!(
app.file_finder.as_ref().unwrap().query,
"a",
"OSK taps must route into open modals, not be swallowed by their mouse gates"
);
}
#[test]
fn hovering_a_non_selected_activity_icon_emits_its_hovered_variant() {
use ratatui::layout::Rect;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.overlays.activity.set_images(ActivityBarImages {
icons: [
ActivityIconImages {
active: Some("EA".into()),
inactive: "EI".into(),
hovered: "EH".into(),
},
ActivityIconImages {
active: Some("SA".into()),
inactive: "SI".into(),
hovered: "SH".into(),
},
ActivityIconImages {
active: Some("CA".into()),
inactive: "CI".into(),
hovered: "CH".into(),
},
ActivityIconImages {
active: Some("RA".into()),
inactive: "RI".into(),
hovered: "RH".into(),
},
ActivityIconImages {
active: Some("DA".into()),
inactive: "DI".into(),
hovered: "DH".into(),
},
ActivityIconImages {
active: Some("XA".into()),
inactive: "XI".into(),
hovered: "XH".into(),
},
ActivityIconImages {
active: Some("TA".into()),
inactive: "TI".into(),
hovered: "TH".into(),
},
ActivityIconImages {
active: Some("CA".into()),
inactive: "CI".into(),
hovered: "CH".into(),
},
ActivityIconImages {
active: None,
inactive: "HI".into(),
hovered: "HH".into(),
},
ActivityIconImages {
active: Some("GA".into()),
inactive: "GI".into(),
hovered: "GH".into(),
},
],
layout_sidebar_on: "LS".into(),
layout_sidebar_on_hover: "LSh".into(),
layout_sidebar_off: "LF".into(),
layout_sidebar_off_hover: "LFh".into(),
layout_panel_on: "LP".into(),
layout_panel_on_hover: "LPh".into(),
layout_panel_off: "LQ".into(),
layout_panel_off_hover: "LQh".into(),
layout_customize: "LC".into(),
layout_customize_hover: "LCh".into(),
});
app.sidebar_areas.activity_icons[ActivityIcon::Explorer] = Rect::new(0, 0, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Search] = Rect::new(0, 2, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::SourceControl] = Rect::new(0, 4, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Remote] = Rect::new(0, 6, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::RunDebug] = Rect::new(0, 8, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Extensions] = Rect::new(0, 10, 2, 1);
app.sidebar_areas.activity_icons[ActivityIcon::Testing] = Rect::new(0, 12, 2, 1);
app.sidebar_view = SidebarView::Explorer;
app.hovered_activity_icon = Some(ActivityIcon::Search);
let emitted: Vec<&str> = app
.pending_activity_image_overlays()
.into_iter()
.map(|(_, s)| s)
.collect();
assert!(
emitted.contains(&"SH"),
"the hovered search icon emits its hovered variant"
);
assert!(
!emitted.contains(&"SI"),
"search drops its resting variant while hovered"
);
assert!(
emitted.contains(&"EA"),
"the selected explorer view still wins with its active variant"
);
}
#[test]
fn hovering_the_sponsor_heart_emits_its_hovered_variant() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut images = ActivityBarImages::default();
images.icons[ActivityIcon::Sponsor as usize] = ActivityIconImages {
active: None,
inactive: "HI".into(),
hovered: "HH".into(),
};
app.overlays.activity.set_images(images);
let emitted = |app: &App| -> Vec<String> {
app.pending_activity_image_overlays()
.into_iter()
.map(|(_, s)| s.to_string())
.collect()
};
draw(&mut app, 120, 40);
assert!(emitted(&app).contains(&"HI".to_string()));
let heart = app.sidebar_areas.activity_icons[ActivityIcon::Sponsor];
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Moved,
column: heart.x,
row: heart.y,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.hovered_activity_icon, Some(ActivityIcon::Sponsor));
let hovered = emitted(&app);
assert!(hovered.contains(&"HH".to_string()), "{hovered:?}");
assert!(!hovered.contains(&"HI".to_string()), "{hovered:?}");
}
#[test]
fn a_collapsed_side_bar_unpills_its_views_activity_icon() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut images = ActivityBarImages::default();
images.icons[ActivityIcon::Explorer as usize] = ActivityIconImages {
active: Some("EA".into()),
inactive: "EI".into(),
hovered: "EH".into(),
};
app.overlays.activity.set_images(images);
let emitted = |app: &App| -> Vec<String> {
app.pending_activity_image_overlays()
.into_iter()
.map(|(_, s)| s.to_string())
.collect()
};
draw(&mut app, 120, 40);
assert!(emitted(&app).contains(&"EA".to_string()));
app.overlays.activity.mark_emitted();
draw(&mut app, 120, 40);
assert!(
!app.overlays.activity.dirty(),
"an unchanged frame re-sends nothing"
);
app.toggle_side_bar();
draw(&mut app, 120, 40);
assert!(
app.overlays.activity.dirty(),
"closing the side bar re-sends the icons"
);
let shown = emitted(&app);
assert!(shown.contains(&"EI".to_string()), "{shown:?}");
assert!(!shown.contains(&"EA".to_string()), "{shown:?}");
}
#[test]
fn moving_over_an_activity_icon_marks_it_hovered_and_redirties_the_overlay() {
use ratatui::layout::Rect;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_areas.activity_icons[ActivityIcon::Search] = Rect::new(0, 4, 2, 2);
app.hovered_activity_icon = None;
app.overlays.activity.mark_emitted();
assert!(!app.overlays.activity.dirty());
let moved = |col: u16, row: u16| crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Moved,
column: col,
row,
modifiers: KeyModifiers::NONE,
};
app.handle_mouse(moved(0, 5));
assert_eq!(app.hovered_activity_icon, Some(ActivityIcon::Search));
assert!(
app.overlays.activity.dirty(),
"entering an icon re-emits the swapped image"
);
app.overlays.activity.mark_emitted();
app.handle_mouse(moved(1, 4));
assert_eq!(app.hovered_activity_icon, Some(ActivityIcon::Search));
assert!(
!app.overlays.activity.dirty(),
"drifting within one icon does not re-emit"
);
app.handle_mouse(moved(40, 20));
assert_eq!(app.hovered_activity_icon, None);
assert!(
app.overlays.activity.dirty(),
"leaving the icon re-emits its resting variant"
);
}
#[test]
fn status_transient_keeps_its_tail_when_longer_than_the_bar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let deep: String = "directory-segment/".repeat(7);
app.status = format!("Opened /{deep}main.rs");
let backend = ratatui::backend::TestBackend::new(140, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer().clone();
let a = buf.area;
let last_row: String = (a.x..a.x + a.width)
.map(|x| buf[(x, a.y + a.height - 1)].symbol().to_string())
.collect();
assert!(
last_row.contains("main.rs"),
"an over-long status transient must middle-elide so its tail stays \
visible; the bar showed: {last_row:?}"
);
app.handle_key(key(KeyCode::Right, KeyModifiers::NONE))
.unwrap();
app.status = format!("Opened /{deep}main.rs");
app.status_logged = app.status.clone();
term.draw(|f| app.render(f)).unwrap();
let last_row = status_row(&term);
assert!(last_row.contains("main.rs"), "{last_row:?}");
assert!(
last_row.contains("Ln 1, Col 1"),
"the right cluster must still paint: {last_row:?}"
);
}
#[test]
fn status_message_with_wide_chars_keeps_its_tail_beside_the_cluster() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(140, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
let deep = "\u{76ee}\u{5f55}/".repeat(15);
app.status = format!("Opened /{deep}main.rs");
app.status_logged = app.status.clone();
app.status_wide = false;
term.draw(|f| app.render(f)).unwrap();
let row = status_row(&term);
assert!(
row.contains("Ln 1, Col 1"),
"the right cluster paints: {row:?}"
);
assert!(
row.contains("main.rs"),
"the wide-char message keeps its tail: {row:?}"
);
}
#[test]
fn a_wide_workspace_name_keeps_the_status_bar_targets_under_their_text() {
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path().join("\u{9879}\u{76ee}");
std::fs::create_dir(&root).unwrap();
let mut app = App::new(root).unwrap();
let backend = ratatui::backend::TestBackend::new(120, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer().clone();
let y = buf.area.height - 1;
let glyph_x = (0..buf.area.width)
.find(|&x| buf[(x, y)].symbol() == "\u{ea87}")
.expect("the error count's glyph is on the bar");
let row = status_row(&term);
assert!(
row.contains("\u{9879} \u{76ee} "),
"the cap names the folder: {row:?}"
);
assert_eq!(app.status_hits.diagnostics.x + 1, glyph_x);
assert_eq!(app.status_hits.diagnostics.y, y);
}
#[test]
fn a_multi_line_status_message_keeps_its_words_apart() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(140, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
app.status =
String::from("Branch: overwritten by checkout:\n\ta.txt\nswitch branches.\nAborting");
term.draw(|f| app.render(f)).unwrap();
let row = status_row(&term);
assert!(
row.contains("Branch: overwritten by checkout: a.txt switch branches. Aborting"),
"{row:?}"
);
}
fn recorder_prompt() -> String {
String::from(
"Press the new shortcut for \u{201c}Sort Lines Ascending\u{201d} (a function key or a chord with Cmd/Ctrl/Alt; Esc cancels)",
)
}
#[test]
fn a_new_long_status_message_takes_the_whole_bar_until_a_key() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(140, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
app.status = recorder_prompt();
term.draw(|f| app.render(f)).unwrap();
let row = status_row(&term);
assert!(
row.contains(&recorder_prompt()),
"the whole message shows at 140 columns: {row:?}"
);
assert!(
!row.contains("Ln 1, Col 1"),
"the cluster made room: {row:?}"
);
term.draw(|f| app.render(f)).unwrap();
assert!(status_row(&term).contains(&recorder_prompt()));
app.handle_mouse(MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 60,
row: 5,
modifiers: KeyModifiers::NONE,
});
app.status = recorder_prompt();
term.draw(|f| app.render(f)).unwrap();
let row = status_row(&term);
assert!(
row.contains("Ln 1, Col 1"),
"a click brings the cluster back: {row:?}"
);
assert!(
row.contains('\u{2026}'),
"and the old message elides beside it: {row:?}"
);
}
#[test]
fn status_messages_are_kept_in_the_messages_channel() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(120, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
let first = format!("{} #{}", recorder_prompt(), std::process::id());
let second = format!("Fleet: no host named web1 #{}", std::process::id());
app.status = first.clone();
term.draw(|f| app.render(f)).unwrap();
app.status = second.clone();
term.draw(|f| app.render(f)).unwrap();
term.draw(|f| app.render(f)).unwrap();
let lines: Vec<String> = crate::output::snapshot(crate::output::CHANNEL_MESSAGES)
.unwrap_or_default()
.into_iter()
.map(|l| l.text)
.collect();
assert_eq!(
lines.iter().filter(|l| **l == first).count(),
1,
"{lines:?}"
);
assert_eq!(
lines.iter().filter(|l| **l == second).count(),
1,
"logged once"
);
let r = app.status_hits.message;
assert!(r.width > 0, "the message has a click target");
app.handle_mouse(MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: r.x + 1,
row: r.y,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Output);
assert_eq!(
app.output.selected_name().as_deref(),
Some(crate::output::CHANNEL_MESSAGES)
);
}
#[test]
fn a_status_message_that_fits_keeps_the_cluster() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(120, 30);
let mut term = ratatui::Terminal::new(backend).unwrap();
app.status = String::from("Saved");
term.draw(|f| app.render(f)).unwrap();
let row = status_row(&term);
assert!(
row.contains("Saved") && row.contains("Ln 1, Col 1"),
"{row:?}"
);
app.status.clear();
term.draw(|f| app.render(f)).unwrap();
let lines = crate::output::snapshot(crate::output::CHANNEL_MESSAGES).unwrap_or_default();
assert!(
lines.iter().all(|l| !l.text.is_empty()),
"an empty status is not logged"
);
assert_eq!(
app.status_hits.message.width, 0,
"no message, no click target"
);
}
fn main_band() -> Rect {
Rect {
x: 0,
y: 0,
width: 100,
height: 30,
}
}
#[test]
fn chrome_left_position_orders_activity_primary_editor_secondary() {
let l = compute_chrome_layout(main_band(), true, true, true, SideBarPosition::Left, 20, 30);
let a = l.activity.expect("activity shown");
let p = l.primary_side.expect("primary shown");
let s = l.secondary_side.expect("secondary shown");
assert_eq!(a.x, 0, "activity bar hugs the left edge");
assert_eq!(a.width, ACTIVITY_BAR_WIDTH);
assert_eq!(
p.x,
a.x + a.width,
"primary side bar follows the activity bar"
);
assert_eq!(p.width, 20);
assert_eq!(
l.right.x,
p.x + p.width,
"editor follows the primary side bar"
);
assert_eq!(
s.x,
l.right.x + l.right.width,
"secondary is on the far right"
);
assert_eq!(
l.sidebar_splitter_x,
Some(l.right.x),
"seam is the editor's left edge"
);
assert_eq!(a.width + p.width + l.right.width + s.width, 100);
}
#[test]
fn chrome_right_position_mirrors_to_secondary_editor_primary_activity() {
let l = compute_chrome_layout(
main_band(),
true,
true,
true,
SideBarPosition::Right,
20,
30,
);
let s = l.secondary_side.expect("secondary shown");
let p = l.primary_side.expect("primary shown");
let a = l.activity.expect("activity shown");
assert_eq!(
s.x, 0,
"secondary hugs the left when the primary is on the right"
);
assert_eq!(l.right.x, s.x + s.width, "editor follows the secondary");
assert_eq!(
p.x,
l.right.x + l.right.width,
"primary side bar follows the editor"
);
assert_eq!(a.x, p.x + p.width, "activity bar is on the far right");
assert_eq!(
l.sidebar_splitter_x,
Some(p.x),
"seam is the editor's right edge"
);
assert_eq!(s.width + l.right.width + p.width + a.width, 100);
}
#[test]
fn chrome_hidden_regions_consume_no_width() {
let l = compute_chrome_layout(
main_band(),
false,
false,
false,
SideBarPosition::Left,
20,
30,
);
assert!(l.activity.is_none());
assert!(l.primary_side.is_none());
assert!(l.secondary_side.is_none());
assert_eq!(l.sidebar_splitter_x, None, "no seam without a side bar");
assert_eq!(l.right.x, 0, "editor reclaims the whole band");
assert_eq!(l.right.width, 100);
}
#[test]
fn chrome_narrow_frame_shrinks_primary_to_keep_editor_min() {
let l = compute_chrome_layout(main_band(), true, true, false, SideBarPosition::Left, 90, 0);
assert_eq!(l.right.width, RIGHT_PANE_MIN, "editor keeps its minimum");
let p = l.primary_side.expect("primary still shown, just narrower");
assert_eq!(p.width, 100 - ACTIVITY_BAR_WIDTH - RIGHT_PANE_MIN);
}
#[test]
fn chrome_drops_a_secondary_side_bar_the_window_cannot_fit() {
let narrow = Rect::new(0, 0, 30, 9);
for pos in [SideBarPosition::Left, SideBarPosition::Right] {
let l = compute_chrome_layout(narrow, true, true, true, pos, 20, 30);
assert!(
l.secondary_side.is_none(),
"{pos:?}: {:?}",
l.secondary_side
);
for r in [l.activity, l.primary_side, Some(l.right)]
.into_iter()
.flatten()
{
assert!(r.right() <= narrow.right(), "{pos:?}: {r:?}");
}
}
}
#[test]
fn chrome_keeps_the_secondary_side_bar_when_it_fits() {
let l = compute_chrome_layout(
main_band(),
true,
false,
true,
SideBarPosition::Left,
20,
30,
);
assert_eq!(l.secondary_side.map(|s| s.width), Some(30));
}
#[test]
fn panel_band_center_and_justify_fill_the_band() {
let band = Rect {
x: 10,
y: 5,
width: 40,
height: 8,
};
assert_eq!(panel_band_rect(band, PanelAlignment::Center), band);
assert_eq!(panel_band_rect(band, PanelAlignment::Justify), band);
}
#[test]
fn panel_band_left_hugs_left_right_hugs_right() {
let band = Rect {
x: 10,
y: 5,
width: 60,
height: 8,
};
let left = panel_band_rect(band, PanelAlignment::Left);
assert_eq!(left.x, 10);
assert_eq!(left.width, 30);
let right = panel_band_rect(band, PanelAlignment::Right);
assert_eq!(
right.x,
10 + 60 - 30,
"right-aligned panel ends at the band's right edge"
);
assert_eq!(right.width, 30);
}
#[test]
fn zen_mode_hides_all_chrome_then_restores_the_snapshot() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.show_tree = true;
app.show_terminal = false;
app.secondary_side_bar_visible = true;
app.activity_bar_visible = true;
app.status_bar_visible = true;
app.toggle_zen_mode();
assert!(app.zen_mode(), "zen on");
assert!(!app.activity_bar_visible);
assert!(!app.status_bar_visible);
assert!(!app.show_tree);
assert!(!app.secondary_side_bar_visible);
assert!(!app.show_terminal);
app.toggle_zen_mode();
assert!(!app.zen_mode(), "zen off");
assert!(app.show_tree, "restored prior side bar");
assert!(!app.show_terminal, "restored prior (hidden) panel");
assert!(
app.secondary_side_bar_visible,
"restored prior secondary bar"
);
assert!(app.activity_bar_visible);
assert!(app.status_bar_visible);
}
fn editor_column(app: &App) -> (u16, u16) {
let text = app.editor.last_full_area;
let strip = if app.minimap.visible && app.minimap.room {
MINIMAP_WIDTH_CELLS
} else {
0
};
(text.x, text.width + strip)
}
#[test]
fn zen_mode_centres_the_editor_in_a_wide_window() {
let (_tmp, mut app) = zen_app();
app.toggle_zen_mode();
draw_screen(&mut app, 200, 30);
assert!(app.minimap.visible && app.minimap.room, "the minimap shows");
assert_eq!(
editor_column(&app),
(40, 120),
"{:?}",
app.editor.last_full_area
);
app.toggle_minimap();
draw_screen(&mut app, 200, 30);
let area = app.editor.last_full_area;
assert_eq!((area.x, area.width), (40, 120), "{area:?}");
app.toggle_minimap();
app.toggle_zen_mode();
draw_screen(&mut app, 200, 30);
assert!(
editor_column(&app).1 > 120,
"out of Zen the editor fills its column again: {:?}",
app.editor.last_full_area
);
}
#[test]
fn toggle_centered_layout_centres_outside_zen_and_uncentres_zen() {
let (_tmp, mut app) = zen_app();
app.show_tree = false;
app.activity_bar_visible = false;
app.show_terminal = false;
app.run_command(crate::widgets::command_palette::Command::ToggleCenteredLayout);
assert!(app.centered_layout);
assert_eq!(app.status, "Centered Layout on");
draw_screen(&mut app, 200, 30);
assert_eq!(editor_column(&app), (40, 120));
app.run_command(crate::widgets::command_palette::Command::ToggleCenteredLayout);
assert!(!app.centered_layout);
app.toggle_zen_mode();
assert!(app.centered_layout_active(), "Zen starts centred");
app.run_command(crate::widgets::command_palette::Command::ToggleCenteredLayout);
assert!(!app.centered_layout_active() && !app.centered_layout);
draw_screen(&mut app, 200, 30);
assert_eq!(editor_column(&app), (0, 200));
let rows = app.customize_layout_items();
assert!(
rows.iter().any(|r| matches!(r, MenuEntry::Item { label, action: MenuAction::ToggleCenteredLayout, .. } if label.contains("Centered Layout"))),
"the Customize Layout popup has the row"
);
}
#[test]
fn a_narrow_window_or_zen_without_centring_keeps_the_full_width() {
let (_tmp, mut app) = zen_app();
app.toggle_zen_mode();
draw_screen(&mut app, 110, 30);
assert_eq!(editor_column(&app), (0, 110));
app.toggle_zen_mode();
app.zen_center_layout = false;
app.toggle_zen_mode();
draw_screen(&mut app, 200, 30);
assert_eq!(editor_column(&app), (0, 200));
assert_eq!(
centered_editor_rect(Rect::new(5, 1, 50, 9), 0),
Rect::new(5, 1, 50, 9),
"a zero width centres nothing"
);
assert_eq!(
centered_editor_rect(Rect::new(5, 1, 51, 9), 20),
Rect::new(20, 1, 20, 9)
);
}
#[test]
fn esc_esc_leaves_zen_mode_and_restores_the_chrome() {
let (_tmp, mut app) = zen_app();
app.show_tree = true;
app.status_bar_visible = true;
app.toggle_zen_mode();
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
assert!(app.zen_mode(), "one Esc is not enough");
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
assert!(!app.zen_mode(), "Esc Esc leaves Zen");
assert!(app.show_tree && app.status_bar_visible);
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
assert!(!app.zen_mode(), "Esc Esc never enters Zen");
}
#[test]
fn entering_zen_says_how_to_leave_it_for_a_while() {
let (_tmp, mut app) = zen_app();
assert!(!draw_screen(&mut app, 120, 30).contains("Esc Esc to exit"));
app.toggle_zen_mode();
assert!(draw_screen(&mut app, 120, 30).contains(zen_hint_text()));
assert!(!app.expire_zen_hint(std::time::Instant::now()), "not yet");
assert!(app.expire_zen_hint(std::time::Instant::now() + ZEN_HINT_FOR));
assert!(!draw_screen(&mut app, 120, 30).contains("Esc Esc to exit"));
app.toggle_zen_mode();
app.toggle_zen_mode();
app.toggle_zen_mode();
assert!(
app.zen_hint_until.is_none(),
"leaving Zen drops a hint still showing"
);
}
#[test]
fn secondary_side_bar_toggle_flips_visibility() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let before = app.secondary_side_bar_visible;
app.toggle_secondary_side_bar();
assert_eq!(app.secondary_side_bar_visible, !before);
}
#[test]
fn customize_layout_items_reflect_current_state_with_checks() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.activity_bar_visible = true;
app.status_bar_visible = false;
app.side_bar_position = SideBarPosition::Right;
app.panel_alignment = PanelAlignment::Justify;
let items = app.customize_layout_items();
let activity = menu_label(&items[0]);
assert!(
activity.starts_with('\u{2713}'),
"Activity Bar checked: {activity}"
);
let status = menu_label(&items[4]);
assert!(
!status.starts_with('\u{2713}'),
"Status Bar unchecked: {status}"
);
let labels = menu_labels(&items);
assert!(
labels
.iter()
.any(|l| l.starts_with('\u{2713}') && l.contains("Right")),
"side-bar Right is checked"
);
assert!(
labels
.iter()
.any(|l| l.starts_with('\u{2713}') && l.contains("Justify")),
"panel Justify is checked"
);
}
#[test]
fn render_survives_every_customize_layout_combination() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let aligns = [
PanelAlignment::Left,
PanelAlignment::Center,
PanelAlignment::Right,
PanelAlignment::Justify,
];
for &pos in &[SideBarPosition::Left, SideBarPosition::Right] {
for &activity in &[true, false] {
for &secondary in &[true, false] {
for &status in &[true, false] {
for &align in &aligns {
app.side_bar_position = pos;
app.activity_bar_visible = activity;
app.secondary_side_bar_visible = secondary;
app.status_bar_visible = status;
app.panel_alignment = align;
for size in [(120u16, 40u16), (40, 12)] {
let backend = ratatui::backend::TestBackend::new(size.0, size.1);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).expect("render must not panic");
}
}
}
}
}
}
app.toggle_zen_mode();
let backend = ratatui::backend::TestBackend::new(30, 8);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f))
.expect("zen render must not panic");
}
#[test]
fn layout_toolbar_emits_2x_inline_images_reflecting_on_off_state() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let mut imgs = dummy_activity_images();
imgs.layout_sidebar_on = "SIDE_ON".into();
imgs.layout_sidebar_on_hover = "SIDE_ON_H".into();
imgs.layout_sidebar_off = "SIDE_OFF".into();
imgs.layout_panel_on = "PANEL_ON".into();
imgs.layout_panel_off = "PANEL_OFF".into();
imgs.layout_customize = "CUSTOMIZE".into();
imgs.layout_customize_hover = "CUSTOMIZE_H".into();
app.overlays.activity.set_images(imgs);
app.sidebar_areas = SidebarAreas::default();
app.layout_icon_areas = LayoutIconAreas {
toggle_side_bar: Rect::new(50, 0, LAYOUT_ICON_CELLS_W, LAYOUT_ICON_CELLS_H),
toggle_panel: Rect::new(55, 0, LAYOUT_ICON_CELLS_W, LAYOUT_ICON_CELLS_H),
customize: Rect::new(60, 0, LAYOUT_ICON_CELLS_W, LAYOUT_ICON_CELLS_H),
};
app.show_tree = true;
app.show_terminal = false;
app.pointer_cell = None;
let overlays = app.pending_activity_image_overlays();
assert!(
overlays
.iter()
.any(|(pos, s)| *pos == (50, 0) && *s == "SIDE_ON"),
"side-bar icon emits the ON image when shown"
);
assert!(
overlays
.iter()
.any(|(pos, s)| *pos == (55, 0) && *s == "PANEL_OFF"),
"panel icon emits the OFF image when hidden"
);
assert!(
overlays
.iter()
.any(|(pos, s)| *pos == (60, 0) && *s == "CUSTOMIZE"),
"customize icon always emits its image"
);
app.pointer_cell = Some((61, 0));
let overlays = app.pending_activity_image_overlays();
assert!(
overlays
.iter()
.any(|(pos, s)| *pos == (60, 0) && *s == "CUSTOMIZE_H"),
"customize icon emits the hover image under the pointer"
);
assert!(
overlays
.iter()
.any(|(pos, s)| *pos == (50, 0) && *s == "SIDE_ON"),
"a non-hovered icon keeps its resting image"
);
app.pointer_cell = Some((51, 0));
let overlays = app.pending_activity_image_overlays();
assert!(
overlays
.iter()
.any(|(pos, s)| *pos == (50, 0) && *s == "SIDE_ON_H"),
"side-bar icon emits the ON hover image under the pointer"
);
app.pointer_cell = None;
app.show_tree = false;
app.show_terminal = true;
let overlays = app.pending_activity_image_overlays();
assert!(
overlays
.iter()
.any(|(p, s)| *p == (50, 0) && *s == "SIDE_OFF")
);
assert!(
overlays
.iter()
.any(|(p, s)| *p == (55, 0) && *s == "PANEL_ON")
);
}
#[test]
fn clicking_the_customize_icon_opens_the_customize_layout_popup() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let cust = app.layout_icon_areas.customize;
assert!(cust.width > 0, "the customize icon must be laid out");
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Down(MouseButton::Left),
column: cust.x,
row: cust.y,
modifiers: KeyModifiers::NONE,
});
let menu = app.context_menu.as_ref().expect("customize popup opens");
assert!(
matches!(
menu.items.first(),
Some(MenuEntry::Item {
action: MenuAction::ToggleActivityBar,
..
})
),
"the popup is the Customize Layout menu"
);
assert_eq!(app.ui_tooltip_at(cust.x, cust.y), Some("Customize Layout"));
}
#[test]
fn clicking_the_side_bar_icon_toggles_the_primary_side_bar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let side = app.layout_icon_areas.toggle_side_bar;
assert!(side.width > 0);
let before = app.show_tree;
app.handle_mouse(crossterm::event::MouseEvent {
kind: crossterm::event::MouseEventKind::Down(MouseButton::Left),
column: side.x,
row: side.y,
modifiers: KeyModifiers::NONE,
});
assert_eq!(app.show_tree, !before, "the side-bar icon flips show_tree");
}
#[test]
fn clicking_the_open_views_activity_icon_collapses_then_reopens_the_side_bar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
draw(&mut app, 120, 40);
let explorer = app.sidebar_areas.activity_icons[ActivityIcon::Explorer];
assert!(app.show_tree && app.sidebar_view == SidebarView::Explorer);
app.focus_pane(Pane::Tree);
left_click(&mut app, explorer.x, explorer.y);
assert!(
!app.show_tree,
"the open view's icon collapses the side bar"
);
assert!(
app.focus == Pane::Editor,
"focus leaves the hidden side bar"
);
draw(&mut app, 120, 40);
left_click(&mut app, explorer.x, explorer.y);
assert!(app.show_tree, "the next click expands it again");
assert_eq!(app.sidebar_view, SidebarView::Explorer);
assert!(app.focus == Pane::Tree);
}
#[test]
fn clicking_another_views_activity_icon_switches_and_expands_a_collapsed_side_bar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
draw(&mut app, 120, 40);
let explorer = app.sidebar_areas.activity_icons[ActivityIcon::Explorer];
let search = app.sidebar_areas.activity_icons[ActivityIcon::Search];
left_click(&mut app, search.x, search.y);
assert!(
app.show_tree,
"another view's icon switches, never collapses"
);
assert_eq!(app.sidebar_view, SidebarView::Search);
left_click(&mut app, search.x, search.y);
assert!(!app.show_tree);
left_click(&mut app, explorer.x, explorer.y);
assert!(
app.show_tree,
"any view's icon expands a collapsed side bar"
);
assert_eq!(app.sidebar_view, SidebarView::Explorer);
}
#[test]
fn collapsing_the_side_bar_from_its_icon_keeps_a_maximized_terminal() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
draw(&mut app, 120, 40);
let explorer = app.sidebar_areas.activity_icons[ActivityIcon::Explorer];
app.show_terminal = true;
app.terminal_maximized = true;
app.focus_pane(Pane::Tree);
left_click(&mut app, explorer.x, explorer.y);
assert!(!app.show_tree);
assert!(app.focus == Pane::Terminal);
assert!(app.terminal_maximized, "the terminal stays maximized");
}
#[test]
fn secondary_sidebar_chord_is_alt_cmd_b_not_plain_cmd_b() {
assert!(is_secondary_sidebar_toggle_key(key(
KeyCode::Char('b'),
KeyModifiers::SUPER | KeyModifiers::ALT
)));
assert!(!is_secondary_sidebar_toggle_key(key(
KeyCode::Char('b'),
KeyModifiers::SUPER
)));
assert!(!is_sidebar_toggle_key(key(
KeyCode::Char('b'),
KeyModifiers::SUPER | KeyModifiers::ALT
)));
}
#[test]
fn resize_must_force_a_full_text_repaint_on_every_protocol() {
use crate::iterm2_inline::InlineImageProtocol;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.inline_protocol = InlineImageProtocol::Kitty;
assert!(
!app.consume_resize_repaint(),
"no repaint owed before any resize"
);
app.on_resize();
assert!(
app.consume_resize_repaint(),
"a WINCH must force the full text repaint even where image eviction skips the wipe"
);
assert!(
!app.consume_resize_repaint(),
"the resize repaint latch is one-shot"
);
}
#[test]
fn a_failed_spawner_releases_the_lock_so_another_window_can_host() {
use std::time::{Duration, Instant};
let tmp = tempfile::tempdir().unwrap();
let socket = tmp.path().join("collab.sock");
let lock_path = tmp.path().join("host.lock");
{
let s = socket.clone();
std::thread::spawn(move || {
let _ = crate::collab::relay_serve(&s);
});
}
let deadline = Instant::now() + Duration::from_secs(5);
while !crate::session::is_alive(&socket) {
assert!(Instant::now() < deadline, "relay never came up");
std::thread::sleep(Duration::from_millis(10));
}
let record = crate::session::PairRecord {
model: None,
name: "nav".into(),
enabled: true,
task: None,
provider: None,
base_url: None,
};
let mut a = App::new(tmp.path().to_path_buf()).unwrap();
a.pair.record_path = tmp.path().join("a.pair.json");
a.pair.socket = socket.clone();
a.pair.host_lock_path = lock_path.clone();
a.pair.spawn_override = Some(Box::new(|_| anyhow::bail!("claude is broken")));
crate::session::write_pair_record(&a.pair.record_path, &record).unwrap();
a.pair.last_check = None;
a.maybe_seat_navigator();
assert!(a.pair.host.is_none());
assert!(
a.pair.navigator_down,
"the failure latches, no 1s retry storm"
);
assert!(
a.pair.host_lock.is_none(),
"a window that cannot host must release the lock"
);
assert!(
a.collab.config.is_none(),
"the same-tick self-appointment is undone with it"
);
let mut b = App::new(tmp.path().to_path_buf()).unwrap();
b.pair.record_path = tmp.path().join("b.pair.json");
b.pair.socket = socket.clone();
b.pair.host_lock_path = lock_path.clone();
b.pair.spawn_override = Some(Box::new(local_test_spawn));
crate::session::write_pair_record(&b.pair.record_path, &record).unwrap();
b.pair.last_check = None;
b.maybe_seat_navigator();
assert!(
b.pair.host.is_some(),
"the working window must be able to host: {}",
b.status
);
}
#[test]
fn status_elision_never_fires_on_a_message_that_fits() {
let tmp = tempfile::tempdir().unwrap();
let git = |args: &[&str]| git_succeeds(tmp.path(), args);
git_init(tmp.path());
std::fs::write(tmp.path().join("a.txt"), "x\n").unwrap();
git(&["add", "-A"]);
git(&["commit", "-qm", "init"]);
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
while std::time::Instant::now() < deadline {
let _ = app.drain_git_responses();
if app.git.status().branch.is_some() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(50));
}
app.status = String::from("Quick select: type a label to copy, UPPERCASE pastes, Esc cancels");
let backend = ratatui::backend::TestBackend::new(153, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let buf = term.backend().buffer().clone();
let a = buf.area;
let last_row: String = (a.x..a.x + a.width)
.map(|x| buf[(x, a.y + a.height - 1)].symbol().to_string())
.collect();
assert!(
last_row.contains(app.status.as_str()),
"a transient that fits beside the right cluster must paint verbatim, \
not elide; the bar showed: {last_row:?}"
);
}
#[test]
fn auto_hide_collapses_on_editor_focus_and_deliberate_actions_restore_it() {
let tmp = tempfile::tempdir().unwrap();
std::fs::write(tmp.path().join("a.rs"), "fn main() {}\n").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
app.focus_pane(Pane::Editor);
assert!(
app.tick_sidebar_auto_hide_at(
std::time::Instant::now() + crate::app::sidebar_dwell::AUTO_HIDE_DWELL
),
"the grace delay elapses and the collapse fires"
);
assert!(!app.show_tree, "focusing the editor collapses the sidebar");
app.set_sidebar_view(SidebarView::Search);
assert!(app.show_tree, "choosing a view reveals the sidebar");
assert!(app.focus == Pane::Tree, "and puts focus in it");
assert!(
!app.sidebar_pinned_open,
"focus landed in the sidebar, so the pin has done its job"
);
app.focus_pane(Pane::Editor);
assert!(
app.tick_sidebar_auto_hide_at(
std::time::Instant::now() + crate::app::sidebar_dwell::AUTO_HIDE_DWELL
),
"the collapse fires after the delay"
);
assert!(!app.show_tree, "leaving collapses it again");
app.set_sidebar_view(SidebarView::Explorer);
app.focus_pane(Pane::Tree);
app.focus_pane(Pane::Terminal);
assert!(
app.tick_sidebar_auto_hide_at(
std::time::Instant::now() + crate::app::sidebar_dwell::AUTO_HIDE_DWELL
),
"and for a terminal too"
);
assert!(!app.show_tree, "a terminal is also 'not the sidebar'");
}
#[test]
fn auto_hide_is_suppressed_while_dragging_prompting_or_in_zen_mode() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(app.sidebar_auto_hide_allowed());
app.gesture = Some(Gesture::Splitter(SplitterDrag::Sidebar));
assert!(!app.sidebar_auto_hide_allowed(), "a drag suppresses it");
app.focus_pane(Pane::Editor);
assert!(
!app.tick_sidebar_auto_hide_at(std::time::Instant::now() + AUTO_HIDE_DWELL),
"the drag suppresses the collapse even once the window elapses"
);
assert!(app.show_tree, "and the sidebar survives the drag");
app.gesture = None;
app.pre_zen = Some(PreZenLayout::default());
assert!(!app.sidebar_auto_hide_allowed(), "zen mode wins");
app.pre_zen = None;
app.sidebar_auto_hide = false;
assert!(!app.sidebar_auto_hide_allowed());
app.focus_pane(Pane::Editor);
assert!(app.show_tree, "opt-in only");
}
#[test]
fn customize_layout_toggle_rows_keep_their_reopen_indices() {
let tmp = tempfile::tempdir().unwrap();
let app = App::new(tmp.path().to_path_buf()).unwrap();
let items = app.customize_layout_items();
let label = |i: usize| match &items[i] {
MenuEntry::Item { label, .. } => label.clone(),
_ => panic!("row {i} is not an item"),
};
assert!(label(0).contains("Activity Bar"));
assert!(label(1).contains("Primary Side Bar"));
assert!(label(2).contains("Secondary Side Bar"));
assert!(label(3).contains("Panel"));
assert!(label(4).contains("Status Bar"));
assert!(label(5).contains("Minimap"));
assert!(
label(6).contains("Auto-Hide Side Bar"),
"the new row is appended, not inserted"
);
}
#[test]
fn both_auto_hide_toggle_routes_agree() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
assert!(!app.sidebar_auto_hide, "off by default");
app.toggle_sidebar_auto_hide();
assert!(app.sidebar_auto_hide);
assert!(
app.status.contains("on"),
"the toggle reports its new state: {}",
app.status
);
app.toggle_sidebar_auto_hide();
assert!(!app.sidebar_auto_hide);
assert!(
app.status.contains("off"),
"and reports off: {}",
app.status
);
}
#[test]
fn the_real_cmd_b_keypress_reveals_and_holds_the_sidebar() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = false;
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::SUPER))
.unwrap();
assert!(app.show_tree, "Cmd+B reveals the sidebar");
let dwell = crate::app::sidebar_dwell::AUTO_HIDE_DWELL;
app.focus_pane(Pane::Editor);
app.tick_sidebar_auto_hide_at(std::time::Instant::now() + dwell);
assert!(
app.show_tree,
"and the reveal survives the next move to the editor"
);
app.focus_pane(Pane::Tree);
app.focus_pane(Pane::Editor);
app.tick_sidebar_auto_hide_at(std::time::Instant::now() + dwell);
assert!(!app.show_tree, "the exemption was consumed, not sticky");
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::CONTROL))
.unwrap();
assert!(app.show_tree);
app.focus_pane(Pane::Editor);
app.tick_sidebar_auto_hide_at(std::time::Instant::now() + dwell);
assert!(app.show_tree, "Ctrl+B pins exactly as Cmd+B does");
}
#[test]
fn a_reveal_while_auto_hide_is_off_does_not_bank_an_exemption() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = false;
app.show_tree = false;
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::SUPER))
.unwrap();
assert!(app.show_tree);
assert!(
!app.sidebar_pinned_open,
"no pin is banked while the feature is off"
);
app.sidebar_auto_hide = true;
app.focus_pane(Pane::Editor);
assert!(
app.tick_sidebar_auto_hide_at(
std::time::Instant::now() + crate::app::sidebar_dwell::AUTO_HIDE_DWELL
),
"the collapse fires"
);
assert!(
!app.show_tree,
"so the first collapse after enabling it actually happens"
);
}
#[test]
fn the_reveal_exemption_is_consumed_rather_than_sticky() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
app.sidebar_pinned_open = true;
app.focus_pane(Pane::Editor);
let t0 = std::time::Instant::now();
let fired = app.tick_sidebar_auto_hide_at(t0 + crate::app::sidebar_dwell::AUTO_HIDE_DWELL);
assert!(!fired, "the exemption protects this collapse");
assert!(app.show_tree, "so the sidebar is still up");
assert!(
!app.sidebar_pinned_open,
"and is consumed rather than latching auto-hide off"
);
app.focus_pane(Pane::Editor);
let t1 = std::time::Instant::now();
assert!(
app.tick_sidebar_auto_hide_at(t1 + crate::app::sidebar_dwell::AUTO_HIDE_DWELL),
"auto-hide is live again"
);
assert!(!app.show_tree, "and the sidebar went down");
}
#[test]
fn auto_hide_yields_to_real_modal_overlays_and_explorer_drags() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(app.sidebar_auto_hide_allowed(), "baseline collapses");
app.command_palette = Some(crate::widgets::command_palette::CommandPalette::new());
assert!(
!app.sidebar_auto_hide_allowed(),
"a modal overlay suppresses the collapse"
);
app.command_palette = None;
app.activity_bar_visible = false;
assert!(
!app.sidebar_auto_hide_allowed(),
"no reveal affordance means no auto-hide"
);
app.activity_bar_visible = true;
app.without_auto_hide(|a| a.focus_pane(Pane::Editor));
assert!(
!app.tick_sidebar_auto_hide_at(std::time::Instant::now() + AUTO_HIDE_DWELL),
"a programmatic focus move must not collapse, even after the delay"
);
assert!(app.show_tree, "programmatic focus leaves the sidebar alone");
}
#[test]
fn a_click_passing_through_the_sidebar_does_not_collapse_it() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: nothing is suppressing auto-hide, so a collapse is live"
);
app.focus_pane(Pane::Editor);
assert!(
app.show_tree,
"the sidebar stays up for the length of the grace delay"
);
app.focus_pane(Pane::Tree);
assert!(
app.show_tree,
"a click through the panel leaves it exactly where it was"
);
assert!(
!app.sidebar_dwell.armed(),
"the return to the sidebar cancelled the pending collapse outright"
);
assert!(
!app.tick_sidebar_auto_hide_at(std::time::Instant::now() + AUTO_HIDE_DWELL),
"no collapse after the deadline"
);
assert!(
app.show_tree,
"so the panel is still up after the window closes"
);
}
#[test]
fn leaving_the_sidebar_arms_a_collapse_rather_than_doing_it_immediately() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is possible here"
);
app.focus_pane(Pane::Editor);
assert!(app.show_tree, "not collapsed on the focus change itself");
let armed_at = std::time::Instant::now();
app.focus_pane(Pane::Terminal);
app.focus_pane(Pane::Editor);
assert!(app.show_tree, "still up while the window is open");
assert!(
app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL),
"the hops did not push the deadline out — it fires on the original one"
);
assert!(!app.show_tree, "and the collapse actually happened");
}
#[test]
fn arming_a_collapse_does_not_consume_the_reveal_pin() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: without the pin, this focus move would collapse"
);
app.sidebar_pinned_open = true;
app.focus_pane(Pane::Editor);
assert!(
app.sidebar_pinned_open,
"arming a collapse must not spend the exemption — only firing one does"
);
assert!(app.show_tree, "and the sidebar is still up");
}
#[test]
fn a_suppressed_tick_does_not_spend_the_reveal_pin() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: without pin or drag, this focus move would collapse"
);
app.sidebar_pinned_open = true;
app.focus_pane(Pane::Editor);
app.gesture = Some(Gesture::Splitter(SplitterDrag::Sidebar));
assert!(
!app.sidebar_auto_hide_allowed(),
"precondition: the seam drag suppresses the collapse by itself"
);
let now = std::time::Instant::now();
let collapsed = app.tick_sidebar_auto_hide_at(now + AUTO_HIDE_DWELL);
assert!(!collapsed, "the drag suppressed this collapse");
assert!(app.show_tree, "so the sidebar is still up");
assert!(
app.sidebar_pinned_open,
"a collapse stopped by an unrelated suppression must not spend the \
one-shot exemption — the user never saw the collapse it was banked for"
);
app.gesture = None;
app.focus_pane(Pane::Terminal);
let pinned_collapse = app.tick_sidebar_auto_hide_at(now + AUTO_HIDE_DWELL * 2);
assert!(!pinned_collapse, "the pin exempts this one");
assert!(app.show_tree, "so the sidebar survives it");
assert!(
!app.sidebar_pinned_open,
"and NOW the exemption is spent — it was banked for exactly this"
);
app.focus_pane(Pane::Editor);
let unpinned_collapse = app.tick_sidebar_auto_hide_at(now + AUTO_HIDE_DWELL * 3);
assert!(
unpinned_collapse,
"with the exemption spent, the next collapse fires — a pin that can \
never be spent is a sidebar that can never auto-hide"
);
assert!(!app.show_tree, "and the sidebar is finally down");
}
#[test]
fn a_reveal_under_zen_mode_banks_no_pin() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = false;
app.toggle_side_bar();
assert!(
app.sidebar_pinned_open,
"precondition: a normal reveal banks the one-shot pin"
);
app.toggle_side_bar();
app.pre_zen = Some(PreZenLayout::default());
app.activity_bar_visible = false;
app.toggle_side_bar();
assert!(app.show_tree, "the reveal still shows the sidebar");
assert!(
!app.sidebar_pinned_open,
"but banks no pin: nothing can spend it until Zen exits, and a pin \
held that long eats a collapse the user never connected to it"
);
}
#[test]
fn a_transiently_suppressed_collapse_is_retried_once_the_suppression_lifts() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: nothing is suppressing auto-hide yet"
);
app.focus_pane(Pane::Editor);
let armed_at = std::time::Instant::now();
app.command_palette = Some(crate::widgets::command_palette::CommandPalette::new());
assert!(
!app.sidebar_auto_hide_allowed(),
"precondition: the open palette suppresses the collapse"
);
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 5),
"the palette suppresses this collapse"
);
assert!(app.show_tree, "so the sidebar is still up");
app.command_palette = None;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: with the palette closed the collapse is live again"
);
assert!(
app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 5),
"the collapse the palette deferred must still fire once it closes — \
a transient suppression delays the collapse, it does not cancel it"
);
assert!(!app.show_tree, "and the sidebar is finally down");
}
#[test]
fn toggling_the_auto_hide_setting_drops_a_pending_collapse() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: collapse is live"
);
let armed_at = std::time::Instant::now();
app.focus_pane(Pane::Editor);
assert!(
app.sidebar_dwell.armed(),
"precondition: a collapse is pending"
);
app.toggle_sidebar_auto_hide();
app.toggle_sidebar_auto_hide();
assert!(app.sidebar_auto_hide, "precondition: back on");
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 1000),
"the collapse armed before the setting was touched must not fire"
);
assert!(app.show_tree, "so the sidebar is still up");
}
#[test]
fn hiding_the_activity_bar_drops_a_pending_collapse_and_its_pin() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
app.sidebar_pinned_open = true;
let armed_at = std::time::Instant::now();
app.focus_pane(Pane::Editor);
assert!(
app.sidebar_dwell.armed(),
"precondition: a collapse is pending"
);
let root = app.active_workspace_root();
app.dispatch_menu_action(MenuAction::ToggleActivityBar, root.clone());
assert!(!app.activity_bar_visible, "precondition: the bar is hidden");
app.dispatch_menu_action(MenuAction::ToggleActivityBar, root);
assert!(app.activity_bar_visible, "precondition: the bar is back");
app.context_menu = None;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: nothing else is suppressing the collapse now"
);
assert!(
!app.sidebar_dwell.armed(),
"the activity-bar toggle cancelled the pending collapse"
);
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 1000),
"an idle tick must not collapse after the bar returns"
);
assert!(app.show_tree, "so the sidebar is still up");
assert!(
!app.sidebar_pinned_open,
"and hiding the bar dropped the pin rather than holding an \
unconsumable one across a period where no collapse can fire — the \
same reason `toggle_side_bar` refuses to bank one in that state"
);
let t1 = std::time::Instant::now();
app.focus_pane(Pane::Tree);
app.focus_pane(Pane::Editor);
assert!(
app.tick_sidebar_auto_hide_at(t1 + AUTO_HIDE_DWELL * 2),
"a fresh focus move after the bar returns collapses — no stale pin ate it"
);
}
#[test]
fn a_collapse_does_not_fire_inside_the_grace_window() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is live here"
);
let before = std::time::Instant::now();
app.focus_pane(Pane::Editor);
assert!(
!app.tick_sidebar_auto_hide_at(before + AUTO_HIDE_DWELL / 2),
"a tick INSIDE the grace window must not collapse — this is the delay"
);
assert!(app.show_tree, "so the sidebar is still up mid-window");
assert!(
app.sidebar_dwell.armed(),
"and the collapse is still pending rather than cancelled"
);
assert!(
app.tick_sidebar_auto_hide_at(before + AUTO_HIDE_DWELL * 3),
"once the window elapses the collapse delivers"
);
assert!(!app.show_tree, "and the sidebar is down");
}
#[test]
fn a_manual_reveal_cancels_a_pending_collapse() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is live here"
);
app.focus_pane(Pane::Editor);
let armed_at = std::time::Instant::now();
app.command_palette = Some(crate::widgets::command_palette::CommandPalette::new());
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 5),
"precondition: the palette defers this collapse"
);
app.command_palette = None;
app.toggle_side_bar();
app.toggle_side_bar();
assert!(
app.show_tree && app.sidebar_pinned_open,
"precondition: the manual reveal banked a one-shot pin"
);
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 6),
"an idle tick must not collapse a sidebar the user just revealed"
);
assert!(
app.sidebar_pinned_open,
"and must not spend the pin on a collapse the user never saw"
);
app.focus_pane(Pane::Editor);
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 20),
"the reveal survives the next focus move, as #294 guarantees"
);
assert!(app.show_tree, "the sidebar is still up");
}
#[test]
fn disabling_auto_hide_drops_a_pin_banked_before_it_was_turned_off() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = false;
app.toggle_side_bar();
assert!(
app.show_tree && app.sidebar_pinned_open,
"precondition: the reveal banked a pin while the feature was on"
);
app.toggle_sidebar_auto_hide();
assert!(!app.sidebar_auto_hide, "precondition: the feature is off");
assert!(
!app.sidebar_pinned_open,
"turning the feature off drops the pin: nothing can consume it while \
off, so it would eat the first collapse after re-enabling"
);
app.toggle_sidebar_auto_hide();
assert!(app.sidebar_auto_hide, "precondition: back on");
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is live again"
);
let t0 = std::time::Instant::now();
app.focus_pane(Pane::Editor);
assert!(
app.tick_sidebar_auto_hide_at(t0 + AUTO_HIDE_DWELL * 2),
"and the first collapse after re-enabling fires — no stranded pin ate it"
);
}
#[test]
fn entering_zen_mode_drops_the_reveal_pin_as_well_as_the_dwell() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = false;
app.toggle_side_bar();
assert!(
app.show_tree && app.sidebar_pinned_open,
"precondition: the reveal banked a pin"
);
app.toggle_zen_mode();
assert!(app.zen_mode(), "precondition: Zen is on");
assert!(
!app.sidebar_pinned_open,
"Zen entry drops the pin: no collapse can fire while Zen owns the \
chrome, so a pin held across it is unconsumable and eats the first \
real collapse afterwards"
);
app.toggle_zen_mode();
assert!(
!app.zen_mode() && app.show_tree,
"precondition: Zen off, sidebar back"
);
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is live again"
);
let t0 = std::time::Instant::now();
app.focus_pane(Pane::Editor);
assert!(
app.tick_sidebar_auto_hide_at(t0 + AUTO_HIDE_DWELL * 2),
"and it fires — no stale pin from before Zen absorbed it"
);
}
#[test]
fn entering_zen_mode_cancels_a_pending_collapse_rather_than_deferring_it() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is live here"
);
app.focus_pane(Pane::Editor);
let armed_at = std::time::Instant::now();
app.toggle_zen_mode();
assert!(app.zen_mode(), "precondition: Zen is on");
assert!(!app.show_tree, "precondition: Zen hid the sidebar");
app.toggle_zen_mode();
assert!(!app.zen_mode(), "precondition: Zen is off");
assert!(
app.show_tree,
"precondition: leaving Zen restored the sidebar"
);
assert!(
!app.tick_sidebar_auto_hide_at(armed_at + AUTO_HIDE_DWELL * 1000),
"a collapse armed before Zen must not fire on the frame Zen exits"
);
assert!(app.show_tree, "so the restored sidebar stays up");
}
#[test]
fn arming_inside_zen_mode_does_not_collapse_the_sidebar_when_zen_exits() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = false;
app.toggle_zen_mode();
assert!(app.zen_mode(), "precondition: Zen is on");
assert!(
!app.sidebar_auto_hide_allowed(),
"precondition: Zen structurally suppresses the collapse"
);
app.toggle_side_bar();
assert!(app.show_tree, "precondition: the sidebar is up inside Zen");
assert!(
!app.sidebar_pinned_open,
"precondition: toggle_side_bar already refuses to bank a pin under a \
structural suppression — this test is about the DWELL, which does not"
);
let t0 = std::time::Instant::now();
app.focus_pane(Pane::Editor);
for i in 0..50u32 {
assert!(
!app.tick_sidebar_auto_hide_at(
t0 + AUTO_HIDE_DWELL * 2 + std::time::Duration::from_millis(8 * i as u64)
),
"no collapse fires inside Zen: Zen owns the chrome (tick {i})"
);
}
assert!(
app.sidebar_dwell.armed(),
"and the dwell SURVIVES those ticks. Cancelling on a suppressed tick \
is indistinguishable from refusing to arm — production ticks every \
8ms, so the cancel lands 8ms after the arm, and nothing re-arms once \
a structural suppression lifts"
);
app.toggle_zen_mode();
assert!(!app.zen_mode(), "precondition: Zen is off again");
app.show_tree = true;
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: a collapse is structurally possible again"
);
assert!(
!app.tick_sidebar_auto_hide_at(t0 + AUTO_HIDE_DWELL * 2),
"and no stale collapse fires after Zen exits, for a focus move made \
while Zen was still on"
);
assert!(
app.show_tree,
"the sidebar is still up: the user asked for it and never asked otherwise"
);
let after_zen = t0 + AUTO_HIDE_DWELL * 2 + std::time::Duration::from_millis(8 * 49);
assert!(
app.tick_sidebar_auto_hide_at(after_zen + AUTO_HIDE_DWELL * 2),
"and once the grace period from Zen exit elapses, it does fire: \
retained, not discarded"
);
}
#[test]
fn auto_hide_recovers_after_the_activity_bar_comes_back() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.sidebar_auto_hide = true;
app.show_tree = true;
app.activity_bar_visible = false;
app.focus_pane(Pane::Tree);
assert!(
!app.sidebar_auto_hide_allowed(),
"precondition: a hidden activity bar structurally suppresses the collapse"
);
let t0 = std::time::Instant::now();
app.focus_pane(Pane::Editor);
for i in 0..50u32 {
let t = t0 + AUTO_HIDE_DWELL * 2 + std::time::Duration::from_millis(8 * i as u64);
assert!(
!app.tick_sidebar_auto_hide_at(t),
"no collapse may fire while the bar is hidden (tick {i})"
);
}
assert!(
app.sidebar_dwell.armed(),
"and the dwell SURVIVES them: cancelling on a suppressed tick is what \
strands the feature, because nothing re-arms once the bar returns"
);
assert!(
app.show_tree,
"precondition: still open after 50 suppressed ticks"
);
app.activity_bar_visible = true;
assert!(
app.focus == Pane::Editor,
"precondition: focus never moved, so nothing re-arms by gesture"
);
assert!(
app.sidebar_auto_hide_allowed(),
"precondition: the suppression has lifted"
);
let last_tick = t0 + AUTO_HIDE_DWELL * 2 + std::time::Duration::from_millis(8 * 49);
assert!(
app.tick_sidebar_auto_hide_at(last_tick + AUTO_HIDE_DWELL * 2),
"auto-hide recovers once the bar returns: the pending collapse fires \
rather than the feature staying dead for the session"
);
assert!(!app.show_tree, "and the sidebar actually collapsed");
}
#[test]
fn a_strip_on_the_sidebar_seam_still_unfolds_its_pane() {
for &pos in &[SideBarPosition::Left, SideBarPosition::Right] {
let (_tmp, mut app, mut term) = app_with_terminal_panes(2);
app.side_bar_position = pos;
let idx = match pos {
SideBarPosition::Left => 0,
SideBarPosition::Right => 1,
};
app.toggle_terminal_collapse(idx);
term.draw(|f| app.render(f)).unwrap();
let strip = app.panel_hits.collapsed_strips[idx];
assert_eq!(strip.width, 1, "{pos:?}: pane {idx} is folded to a strip");
let seam = app
.sidebar_splitter_x
.expect("the side bar is shown, so its seam exists");
assert!(
strip.x == seam || strip.x + 1 == seam,
"{pos:?}: precondition - strip x={} must meet the seam at x={seam}",
strip.x
);
app.handle_mouse(mouse(
MouseEventKind::Down(MouseButton::Left),
strip.x,
strip.y + strip.height / 2,
));
assert!(
!app.terminals[idx].collapsed,
"{pos:?}: the strip on the seam is still the way back out"
);
assert!(
!matches!(app.gesture, Some(Gesture::Splitter(_))),
"{pos:?}: a click on a strip is not a sidebar resize"
);
}
}
#[test]
fn ctrl_b_still_toggles_the_side_bar_outside_the_terminal() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.focus_pane(Pane::Editor);
let before = app.show_tree;
app.handle_key(key(KeyCode::Char('b'), KeyModifiers::CONTROL))
.unwrap();
assert_ne!(
app.show_tree, before,
"with the editor focused, Ctrl+B is still croft's"
);
}
#[test]
fn maximize_ignores_the_collapse_flags_and_gives_them_back_on_exit() {
let (_tmp, mut app, mut term) = app_with_terminal_panes(3);
app.toggle_terminal_collapse(2);
app.active_terminal = 0;
app.toggle_terminal_pane_maximize();
term.draw(|f| app.render(f)).unwrap();
assert!(
app.terminals[2].collapsed,
"maximize must not silently clear the folding"
);
assert_eq!(
app.panel_hits
.collapsed_strips
.iter()
.filter(|r| r.width > 0)
.count(),
0,
"but no strip is painted while maximize owns the panel"
);
app.toggle_terminal_pane_maximize();
term.draw(|f| app.render(f)).unwrap();
assert_eq!(
app.panel_hits.collapsed_strips[2].width, 1,
"leaving maximize brings the strip back"
);
}
#[test]
fn leaving_maximize_never_lands_focus_on_a_folded_pane() {
let (_tmp, mut app, mut term) = app_with_terminal_panes(3);
app.toggle_terminal_collapse(2);
app.active_terminal = 0;
app.toggle_terminal_pane_maximize();
term.draw(|f| app.render(f)).unwrap();
app.active_terminal = 2;
app.toggle_terminal_pane_maximize();
assert!(
!app.terminal_pane_maximized,
"precondition: back to the split"
);
assert!(
!app.terminals[app.active_terminal].collapsed,
"leaving maximize must not leave focus on a strip"
);
}
#[test]
fn a_chrome_image_is_sent_only_when_it_could_be_missing() {
use crate::iterm2_inline::InlineImageProtocol;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let at = Rect::new(2, 2, 3, 1);
let mut buf = Buffer::empty(Rect::new(0, 0, 20, 10));
app.inline_protocol = InlineImageProtocol::ITerm2;
assert!(app.chrome_image_due("k", "img", at, &buf), "new");
app.end_chrome_flush();
assert!(
!app.chrome_image_due("k", "img", at, &buf),
"unchanged frame"
);
app.end_chrome_flush();
assert!(app.chrome_image_due("k", "img2", at, &buf), "changed");
assert!(
app.chrome_image_due("k", "img2", Rect::new(3, 2, 3, 1), &buf),
"moved"
);
app.end_chrome_flush();
buf[(2, 2)].set_symbol("x");
assert!(
app.chrome_image_due("k", "img2", Rect::new(3, 2, 3, 1), &buf),
"a neighbour repainted on iTerm2"
);
app.end_chrome_flush();
app.end_chrome_flush();
assert!(
app.chrome_image_due("k", "img2", Rect::new(3, 2, 3, 1), &buf),
"back after a frame hidden"
);
app.end_chrome_flush();
app.inline_protocol = InlineImageProtocol::Kitty;
assert!(app.chrome_image_due("k", "img2", Rect::new(3, 2, 3, 1), &buf));
app.end_chrome_flush();
buf[(2, 3)].set_symbol("y");
assert!(
!app.chrome_image_due("k", "img2", Rect::new(3, 2, 3, 1), &buf),
"Kitty ignores neighbours"
);
}
#[test]
fn every_bottom_panel_tab_is_reachable_from_the_palette() {
use crate::widgets::command_palette::ALL_COMMANDS;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
for tab in BottomPanelTab::ALL {
let cmd = tab.show_command();
assert!(
ALL_COMMANDS.contains(&cmd),
"{cmd:?} (shows {tab:?}) is missing from the palette"
);
app.show_terminal = false;
app.focus_pane(Pane::Editor);
app.bottom_panel_tab = if tab == BottomPanelTab::Terminal {
BottomPanelTab::Problems
} else {
BottomPanelTab::Terminal
};
app.run_command(cmd);
assert_eq!(app.bottom_panel_tab, tab, "{cmd:?}");
assert!(app.show_terminal, "{cmd:?} must reveal the panel");
assert!(
app.focus == Pane::Terminal,
"{cmd:?} must focus the panel so its keys work at once"
);
}
}
#[test]
fn panel_tab_chords_switch_between_problems_output_and_terminal() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let ctrl_shift = KeyModifiers::CONTROL | KeyModifiers::SHIFT;
let cmd_shift = KeyModifiers::SUPER | KeyModifiers::SHIFT;
app.focus_pane(Pane::Editor);
app.handle_key(key(KeyCode::Char('M'), ctrl_shift)).unwrap();
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Problems);
assert!(app.focus == Pane::Terminal);
app.handle_key(key(KeyCode::Char('u'), cmd_shift)).unwrap();
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Output);
app.handle_key(key(KeyCode::Char('T'), cmd_shift)).unwrap();
assert_eq!(
app.bottom_panel_tab,
BottomPanelTab::Terminal,
"Cmd+Shift+T must bring the TERMINAL tab forward"
);
assert!(app.focus == Pane::Terminal);
app.handle_key(key(KeyCode::Char('U'), ctrl_shift)).unwrap();
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Output);
assert!(!is_show_problems_key(key(
KeyCode::Char('m'),
KeyModifiers::CONTROL
)));
assert!(!is_show_output_key(key(
KeyCode::Char('u'),
KeyModifiers::CONTROL
)));
assert!(!is_show_output_key(key(
KeyCode::Char('U'),
cmd_shift | KeyModifiers::ALT
)));
}
#[test]
fn output_select_channel_picks_a_channel_from_the_keyboard() {
use crate::widgets::command_palette::Command;
use crate::widgets::list_picker::ListPurpose;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let channel = "Keyboard Reach 852";
crate::output::push(channel, crate::output::OutputLevel::Info, "hello");
app.run_command(Command::OutputSelectChannel);
let picker = app.list_picker.as_mut().expect("the channel picker opens");
assert_eq!(picker.purpose, ListPurpose::OutputChannel);
for c in "reach 852".chars() {
picker.push_char(c);
}
assert_eq!(picker.visible_count(), 1);
app.confirm_list_picker();
assert_eq!(app.bottom_panel_tab, BottomPanelTab::Output);
assert!(app.focus == Pane::Terminal);
assert_eq!(app.output.selected_name().as_deref(), Some(channel));
}
#[test]
fn pressing_and_dragging_the_output_scrollbar_scrolls_the_log() {
use crossterm::event::{MouseButton, MouseEventKind};
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let channel = "Scrollbar Drag 2848";
for i in 0..200 {
crate::output::push(
channel,
crate::output::OutputLevel::Info,
&format!("log line {i:03}"),
);
}
app.output.sync();
assert!(app.output.select_by_name(channel));
app.bottom_panel_tab = BottomPanelTab::Output;
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let bar = app.output.last_scrollbar;
assert!(
bar.width > 0 && bar.height > 2,
"200 log lines in the panel must draw a scrollbar"
);
let left = app.output.last_area.x;
let top_row = |term: &ratatui::Terminal<ratatui::backend::TestBackend>| {
let buf = term.backend().buffer();
(left..bar.x)
.map(|x| buf[(x, bar.y)].symbol())
.collect::<String>()
};
let opened = top_row(&term);
assert!(
opened.contains("log line") && !opened.contains("log line 000"),
"the log opens on its tail: {opened:?}"
);
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), bar.x, bar.y));
term.draw(|f| app.render(f)).unwrap();
let jumped = top_row(&term);
assert!(
jumped.contains("log line 000"),
"a press on the scrollbar's top must jump the log to its start: {jumped:?}"
);
app.handle_mouse(mouse(
MouseEventKind::Drag(MouseButton::Left),
bar.x,
bar.y + bar.height - 1,
));
term.draw(|f| app.render(f)).unwrap();
assert_eq!(
top_row(&term),
opened,
"dragging the thumb to the track's foot must bring the tail back"
);
app.handle_mouse(mouse(
MouseEventKind::Up(MouseButton::Left),
bar.x,
bar.y + bar.height - 1,
));
assert!(app.gesture.is_none(), "the release ends the drag");
}
#[test]
fn a_press_on_the_output_scrollbar_with_the_channel_list_open_is_the_lists() {
use crossterm::event::{MouseButton, MouseEventKind};
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let channel = "Scrollbar Under List 2848";
for i in 0..200 {
crate::output::push(
channel,
crate::output::OutputLevel::Info,
&format!("log line {i:03}"),
);
}
app.output.sync();
assert!(app.output.select_by_name(channel));
app.bottom_panel_tab = BottomPanelTab::Output;
let backend = ratatui::backend::TestBackend::new(140, 50);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let bar = app.output.last_scrollbar;
assert!(bar.width > 0 && bar.height > 2, "the log draws a scrollbar");
let area = app.output.last_area;
let toolbar: String = {
let buf = term.backend().buffer();
(area.x..area.x + area.width)
.map(|x| buf[(x, area.y)].symbol())
.collect()
};
let at = toolbar
.find(channel)
.expect("the toolbar names the shown channel");
let button_x = area.x + toolbar[..at].chars().count() as u16;
app.handle_mouse(mouse(
MouseEventKind::Down(MouseButton::Left),
button_x,
area.y,
));
app.handle_mouse(mouse(
MouseEventKind::Up(MouseButton::Left),
button_x,
area.y,
));
assert!(
app.output.dropdown_open(),
"the channel button opens the list"
);
term.draw(|f| app.render(f)).unwrap();
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), bar.x, bar.y));
assert!(
!app.output.dropdown_open(),
"a press on the bar's column while the list is open is the list's"
);
assert!(app.gesture.is_none(), "and does not start a scrollbar drag");
app.handle_mouse(mouse(MouseEventKind::Up(MouseButton::Left), bar.x, bar.y));
}
#[test]
fn panel_tab_chords_reach_problems_output_and_terminal_by_key() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let ctrl_shift = KeyModifiers::CONTROL | KeyModifiers::SHIFT;
let cmd_shift = KeyModifiers::SUPER | KeyModifiers::SHIFT;
app.show_terminal = false;
app.bottom_panel_tab = BottomPanelTab::Terminal;
app.focus_pane(Pane::Editor);
app.handle_key(key(KeyCode::Char('M'), ctrl_shift)).unwrap();
assert_eq!(
app.bottom_panel_tab,
BottomPanelTab::Problems,
"Ctrl+Shift+M must show PROBLEMS"
);
assert!(app.show_terminal, "Ctrl+Shift+M must reveal the panel");
assert!(app.focus == Pane::Terminal);
app.handle_key(key(KeyCode::Char('U'), ctrl_shift)).unwrap();
assert_eq!(
app.bottom_panel_tab,
BottomPanelTab::Output,
"Ctrl+Shift+U must show OUTPUT"
);
app.handle_key(key(KeyCode::Char('T'), cmd_shift)).unwrap();
assert_eq!(
app.bottom_panel_tab,
BottomPanelTab::Terminal,
"Cmd+Shift+T must bring TERMINAL forward"
);
assert!(app.focus == Pane::Terminal);
}
#[test]
fn typing_customize_layout_in_the_palette_opens_the_popup() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
open_palette_852(&mut app);
type_keys(&mut app, "customize layout");
app.handle_key(key(KeyCode::Enter, KeyModifiers::NONE))
.unwrap();
let menu = app
.context_menu
.as_ref()
.expect("View: Customize Layout… opens the Customize Layout popup");
assert!(
menu.items.iter().any(|e| matches!(
e,
MenuEntry::Item {
action: MenuAction::ToggleStatusBar,
..
}
)),
"the popup is the Customize Layout one"
);
}
#[test]
fn every_customize_layout_row_has_a_palette_command_that_does_the_same() {
use crate::command_registry::{ALL_COMMANDS, Command, LAYOUT_COMMANDS};
fn command_for(action: &MenuAction) -> Option<Command> {
match action {
MenuAction::ToggleActivityBar => Some(Command::ToggleActivityBar),
MenuAction::ToggleSideBar => Some(Command::ToggleSideBar),
MenuAction::ToggleSecondarySideBar => Some(Command::ToggleSecondarySideBar),
MenuAction::TogglePanel => Some(Command::ToggleTerminal),
MenuAction::ToggleStatusBar => Some(Command::ToggleStatusBar),
MenuAction::ToggleMinimap => Some(Command::ToggleMinimap),
MenuAction::ToggleAutoHideSideBar => Some(Command::ToggleAutoHideSideBar),
MenuAction::SetSideBarPosition(_) => Some(Command::ToggleSideBarPosition),
MenuAction::SetPanelAlignment(_) => Some(Command::SetPanelAlignment),
MenuAction::SetQuickInputPosition(_) => Some(Command::SetQuickInputPosition),
MenuAction::ToggleZenMode => Some(Command::ToggleZenMode),
MenuAction::ToggleCenteredLayout => Some(Command::ToggleCenteredLayout),
_ => None,
}
}
fn off_option(app: &mut App, action: &MenuAction) {
match *action {
MenuAction::SetSideBarPosition(p) => {
app.side_bar_position = if p == SideBarPosition::Left {
SideBarPosition::Right
} else {
SideBarPosition::Left
};
}
MenuAction::SetPanelAlignment(al) => {
app.panel_alignment = if al == PanelAlignment::Left {
PanelAlignment::Center
} else {
PanelAlignment::Left
};
}
MenuAction::SetQuickInputPosition(p) => {
app.quick_input_position = if p == QuickInputPosition::Top {
QuickInputPosition::Center
} else {
QuickInputPosition::Top
};
}
_ => {}
}
}
let snapshot = |app: &App| {
(
app.activity_bar_visible,
app.show_tree,
app.secondary_side_bar_visible,
app.show_terminal,
app.status_bar_visible,
app.minimap.visible,
app.sidebar_auto_hide,
app.side_bar_position,
app.panel_alignment,
app.quick_input_position,
app.zen_mode(),
app.centered_layout,
)
};
let tmp = tempfile::tempdir().unwrap();
let rows: Vec<(String, MenuAction)> = App::new(tmp.path().to_path_buf())
.unwrap()
.customize_layout_items()
.into_iter()
.filter_map(|e| match e {
MenuEntry::Item { label, action } => Some((label, action)),
_ => None,
})
.collect();
assert!(rows.len() >= 12, "the popup's rows: {rows:?}");
for (label, action) in rows {
let cmd = command_for(&action)
.unwrap_or_else(|| panic!("Customize Layout row {label:?} has no palette command"));
assert!(ALL_COMMANDS.contains(&cmd), "{cmd:?} is not in the palette");
assert!(
LAYOUT_COMMANDS.contains(&cmd),
"{cmd:?} is not found by the query \"layout\""
);
let mut by_click = App::new(tmp.path().to_path_buf()).unwrap();
let mut by_palette = App::new(tmp.path().to_path_buf()).unwrap();
off_option(&mut by_click, &action);
off_option(&mut by_palette, &action);
assert_eq!(snapshot(&by_click), snapshot(&by_palette), "fixture");
by_click.dispatch_menu_action(action.clone(), tmp.path().to_path_buf());
by_palette.run_command(cmd);
if let Some(picker) = by_palette.list_picker.as_mut() {
let option = label.trim_start_matches('\u{2713}').trim().to_lowercase();
for c in option.chars() {
picker.push_char(c);
}
assert_eq!(picker.visible_count(), 1, "{cmd:?} offers {option:?}");
by_palette.confirm_list_picker();
}
assert_eq!(
snapshot(&by_palette),
snapshot(&by_click),
"{cmd:?} must do what the row {label:?} does"
);
}
}
#[test]
fn dismissing_the_panel_alignment_picker_keeps_the_alignment() {
use crate::widgets::command_palette::Command;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.panel_alignment = PanelAlignment::Right;
app.run_command(Command::SetPanelAlignment);
let picker = app.list_picker.as_ref().expect("the picker opens");
assert_eq!(
picker.selected_row().map(|r| r.id.as_str()),
Some("right"),
"the picker opens on the current alignment"
);
app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
.unwrap();
assert!(app.list_picker.is_none());
assert_eq!(app.panel_alignment, PanelAlignment::Right);
}
#[test]
fn bottom_panel_hover_follows_the_pointer() {
use crate::widgets::ports::PortOrigin;
use crossterm::event::MouseEventKind;
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
for port in [3000, 3001, 3002] {
app.ports
.upsert(port, None, None, PortOrigin::Remote("box".into()));
}
app.bottom_panel_tab = BottomPanelTab::Ports;
draw(&mut app, 140, 50);
let area = app.ports.last_area;
let (x, second, third) = (area.x + 2, area.y + 2, area.y + 3);
let lift = crate::gradient::rgb_color(crate::gradient::POPUP_SEL_BG);
let lit = |app: &mut App, at: Option<(u16, u16)>| {
if let Some((px, py)) = at {
app.handle_mouse(mouse(MouseEventKind::Moved, px, py));
}
let buf = draw_buffer(app, 140, 50);
(buf[(x, second)].bg == lift, buf[(x, third)].bg == lift)
};
assert_eq!(lit(&mut app, Some((x, second))), (true, false));
assert_eq!(
lit(&mut app, Some((x, third))),
(false, true),
"the lift follows the pointer"
);
assert_eq!(
lit(&mut app, Some((x, 2))),
(false, false),
"and leaves with it"
);
}
#[test]
fn the_secondary_side_bar_leaves_the_explorer_outline_s_focus_alone() {
let tmp = tempfile::tempdir().unwrap();
let (mut app, _) = secondary_outline_app(&tmp, 120);
app.set_sidebar_view(SidebarView::Explorer);
let focused = app.theme.scrollbar_thumb_focused();
let thumb_lit = |app: &mut App| {
let buf = draw_buffer(app, 140, 40);
let bar = app.outline.last_scrollbar;
assert!(bar.height > 0, "the Explorer's OUTLINE scrolls");
(bar.y..bar.bottom()).any(|y| buf[(bar.x, y)].bg == focused)
};
assert!(thumb_lit(&mut app), "the Explorer has focus");
app.focus_pane(Pane::Editor);
assert!(!thumb_lit(&mut app), "and then it does not");
}
#[test]
fn the_activity_bar_table_keeps_each_icon_in_its_place() {
use ratatui::layout::Rect;
let bar = Rect::new(0, 3, ACTIVITY_BAR_WIDTH, 40);
let tops: Vec<(ActivityIcon, u16)> = ActivityIcon::ALL
.into_iter()
.filter_map(|icon| {
icon.slot()
.map(|slot| (icon, activity_view_block(bar, slot).y))
})
.collect();
assert_eq!(
tops,
vec![
(ActivityIcon::Explorer, 4),
(ActivityIcon::Search, 6),
(ActivityIcon::SourceControl, 8),
(ActivityIcon::Remote, 12),
(ActivityIcon::RunDebug, 10),
(ActivityIcon::Extensions, 14),
(ActivityIcon::Testing, 16),
(ActivityIcon::CodeQL, 18),
]
);
for (index, icon) in ActivityIcon::ALL.into_iter().enumerate() {
assert_eq!(icon as usize, index, "{icon:?} is stored where it is drawn");
}
}
#[test]
fn every_activity_icon_is_found_under_the_pointer_and_named() {
let tmp = tempfile::tempdir().unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
let backend = ratatui::backend::TestBackend::new(120, 40);
let mut term = ratatui::Terminal::new(backend).unwrap();
term.draw(|f| app.render(f)).unwrap();
let names: Vec<(ActivityIcon, &str)> = ActivityIcon::ALL
.into_iter()
.filter(|&icon| app.sidebar_areas.activity_icons[icon].width > 0)
.map(|icon| {
let block = app.sidebar_areas.activity_icons[icon];
assert_eq!(app.activity_icon_at(block.x, block.y), Some(icon));
(icon, icon.label())
})
.collect();
assert_eq!(
names,
vec![
(ActivityIcon::Explorer, "Explorer"),
(ActivityIcon::Search, "Search"),
(ActivityIcon::SourceControl, "Source Control"),
(ActivityIcon::Remote, "Remote"),
(ActivityIcon::RunDebug, "Run and Debug"),
(ActivityIcon::Extensions, "Extensions"),
(ActivityIcon::Testing, "Testing"),
(ActivityIcon::Sponsor, "Sponsor croft"),
(ActivityIcon::Settings, "Manage"),
],
"CodeQL is not added by default, so it has no block"
);
}
#[test]
fn an_activity_badge_is_built_again_only_when_its_count_changes() {
use ratatui::layout::Rect;
let mut badge = CountBadge::default();
let builds = std::cell::Cell::new(0);
let build = |n: usize| {
builds.set(builds.get() + 1);
Some(format!("BADGE{n}"))
};
assert!(
badge.refresh(3, true, || build(3)),
"a new count changes it"
);
assert!(
!badge.refresh(3, true, || build(3)),
"the same count does not"
);
assert_eq!(builds.get(), 1, "and is not built again");
let icon = Rect::new(0, 4, 4, 2);
let width = crate::iterm2_inline::count_badge_cells_w;
assert_eq!(
badge.placed(icon),
Some((Rect::new(4 - width(3), 5, width(3), 1), "BADGE3")),
"on the icon's bottom row, against its right edge"
);
assert!(badge.refresh(12, true, || build(12)));
assert_eq!(
badge.placed(icon),
Some((Rect::new(4 - width(12), 5, width(12), 1), "BADGE12")),
"as wide as the count needs"
);
badge.invalidate();
assert!(
badge.refresh(12, true, || build(12)),
"new pictures rebuild it"
);
assert_eq!(builds.get(), 3);
assert!(badge.refresh(0, true, || build(0)), "zero changes it");
assert_eq!(badge.placed(icon), None, "and clears the picture");
assert_eq!(builds.get(), 3, "without building one");
assert!(
badge.refresh(5, false, || build(5)),
"without pictures the count still changes"
);
assert_eq!(badge.placed(icon), None, "but no picture is built");
assert_eq!(builds.get(), 3);
}
#[test]
fn the_explorer_badge_goes_out_over_its_icon_after_every_icon() {
let tmp = tempfile::tempdir().unwrap();
let a = tmp.path().join("a.txt");
std::fs::write(&a, "aaa").unwrap();
let mut app = App::new(tmp.path().to_path_buf()).unwrap();
app.auto_save = false;
app.auto_save_on_focus_change = false;
app.format_on_save = false;
app.inline_protocol = crate::iterm2_inline::InlineImageProtocol::Kitty;
app.cell_pixel = Some((8, 16));
app.overlays.activity.set_images(empty_activity_images());
app.editor.open_pinned(&a).unwrap();
app.focus_pane(Pane::Editor);
app.handle_key(key(KeyCode::Char('X'), KeyModifiers::NONE))
.unwrap();
assert_eq!(app.unsaved_count(), 1);
draw(&mut app, 120, 40);
let sent = app.pending_activity_image_overlays();
let explorer = app.sidebar_areas.activity_icons[ActivityIcon::Explorer];
let width = crate::iterm2_inline::count_badge_cells_w(1);
let corner = (
explorer.x + explorer.width - width,
explorer.y + explorer.height - 1,
);
let badge_at = sent
.iter()
.position(|(at, _)| *at == corner)
.expect("the badge goes out at the Explorer icon's bottom-right");
let shown_icons = ActivityIcon::ALL
.into_iter()
.filter(|&icon| app.sidebar_areas.activity_icons[icon].width > 0)
.count();
assert!(
badge_at >= shown_icons,
"after every icon: {badge_at} of {sent:?}"
);
let id = crate::iterm2_inline::KITTY_ID_EXPLORER_BADGE;
assert!(
sent[badge_at].1.contains(&format!("i={id}")),
"built with the Explorer badge's own picture id"
);
}