返回 CodeWhale
dock_tabs_tests.rs
根目录 / crates / tui / src / tui / work_surface / render / dock_tabs_tests.rs
1 use super::*;
2 use codewhale_runtime::config::Config;
3 use ratatui::{Terminal, backend::TestBackend, buffer::Buffer, style::Color};
4 use std::path::PathBuf;
5
6 fn app() -> App {
7 let mut app = App::new(
8 crate::tui::test_support::test_tui_options(PathBuf::from(".")),
9 &Config::default(),
10 );
11 app.ui_locale = codewhale_localization::Locale::En;
12 app.ui_theme.text_body = Color::Rgb(19, 41, 83);
13 app.ui_theme.selection_bg = Color::Rgb(89, 31, 67);
14 app.ui_theme.elevated_bg = Color::Rgb(37, 59, 23);
15 app
16 }
17
18 fn paint(
19 app: &mut App,
20 area: Rect,
21 ) -> (
22 Buffer,
23 Vec<DockTabHitbox>,
24 Vec<crate::tui::tideline::InteractionTarget>,
25 ) {
26 let mut terminal = Terminal::new(TestBackend::new(150, 12)).unwrap();
27 app.viewport.interaction_targets.clear();
28 terminal
29 .draw(|frame| {
30 for cell in &mut frame.buffer_mut().content {
31 cell.set_symbol("~").set_style(
32 Style::default()
33 .fg(Color::Yellow)
34 .bg(Color::Rgb(11, 23, 37))
35 .add_modifier(Modifier::ITALIC),
36 );
37 }
38 render_dock_tabs(frame, area, app);
39 register_dock_targets(app);
40 })
41 .unwrap();
42 (
43 terminal.backend().buffer().clone(),
44 app.work_surface.dock_tabs.clone(),
45 app.viewport.interaction_targets.iter().copied().collect(),
46 )
47 }
48
49 #[test]
50 fn native_dock_zero_viewport_retires_every_painted_target() {
51 let mut app = app();
52 app.work_surface.effective_placement = WorkSurfacePlacement::Top;
53 app.work_surface.panel = RailPanel::Context;
54 assert!(!paint(&mut app, Rect::new(7, 5, 80, 3)).1.is_empty());
55 let actual = paint(&mut app, Rect::new(7, 5, 0, 3));
56 assert!(actual.1.is_empty());
57 assert!(actual.2.is_empty());
58 }
59
60 #[test]
61 fn jobs_tab_counts_one_running_shell_as_one_job() {
62 let mut app = app();
63 app.task_panel.push(crate::tui::app::TaskPanelEntry {
64 exit_code: None,
65 id: "shell_a1b2c3d4".to_string(),
66 status: "running".to_string(),
67 prompt_summary: "shell: ls | head -40".to_string(),
68 duration_ms: Some(34_000),
69 kind: crate::tui::app::TaskPanelEntryKind::Shell,
70 stale: false,
71 elapsed_since_output_ms: None,
72 owner_agent_id: None,
73 owner_agent_name: None,
74 current_tool: None,
75 role: None,
76 files_touched: 0,
77 });
78 // The `▾ Shells 1` heading is a selectable door, not a second job.
79 assert_eq!(dock_tab_count(&mut app, RailPanel::Background), Some(1));
80 }
81
81 lines RUST