use par_term::config::{Config, TabBarMode};
use par_term::tab_bar_ui::{TabBarAction, TabBarUI};
#[test]
fn test_tab_bar_height_affects_content_area() {
let tab_bar = TabBarUI::new();
let config = Config {
tab_bar_mode: TabBarMode::WhenMultiple,
..Config::default()
};
let height_1_tab = tab_bar.get_height(1, &config);
assert_eq!(height_1_tab, 0.0, "Single tab should hide tab bar");
let height_2_tabs = tab_bar.get_height(2, &config);
assert!(height_2_tabs > 0.0, "Multiple tabs should show tab bar");
assert_eq!(
height_2_tabs, config.tab_bar_height,
"Tab bar height should match config"
);
}
#[test]
fn test_tab_bar_height_zero_tabs() {
let tab_bar = TabBarUI::new();
let config = Config {
tab_bar_mode: TabBarMode::WhenMultiple,
..Config::default()
};
let height = tab_bar.get_height(0, &config);
assert_eq!(height, 0.0, "Zero tabs should hide tab bar");
}
#[test]
fn test_tab_bar_height_many_tabs() {
let tab_bar = TabBarUI::new();
let config = Config::default();
let height_2 = tab_bar.get_height(2, &config);
let height_10 = tab_bar.get_height(10, &config);
let height_100 = tab_bar.get_height(100, &config);
assert_eq!(
height_2, height_10,
"Height should be constant for multiple tabs"
);
assert_eq!(
height_10, height_100,
"Height should be constant regardless of tab count"
);
}
#[test]
fn test_close_action_distinct_from_switch() {
let switch_action = TabBarAction::SwitchTo(5);
let close_action = TabBarAction::Close(5);
assert_ne!(
switch_action, close_action,
"Close and SwitchTo should be different actions"
);
}
#[test]
fn test_close_action_equality() {
let close1 = TabBarAction::Close(1);
let close2 = TabBarAction::Close(1);
let close3 = TabBarAction::Close(2);
assert_eq!(close1, close2, "Same tab close actions should be equal");
assert_ne!(
close1, close3,
"Different tab close actions should be different"
);
}
#[test]
fn test_reorder_action_preserves_target_position() {
let action = TabBarAction::Reorder(3, 0);
match action {
TabBarAction::Reorder(id, pos) => {
assert_eq!(id, 3, "Tab ID should be preserved");
assert_eq!(pos, 0, "Target position should be preserved");
}
_ => panic!("Expected Reorder action"),
}
}
#[test]
fn test_reorder_action_different_positions() {
let action1 = TabBarAction::Reorder(1, 0);
let action2 = TabBarAction::Reorder(1, 2);
assert_ne!(
action1, action2,
"Reorder to different positions should differ"
);
}
#[test]
fn test_reorder_action_different_tabs() {
let action1 = TabBarAction::Reorder(1, 0);
let action2 = TabBarAction::Reorder(2, 0);
assert_ne!(action1, action2, "Reorder of different tabs should differ");
}
#[test]
fn test_close_hovered_state_initialization() {
let tab_bar = TabBarUI::new();
assert!(
tab_bar.close_hovered.is_none(),
"Close button should not be hovered initially"
);
}
#[test]
fn test_hovered_tab_state_initialization() {
let tab_bar = TabBarUI::new();
assert!(
tab_bar.hovered_tab.is_none(),
"No tab should be hovered initially"
);
}
#[test]
fn test_context_menu_initially_closed() {
let tab_bar = TabBarUI::new();
assert!(
!tab_bar.is_context_menu_open(),
"Context menu should be closed initially"
);
}
#[test]
fn test_tab_bar_height_with_very_large_tab_count() {
let tab_bar = TabBarUI::new();
let config = Config::default();
let height = tab_bar.get_height(usize::MAX / 2, &config);
assert!(height >= 0.0, "Height should be non-negative");
}
#[test]
fn test_actions_are_exhaustive() {
let actions: Vec<TabBarAction> = vec![
TabBarAction::None,
TabBarAction::SwitchTo(1),
TabBarAction::Close(1),
TabBarAction::NewTab,
TabBarAction::Reorder(1, 0),
TabBarAction::SetColor(1, [255, 0, 0]),
TabBarAction::ClearColor(1),
];
for action in actions {
let _ = format!("{:?}", action);
}
}
#[test]
fn test_action_none_initialization() {
let action = TabBarAction::None;
assert!(
matches!(action, TabBarAction::None),
"None action should match TabBarAction::None"
);
assert!(!matches!(action, TabBarAction::NewTab));
assert!(!matches!(action, TabBarAction::SwitchTo(_)));
assert!(!matches!(action, TabBarAction::Close(_)));
}
#[test]
fn test_keyboard_focus_prevention_documented() {
let action = TabBarAction::SwitchTo(1);
assert!(matches!(action, TabBarAction::SwitchTo(1)));
}
#[test]
fn test_tab_renumbering_documented() {
let action = TabBarAction::Reorder(1, 0);
assert!(matches!(action, TabBarAction::Reorder(1, 0)));
}
#[test]
fn test_content_offset_documented() {
let tab_bar = TabBarUI::new();
let config = Config::default();
let height = tab_bar.get_height(2, &config);
assert!(
height > 0.0,
"Tab bar height should be positive when visible"
);
}
#[test]
fn test_mouse_event_timing_documented() {
let tab_bar = TabBarUI::new();
let config = Config {
tab_bar_mode: TabBarMode::WhenMultiple,
..Config::default()
};
let height_1 = tab_bar.get_height(1, &config);
assert_eq!(height_1, 0.0, "No tab bar with 1 tab");
let height_2 = tab_bar.get_height(2, &config);
assert!(height_2 > 0.0, "Tab bar exists with 2+ tabs");
}
#[test]
fn test_should_show_with_always_mode() {
use par_term::config::TabBarMode;
let tab_bar = TabBarUI::new();
assert!(tab_bar.should_show(0, TabBarMode::Always));
assert!(tab_bar.should_show(1, TabBarMode::Always));
assert!(tab_bar.should_show(2, TabBarMode::Always));
}
#[test]
fn test_should_show_with_when_multiple_mode() {
use par_term::config::TabBarMode;
let tab_bar = TabBarUI::new();
assert!(!tab_bar.should_show(0, TabBarMode::WhenMultiple));
assert!(!tab_bar.should_show(1, TabBarMode::WhenMultiple));
assert!(tab_bar.should_show(2, TabBarMode::WhenMultiple));
assert!(tab_bar.should_show(10, TabBarMode::WhenMultiple));
}
#[test]
fn test_should_show_with_never_mode() {
use par_term::config::TabBarMode;
let tab_bar = TabBarUI::new();
assert!(!tab_bar.should_show(0, TabBarMode::Never));
assert!(!tab_bar.should_show(1, TabBarMode::Never));
assert!(!tab_bar.should_show(2, TabBarMode::Never));
assert!(!tab_bar.should_show(100, TabBarMode::Never));
}
#[test]
#[ignore] fn test_tab_numbering_on_creation() {
}
#[test]
#[ignore] fn test_tab_renumbering_on_close() {
}
#[test]
#[ignore] fn test_tab_renumbering_on_reorder() {
}
#[test]
#[ignore] fn test_custom_titled_tabs_not_renumbered() {
}