返回 CodeWhale
dock_tabs_tests.rs
根目录 / crates / tui / src / tui / work_surface / render / dock_tabs_tests.rs
1 use super::*;
2 use crate::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::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 legacy: bool,
22 ) -> (
23 Buffer,
24 Vec<DockTabHitbox>,
25 Vec<crate::tui::tideline::InteractionTarget>,
26 ) {
27 let mut terminal = Terminal::new(TestBackend::new(150, 12)).unwrap();
28 app.viewport.interaction_targets.clear();
29 terminal
30 .draw(|frame| {
31 for cell in &mut frame.buffer_mut().content {
32 cell.set_symbol("~").set_style(
33 Style::default()
34 .fg(Color::Yellow)
35 .bg(Color::Rgb(11, 23, 37))
36 .add_modifier(Modifier::ITALIC),
37 );
38 }
39 if legacy {
40 super::dock_tabs_legacy::render_dock_tabs(frame, area, app);
41 } else {
42 render_dock_tabs(frame, area, app);
43 }
44 register_dock_targets(app);
45 })
46 .unwrap();
47 (
48 terminal.backend().buffer().clone(),
49 app.work_surface.dock_tabs.clone(),
50 app.viewport.interaction_targets.iter().copied().collect(),
51 )
52 }
53
54 #[test]
55 fn native_dock_tab_buffer_and_typed_actions_match_frozen_renderer() {
56 let mut app = app();
57 for placement in [
58 WorkSurfacePlacement::Top,
59 WorkSurfacePlacement::Bottom,
60 WorkSurfacePlacement::Left,
61 WorkSurfacePlacement::Right,
62 ] {
63 for panel in RailPanel::ORDER {
64 for (focused, explicit) in [(false, false), (true, false), (true, true)] {
65 for interaction in [
66 None,
67 Some(DockTabTarget::Close),
68 Some(DockTabTarget::Panel(RailPanel::Context)),
69 Some(DockTabTarget::Panel(RailPanel::Tasks)),
70 ] {
71 app.work_surface.effective_placement = placement;
72 app.work_surface.panel = panel;
73 app.work_surface.focused = focused;
74 app.work_surface.explicit_view = explicit;
75 app.work_surface.hovered_tab = interaction;
76 app.work_surface.pressed_tab = interaction;
77 for width in [1, 3, 8, 12, 24, 39, 40, 59, 60, 61, 80, 120, 128] {
78 let area = Rect::new(7, 5, width, 3);
79 let expected = paint(&mut app, area, true);
80 let actual = paint(&mut app, area, false);
81 assert_eq!(
82 actual, expected,
83 "placement={placement:?} panel={panel:?} focused={focused} explicit={explicit} interaction={interaction:?} area={area:?}"
84 );
85 }
86 }
87 }
88 }
89 }
90 }
91
92 #[test]
93 fn native_dock_zero_viewport_retires_every_painted_target() {
94 let mut app = app();
95 app.work_surface.effective_placement = WorkSurfacePlacement::Top;
96 app.work_surface.panel = RailPanel::Context;
97 assert!(!paint(&mut app, Rect::new(7, 5, 80, 3), false).1.is_empty());
98 let actual = paint(&mut app, Rect::new(7, 5, 0, 3), false);
99 assert!(actual.1.is_empty());
100 assert!(actual.2.is_empty());
101 }
102
102 lines RUST