Skip to content

Commit 7e99280

Browse files
authored
Merge pull request #9 from Ivy-Interactive/tendril/00237-AddTestForTooltipWrappingInteractiveWidgetWithEvents
[00237] Add test for Tooltip wrapping interactive widget with events
2 parents f5aa3f3 + e606fcb commit 7e99280

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

rusty/src/views/view.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,40 @@ mod tests {
531531
assert_eq!(tooltip.get_id(), Some("w-0"));
532532
}
533533
}
534+
535+
#[test]
536+
fn test_tooltip_child_button_click_dispatched() {
537+
let mut store = HookStore::default();
538+
let mut ctx = BuildContext::new(&mut store, None);
539+
540+
let clicked = Arc::new(std::sync::atomic::AtomicBool::new(false));
541+
let clicked_clone = clicked.clone();
542+
543+
let mut element: Element = Tooltip::new(
544+
"tip",
545+
Button::new("Click").on_click(move || {
546+
clicked_clone.store(true, std::sync::atomic::Ordering::SeqCst);
547+
}),
548+
)
549+
.into();
550+
551+
element.assign_ids(&mut ctx);
552+
553+
// Tooltip gets w-0, inner Button gets w-1
554+
if let Element::Widget(tooltip) = &element {
555+
assert_eq!(tooltip.get_id(), Some("w-0"));
556+
}
557+
558+
// Dispatch the click event on the inner Button's ID
559+
let registry = ctx.take_event_registry();
560+
let dispatched = registry.dispatch("w-1", "click", serde_json::Value::Null);
561+
assert!(
562+
dispatched,
563+
"click event should be registered for inner Button w-1"
564+
);
565+
assert!(
566+
clicked.load(std::sync::atomic::Ordering::SeqCst),
567+
"on_click handler should have fired"
568+
);
569+
}
534570
}

0 commit comments

Comments
 (0)