Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 101 additions & 3 deletions src/features/sessions/input/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,48 @@ mod tests {
assert_eq!(state.session_popup_tab, 0);
}

#[test]
fn movement_traverses_rows_and_group_boundaries() {
let mut state = SessionsState::new();
let mut other_group = group(&["two"]);
other_group.cwd = Some("/other".into());
state.session_groups = vec![group(&["one"]), other_group];

for cursor in [1, 2, 3] {
assert_eq!(
handle_key(&mut state, KeyCode::Down, 1),
SessionPopupInputResult::Moved
);
assert_eq!(state.session_cursor, cursor);
}
for cursor in [2, 1, 0] {
assert_eq!(
handle_key(&mut state, KeyCode::Up, 1),
SessionPopupInputResult::Moved
);
assert_eq!(state.session_cursor, cursor);
}
}

#[test]
fn movement_clamps_at_first_and_last_row() {
let mut state = SessionsState::new();
state.session_groups = vec![group(&["one"])];

assert_eq!(
handle_key(&mut state, KeyCode::Up, 1),
SessionPopupInputResult::Moved
);
assert_eq!(state.session_cursor, 0);

state.session_cursor = 1;
assert_eq!(
handle_key(&mut state, KeyCode::Down, 1),
SessionPopupInputResult::Moved
);
assert_eq!(state.session_cursor, 1);
}

#[test]
fn page_movement_uses_root_supplied_step() {
let mut state = SessionsState::new();
Expand All @@ -204,20 +246,63 @@ mod tests {
assert_eq!(state.session_cursor, 1);
}

#[test]
fn filtering_plain_characters_and_backspace_reset_cursor() {
let mut state = SessionsState::new();
state.session_groups = vec![group(&["one", "two"])];

for (character, expected) in [('x', "x"), ('o', "xo"), ('n', "xon")] {
state.session_cursor = 2;
assert_eq!(
handle_key(&mut state, KeyCode::Char(character), 1),
SessionPopupInputResult::Filtered
);
assert_eq!(state.session_filter, expected);
assert_eq!(state.session_cursor, 0);
}

for expected in ["xo", "x", ""] {
state.session_cursor = 2;
assert_eq!(
handle_key(&mut state, KeyCode::Backspace, 1),
SessionPopupInputResult::Filtered
);
assert_eq!(state.session_filter, expected);
assert_eq!(state.session_cursor, 0);
}

state.session_cursor = 2;
assert_eq!(
handle_key(&mut state, KeyCode::Backspace, 1),
SessionPopupInputResult::Filtered
);
assert!(state.session_filter.is_empty());
assert_eq!(state.session_cursor, 0);
}

#[test]
fn collapse_and_load_more_preserve_popup_semantics() {
let mut state = SessionsState::new();
state.session_groups = vec![group(&["one"])];
state.session_groups[0].next_cursor = Some("next".into());
state.session_groups = vec![group(&["one"]), group(&["two"])];
state.session_cursor = 2;

assert_eq!(
handle_key(&mut state, KeyCode::Enter, 1),
SessionPopupInputResult::ToggledGroup
);
assert!(state.popup_collapsed_groups.contains("/work"));
assert!(!state.collapsed_groups.contains("/work"));
assert_eq!(state.session_cursor, 1);

state.popup_collapsed_groups.clear();
assert_eq!(
handle_key(&mut state, KeyCode::Enter, 1),
SessionPopupInputResult::ToggledGroup
);
assert!(!state.popup_collapsed_groups.contains("/work"));
assert!(!state.collapsed_groups.contains("/work"));

state.session_groups = vec![group(&["one"])];
state.session_groups[0].next_cursor = Some("next".into());
state.session_cursor = 2;
assert_eq!(
handle_key(&mut state, KeyCode::Enter, 1),
Expand Down Expand Up @@ -269,6 +354,19 @@ mod tests {
assert!(state.session_groups.is_empty());
}

#[test]
fn delete_on_header_is_not_handled_and_preserves_projection() {
let mut state = SessionsState::new();
state.session_groups = vec![group(&["one"]), group(&["two"])];
let projection = state.visible_popup_items();

assert_eq!(
handle_key(&mut state, KeyCode::Delete, 1),
SessionPopupInputResult::NotHandled
);
assert_eq!(state.visible_popup_items(), projection);
}

#[test]
fn escape_is_data_only_close_intent() {
let mut state = SessionsState::new();
Expand Down
Loading