Toaster::shown: the titles and severities on show, for owners and tests
This commit is contained in:
2 files changed
+18
No files matched your search
@@ -142,6 +142,18 @@ fn a_toast_folds_away_after_its_time(cx: &mut TestAppContext) {
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_owner_reads_what_is_shown(cx: &mut TestAppContext) {
|
||||
let (view, cx) = desk(cx);
|
||||
let first = push(&view, Toast::new("Saved"), cx);
|
||||
push(&view, Toast::new("Denied").severity(Severity::Danger), cx);
|
||||
let toaster = view.read_with(cx, |desk, _| desk.toaster.clone());
|
||||
let shown = |cx: &mut VisualTestContext| toaster.read_with(cx, |toaster, _| toaster.shown());
|
||||
assert_eq!(shown(cx), [("Saved".into(), None), ("Denied".into(), Some(Severity::Danger))]);
|
||||
toaster.update(cx, |toaster, cx| toaster.dismiss(first, cx));
|
||||
assert_eq!(shown(cx), [("Denied".into(), Some(Severity::Danger))], "a leaving toast is not shown");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_pointer_on_the_stack_holds_the_clock(cx: &mut TestAppContext) {
|
||||
let (view, cx) = desk(cx);
|
||||
|
||||
@@ -125,6 +125,12 @@ impl Toaster {
|
||||
id
|
||||
}
|
||||
|
||||
/// The titles and severities on show, oldest first.
|
||||
pub fn shown(&self) -> Vec<(SharedString, Option<Severity>)> {
|
||||
let staying = self.live.iter().filter(|live| !live.leaving);
|
||||
staying.map(|live| (live.toast.title.clone(), live.toast.severity)).collect()
|
||||
}
|
||||
|
||||
/// Sends a toast away: it fades and folds, then leaves the stack.
|
||||
pub fn dismiss(&mut self, id: u64, cx: &mut Context<Self>) {
|
||||
let Some(live) = self
|
||||
|
||||
Reference in new issue
Block a user