use seval::action::Action;
use tokio::sync::mpsc;
#[tokio::test]
async fn action_dispatch_through_channel() {
let (tx, mut rx) = mpsc::unbounded_channel::<Action>();
tx.send(Action::Quit).unwrap();
tx.send(Action::Render).unwrap();
tx.send(Action::Resize(80, 24)).unwrap();
assert_eq!(rx.recv().await.unwrap(), Action::Quit);
assert_eq!(rx.recv().await.unwrap(), Action::Render);
assert_eq!(rx.recv().await.unwrap(), Action::Resize(80, 24));
}
#[tokio::test]
async fn quit_action_received() {
let (tx, mut rx) = mpsc::unbounded_channel::<Action>();
tx.send(Action::Quit).unwrap();
let action = rx.recv().await.unwrap();
assert_eq!(action, Action::Quit);
}
#[test]
fn action_display() {
assert_eq!(Action::Tick.to_string(), "Tick");
assert_eq!(Action::Render.to_string(), "Render");
assert_eq!(Action::Quit.to_string(), "Quit");
assert_eq!(Action::Suspend.to_string(), "Suspend");
assert_eq!(Action::Resume.to_string(), "Resume");
assert_eq!(Action::Error("test".to_string()).to_string(), "Error");
}
#[test]
fn action_equality() {
assert_eq!(Action::Quit, Action::Quit);
assert_ne!(Action::Quit, Action::Render);
assert_eq!(Action::Resize(80, 24), Action::Resize(80, 24));
assert_ne!(Action::Resize(80, 24), Action::Resize(100, 40));
}
#[test]
fn action_clone() {
let original = Action::Resize(120, 40);
let cloned = original.clone();
assert_eq!(original, cloned);
}
#[tokio::test]
async fn channel_closes_on_sender_drop() {
let (tx, mut rx) = mpsc::unbounded_channel::<Action>();
tx.send(Action::Render).unwrap();
drop(tx);
assert_eq!(rx.recv().await.unwrap(), Action::Render);
assert!(rx.recv().await.is_none());
}