in src/app.rs [525:579]
fn test_previous_program() {
let mut app = App::new();
let prog_1 = BpfProgram {
id: 1,
bpf_type: "test".to_string(),
name: "test".to_string(),
prev_runtime_ns: 100,
run_time_ns: 200,
prev_run_cnt: 1,
run_cnt: 2,
instant: Instant::now(),
period_ns: 0,
processes: vec![],
};
let prog_2 = BpfProgram {
id: 2,
bpf_type: "test".to_string(),
name: "test".to_string(),
prev_runtime_ns: 100,
run_time_ns: 200,
prev_run_cnt: 1,
run_cnt: 2,
instant: Instant::now(),
period_ns: 0,
processes: vec![],
};
// Add some dummy BpfPrograms to the items vector
app.items.lock().unwrap().push(prog_1.clone());
app.items.lock().unwrap().push(prog_2.clone());
// 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 with no table state, nothing should be selected
app.previous_program();
assert_eq!(app.selected_program(), None, "expected None");
assert_eq!(app.vertical_scroll, 0, "still 0, no wrapping");
// After calling previous again, still nothing should be selected
app.previous_program();
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, 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");
}