use super::*;
#[test]
fn test_new_help_state() {
let state = HelpPopupState::new();
assert!(!state.visible);
assert_eq!(state.active_tab, HelpTab::Global);
assert_eq!(state.current_scroll().offset, 0);
}
#[test]
fn test_help_tab_all() {
let tabs = HelpTab::all();
assert_eq!(tabs.len(), 7);
assert_eq!(tabs[0], HelpTab::Global);
assert_eq!(tabs[6], HelpTab::Snippet);
}
#[test]
fn test_help_tab_index() {
assert_eq!(HelpTab::Global.index(), 0);
assert_eq!(HelpTab::Input.index(), 1);
assert_eq!(HelpTab::Result.index(), 2);
assert_eq!(HelpTab::History.index(), 3);
assert_eq!(HelpTab::AI.index(), 4);
assert_eq!(HelpTab::Search.index(), 5);
assert_eq!(HelpTab::Snippet.index(), 6);
}
#[test]
fn test_help_tab_from_index() {
assert_eq!(HelpTab::from_index(0), HelpTab::Global);
assert_eq!(HelpTab::from_index(1), HelpTab::Input);
assert_eq!(HelpTab::from_index(2), HelpTab::Result);
assert_eq!(HelpTab::from_index(3), HelpTab::History);
assert_eq!(HelpTab::from_index(4), HelpTab::AI);
assert_eq!(HelpTab::from_index(5), HelpTab::Search);
assert_eq!(HelpTab::from_index(6), HelpTab::Snippet);
assert_eq!(HelpTab::from_index(100), HelpTab::Global);
}
#[test]
fn test_help_tab_name() {
assert_eq!(HelpTab::Global.name(), "Global");
assert_eq!(HelpTab::Input.name(), "Input");
assert_eq!(HelpTab::Result.name(), "Result");
assert_eq!(HelpTab::History.name(), "History");
assert_eq!(HelpTab::AI.name(), "AI");
assert_eq!(HelpTab::Search.name(), "Search");
assert_eq!(HelpTab::Snippet.name(), "Snippet");
}
#[test]
fn test_help_tab_next() {
assert_eq!(HelpTab::Global.next(), HelpTab::Input);
assert_eq!(HelpTab::Input.next(), HelpTab::Result);
assert_eq!(HelpTab::Snippet.next(), HelpTab::Global); }
#[test]
fn test_help_tab_prev() {
assert_eq!(HelpTab::Input.prev(), HelpTab::Global);
assert_eq!(HelpTab::Result.prev(), HelpTab::Input);
assert_eq!(HelpTab::Global.prev(), HelpTab::Snippet); }
#[test]
fn test_help_popup_state_current_scroll() {
let mut state = HelpPopupState::new();
state.current_scroll_mut().update_bounds(50, 20);
state.current_scroll_mut().scroll_down(5);
assert_eq!(state.current_scroll().offset, 5);
state.active_tab = HelpTab::Input;
assert_eq!(state.current_scroll().offset, 0);
state.current_scroll_mut().update_bounds(30, 15);
state.current_scroll_mut().scroll_down(3);
assert_eq!(state.current_scroll().offset, 3);
state.active_tab = HelpTab::Global;
assert_eq!(state.current_scroll().offset, 5);
}
#[test]
fn test_help_popup_state_reset() {
let mut state = HelpPopupState::new();
state.visible = true;
state.active_tab = HelpTab::Result;
state.current_scroll_mut().update_bounds(50, 20);
state.current_scroll_mut().scroll_down(10);
state.reset();
assert!(!state.visible);
assert_eq!(state.active_tab, HelpTab::Global);
for tab in HelpTab::all() {
state.active_tab = *tab;
assert_eq!(state.current_scroll().offset, 0);
}
assert_eq!(state.get_hovered_tab(), None);
}
#[test]
fn test_help_popup_hovered_tab() {
let mut state = HelpPopupState::new();
assert_eq!(state.get_hovered_tab(), None);
state.set_hovered_tab(Some(HelpTab::Input));
assert_eq!(state.get_hovered_tab(), Some(HelpTab::Input));
state.set_hovered_tab(Some(HelpTab::AI));
assert_eq!(state.get_hovered_tab(), Some(HelpTab::AI));
state.clear_hovered_tab();
assert_eq!(state.get_hovered_tab(), None);
}
#[test]
fn test_tab_at_x_global_active() {
let state = HelpPopupState::new(); let width = state.tab_bar_width();
assert_eq!(state.tab_at_x(0, width), Some(HelpTab::Global));
assert_eq!(state.tab_at_x(9, width), Some(HelpTab::Global));
assert_eq!(state.tab_at_x(10, width), None);
assert_eq!(state.tab_at_x(12, width), None);
assert_eq!(state.tab_at_x(13, width), Some(HelpTab::Input));
assert_eq!(state.tab_at_x(19, width), Some(HelpTab::Input));
assert_eq!(state.tab_at_x(20, width), None);
assert_eq!(state.tab_at_x(23, width), Some(HelpTab::Result));
}
#[test]
fn test_tab_at_x_input_active() {
let mut state = HelpPopupState::new();
state.active_tab = HelpTab::Input;
let width = state.tab_bar_width();
assert_eq!(state.tab_at_x(0, width), Some(HelpTab::Global));
assert_eq!(state.tab_at_x(7, width), Some(HelpTab::Global));
assert_eq!(state.tab_at_x(8, width), None);
assert_eq!(state.tab_at_x(10, width), None);
assert_eq!(state.tab_at_x(11, width), Some(HelpTab::Input));
assert_eq!(state.tab_at_x(19, width), Some(HelpTab::Input));
}
#[test]
fn test_tab_at_x_out_of_bounds() {
let state = HelpPopupState::new();
let width = state.tab_bar_width();
assert_eq!(state.tab_at_x(200, width), None);
}
#[test]
fn test_tab_at_x_with_centering() {
let state = HelpPopupState::new();
let tab_bar_width = state.tab_bar_width();
let container_width = tab_bar_width + 20;
assert_eq!(state.tab_at_x(0, container_width), None);
assert_eq!(state.tab_at_x(9, container_width), None);
assert_eq!(state.tab_at_x(10, container_width), Some(HelpTab::Global));
assert_eq!(state.tab_at_x(19, container_width), Some(HelpTab::Global));
}