Skip to content

Commit

Permalink
scrollbar test, match test to expected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
m12t committed Feb 14, 2025
1 parent 7f6ecca commit 6db0a0c
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl App {
i - 1
}
}
None => 0,
None => return, // do nothing if table_state == None && previous_program() called
};
self.table_state.select(Some(i));
self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll);
Expand Down Expand Up @@ -483,18 +483,23 @@ mod tests {

// Initially no item is selected
assert_eq!(app.selected_program(), None, "expected no program");
assert_eq!(app.vertical_scroll, 0, "expected init with 0, got: {}", app.vertical_scroll);

// After calling next, the first item should be selected
app.next_program();
assert_eq!(app.selected_program(), Some(prog_1.clone()), "expected prog_1");
assert_eq!(app.vertical_scroll, 0, "expected scroll 0, got: {}", app.vertical_scroll);

// After calling next again, the second item should be selected
app.next_program();
assert_eq!(app.selected_program(), Some(prog_2.clone()), "expected prog_2");
assert_eq!(app.vertical_scroll, 1, "expected scroll 1, got: {}", app.vertical_scroll);

// After calling next again, we should wrap around to the first item
// After calling next again, the second item should still be selected without wrapping
app.next_program();
assert_eq!(app.selected_program(), Some(prog_2.clone()), "expected prog_2; no wrap around");
assert_eq!(app.vertical_scroll, 1, "expected scroll 1, got: {}", app.vertical_scroll);

}

#[test]
Expand All @@ -503,10 +508,17 @@ mod tests {

// Initially no item is selected
assert_eq!(app.selected_program(), None);

// Initially ScrollbarState is 0
assert_eq!(app.vertical_scroll_state, ScrollbarState::new(0), "unexpected ScrollbarState");
assert_eq!(app.vertical_scroll, 0, "expected 0 vertical_scroll, got: {}", app.vertical_scroll);

// After calling previous, no item should be selected
app.previous_program();
assert_eq!(app.selected_program(), None);

assert_eq!(app.vertical_scroll_state, ScrollbarState::new(0), "unexpected ScrollbarState");
assert_eq!(app.vertical_scroll, 0, "expected 0 vertical_scroll, got: {}", app.vertical_scroll);
}

#[test]
Expand Down Expand Up @@ -544,18 +556,26 @@ mod tests {

// Initially no item is selected
assert_eq!(app.selected_program(), None, "expected no program");
assert_eq!(app.vertical_scroll, 0, "expected init with 0");

// After calling previous, the last item should be selected
// After calling previous with no table state, nothing should be selected
app.previous_program();
assert_eq!(app.selected_program(), Some(prog_1.clone()), "expected prog_1");
assert_eq!(app.selected_program(), None, "expected None");
assert_eq!(app.vertical_scroll, 0, "still 0, no wrapping");

// After calling previous again, the first item should be selected
// After calling previous again, still nothing should be selected
app.previous_program();
assert_eq!(app.selected_program(), Some(prog_1.clone()), "still prog_1");
assert_eq!(app.selected_program(), None, "still None");
assert_eq!(app.vertical_scroll, 0, "still 0, no wrapping");

app.next_program(); // populate table state and expect prog_1 selected
assert_eq!(app.selected_program(), Some(prog_1.clone()), "expected prog_1");
assert_eq!(app.vertical_scroll, 0, "expected scroll 0");

// After calling previous again, we should wrap around to the last item
// After calling previous again, prog_1 should still be selected (0th index)
app.previous_program();
assert_eq!(app.selected_program(), Some(prog_1.clone()), "still expecting prog_1");
assert_eq!(app.vertical_scroll, 0, "still 0, no wrapping");
}

#[test]
Expand Down

0 comments on commit 6db0a0c

Please sign in to comment.