Add basic test for labeled tasks

This commit is contained in:
Kay Simmons 2023-02-21 16:14:22 -08:00
parent 3564e95f27
commit 6b6e4e3bfe

View file

@ -5279,6 +5279,7 @@ impl Subscription {
mod tests {
use super::*;
use crate::{actions, elements::*, impl_actions, MouseButton, MouseButtonEvent};
use postage::{sink::Sink, stream::Stream};
use serde::Deserialize;
use smol::future::poll_once;
use std::{
@ -6894,6 +6895,23 @@ mod tests {
assert_eq!(presenter.borrow().rendered_views.len(), 1);
}
#[crate::test(self)]
async fn test_labeled_tasks(cx: &mut TestAppContext) {
assert_eq!(None, cx.update(|cx| cx.active_labeled_tasks().next()));
let (mut sender, mut reciever) = postage::oneshot::channel::<()>();
let task = cx
.update(|cx| cx.spawn_labeled("Test Label", |_| async move { reciever.recv().await }));
assert_eq!(
Some("Test Label"),
cx.update(|cx| cx.active_labeled_tasks().next())
);
sender.send(()).await;
task.await;
assert_eq!(None, cx.update(|cx| cx.active_labeled_tasks().next()));
}
#[crate::test(self)]
async fn test_window_activation(cx: &mut TestAppContext) {
struct View(&'static str);