use crossterm::event::{KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
use tokio::sync::mpsc;
use super::handle_mouse_event_with_pkgbuild_checks;
use crate::state::{AppState, PackageItem, PkgbuildCheckRequest, QueryInput};
fn new_app() -> AppState {
unsafe {
std::env::set_var("PACSEA_TEST_HEADLESS", "1");
}
AppState::default()
}
#[test]
fn click_pkgb_toggle_opens() {
let mut app = new_app();
app.results = vec![crate::state::PackageItem {
name: "rg".into(),
version: "1".into(),
description: String::new(),
source: crate::state::Source::Aur,
popularity: None,
out_of_date: None,
orphaned: false,
}];
app.selected = 0;
app.pkgb_button_rect = Some((10, 10, 5, 1));
let (dtx, _drx) = mpsc::unbounded_channel::<PackageItem>();
let (ptx, _prx) = mpsc::unbounded_channel::<PackageItem>();
let (atx, _arx) = mpsc::unbounded_channel::<PackageItem>();
let (pkgb_tx, mut pkgb_rx) = mpsc::unbounded_channel::<PackageItem>();
let (comments_tx, _comments_rx) = mpsc::unbounded_channel::<String>();
let (qtx, _qrx) = mpsc::unbounded_channel::<QueryInput>();
let (pkgb_check_tx, _pkgb_check_rx) = mpsc::unbounded_channel::<PkgbuildCheckRequest>();
let ev = MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 11,
row: 10,
modifiers: KeyModifiers::empty(),
};
let _ = handle_mouse_event_with_pkgbuild_checks(
ev,
&mut app,
&dtx,
&ptx,
&atx,
&pkgb_tx,
&comments_tx,
&qtx,
&pkgb_check_tx,
);
assert!(app.pkgb_visible);
assert!(pkgb_rx.try_recv().ok().is_some());
}
#[test]
fn click_pkgb_toggle_closes_and_resets() {
let mut app = new_app();
app.results = vec![crate::state::PackageItem {
name: "rg".into(),
version: "1".into(),
description: String::new(),
source: crate::state::Source::Aur,
popularity: None,
out_of_date: None,
orphaned: false,
}];
app.selected = 0;
app.pkgb_button_rect = Some((10, 10, 5, 1));
app.pkgb_visible = true;
app.pkgb_text = Some("dummy".into());
app.pkgb_scroll = 7;
app.pkgb_rect = Some((50, 50, 20, 5));
let (dtx, _drx) = mpsc::unbounded_channel::<PackageItem>();
let (ptx, _prx) = mpsc::unbounded_channel::<PackageItem>();
let (atx, _arx) = mpsc::unbounded_channel::<PackageItem>();
let (pkgb_tx, _pkgb_rx) = mpsc::unbounded_channel::<PackageItem>();
let (comments_tx, _comments_rx) = mpsc::unbounded_channel::<String>();
let (qtx, _qrx) = mpsc::unbounded_channel::<QueryInput>();
let (pkgb_check_tx, _pkgb_check_rx) = mpsc::unbounded_channel::<PkgbuildCheckRequest>();
let ev = MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 11,
row: 10,
modifiers: KeyModifiers::empty(),
};
let _ = handle_mouse_event_with_pkgbuild_checks(
ev,
&mut app,
&dtx,
&ptx,
&atx,
&pkgb_tx,
&comments_tx,
&qtx,
&pkgb_check_tx,
);
assert!(!app.pkgb_visible);
assert!(app.pkgb_text.is_none());
assert_eq!(app.pkgb_scroll, 0);
assert!(app.pkgb_rect.is_none());
}
#[test]
fn click_aur_filter_toggles() {
let mut app = new_app();
app.results_filter_show_aur = false;
app.results_filter_aur_rect = Some((5, 2, 10, 1));
let (dtx, _drx) = mpsc::unbounded_channel::<PackageItem>();
let (ptx, _prx) = mpsc::unbounded_channel::<PackageItem>();
let (atx, _arx) = mpsc::unbounded_channel::<PackageItem>();
let (pkgb_tx, _pkgb_rx) = mpsc::unbounded_channel::<PackageItem>();
let (comments_tx, _comments_rx) = mpsc::unbounded_channel::<String>();
let (qtx, _qrx) = mpsc::unbounded_channel::<QueryInput>();
let (pkgb_check_tx, _pkgb_check_rx) = mpsc::unbounded_channel::<PkgbuildCheckRequest>();
let ev = MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 7,
row: 2,
modifiers: KeyModifiers::empty(),
};
let _ = handle_mouse_event_with_pkgbuild_checks(
ev,
&mut app,
&dtx,
&ptx,
&atx,
&pkgb_tx,
&comments_tx,
&qtx,
&pkgb_check_tx,
);
assert!(app.results_filter_show_aur);
}
#[test]
fn click_artix_filter_all_on_turns_all_off() {
let mut app = new_app();
app.results_filter_show_artix_omniverse = true;
app.results_filter_show_artix_universe = true;
app.results_filter_show_artix_lib32 = true;
app.results_filter_show_artix_galaxy = true;
app.results_filter_show_artix_world = true;
app.results_filter_show_artix_system = true;
app.results_filter_show_artix = true;
app.results_filter_artix_omniverse_rect = Some((10, 2, 5, 1));
app.results_filter_artix_rect = Some((5, 2, 8, 1));
let (dtx, _drx) = mpsc::unbounded_channel::<PackageItem>();
let (ptx, _prx) = mpsc::unbounded_channel::<PackageItem>();
let (atx, _arx) = mpsc::unbounded_channel::<PackageItem>();
let (pkgb_tx, _pkgb_rx) = mpsc::unbounded_channel::<PackageItem>();
let (comments_tx, _comments_rx) = mpsc::unbounded_channel::<String>();
let (qtx, _qrx) = mpsc::unbounded_channel::<QueryInput>();
let (pkgb_check_tx, _pkgb_check_rx) = mpsc::unbounded_channel::<PkgbuildCheckRequest>();
let ev = MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 7,
row: 2,
modifiers: KeyModifiers::empty(),
};
let _ = handle_mouse_event_with_pkgbuild_checks(
ev,
&mut app,
&dtx,
&ptx,
&atx,
&pkgb_tx,
&comments_tx,
&qtx,
&pkgb_check_tx,
);
assert!(!app.results_filter_show_artix_omniverse);
assert!(!app.results_filter_show_artix_universe);
assert!(!app.results_filter_show_artix_lib32);
assert!(!app.results_filter_show_artix_galaxy);
assert!(!app.results_filter_show_artix_world);
assert!(!app.results_filter_show_artix_system);
assert!(!app.results_filter_show_artix);
}
#[test]
fn click_artix_filter_some_off_turns_all_on() {
let mut app = new_app();
app.results_filter_show_artix_omniverse = true;
app.results_filter_show_artix_universe = false; app.results_filter_show_artix_lib32 = true;
app.results_filter_show_artix_galaxy = true;
app.results_filter_show_artix_world = true;
app.results_filter_show_artix_system = true;
app.results_filter_show_artix = true;
app.results_filter_artix_omniverse_rect = Some((10, 2, 5, 1));
app.results_filter_artix_rect = Some((5, 2, 8, 1));
let (dtx, _drx) = mpsc::unbounded_channel::<PackageItem>();
let (ptx, _prx) = mpsc::unbounded_channel::<PackageItem>();
let (atx, _arx) = mpsc::unbounded_channel::<PackageItem>();
let (pkgb_tx, _pkgb_rx) = mpsc::unbounded_channel::<PackageItem>();
let (comments_tx, _comments_rx) = mpsc::unbounded_channel::<String>();
let (qtx, _qrx) = mpsc::unbounded_channel::<QueryInput>();
let (pkgb_check_tx, _pkgb_check_rx) = mpsc::unbounded_channel::<PkgbuildCheckRequest>();
let ev = MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 7,
row: 2,
modifiers: KeyModifiers::empty(),
};
let _ = handle_mouse_event_with_pkgbuild_checks(
ev,
&mut app,
&dtx,
&ptx,
&atx,
&pkgb_tx,
&comments_tx,
&qtx,
&pkgb_check_tx,
);
assert!(app.results_filter_show_artix_omniverse);
assert!(app.results_filter_show_artix_universe);
assert!(app.results_filter_show_artix_lib32);
assert!(app.results_filter_show_artix_galaxy);
assert!(app.results_filter_show_artix_world);
assert!(app.results_filter_show_artix_system);
assert!(app.results_filter_show_artix);
}
#[test]
fn click_artix_filter_toggles_dropdown() {
let mut app = new_app();
app.artix_filter_menu_open = false;
app.results_filter_artix_rect = Some((5, 2, 8, 1));
app.results_filter_artix_omniverse_rect = None;
app.results_filter_artix_universe_rect = None;
let (dtx, _drx) = mpsc::unbounded_channel::<PackageItem>();
let (ptx, _prx) = mpsc::unbounded_channel::<PackageItem>();
let (atx, _arx) = mpsc::unbounded_channel::<PackageItem>();
let (pkgb_tx, _pkgb_rx) = mpsc::unbounded_channel::<PackageItem>();
let (comments_tx, _comments_rx) = mpsc::unbounded_channel::<String>();
let (qtx, _qrx) = mpsc::unbounded_channel::<QueryInput>();
let (pkgb_check_tx, _pkgb_check_rx) = mpsc::unbounded_channel::<PkgbuildCheckRequest>();
let ev = MouseEvent {
kind: MouseEventKind::Down(MouseButton::Left),
column: 7,
row: 2,
modifiers: KeyModifiers::empty(),
};
let _ = handle_mouse_event_with_pkgbuild_checks(
ev,
&mut app,
&dtx,
&ptx,
&atx,
&pkgb_tx,
&comments_tx,
&qtx,
&pkgb_check_tx,
);
assert!(app.artix_filter_menu_open);
}