1use gpui::{Element, Hitbox, InteractiveElement};
3
4#[doc(hidden)]
5#[cfg(feature = "test-support")]
6pub type ObservedElement<E> = crate::test_support::Observed<E>;
7#[doc(hidden)]
8#[cfg(not(feature = "test-support"))]
9pub type ObservedElement<E> = E;
10
11pub trait TestSupportExt:
21 Element<PrepaintState = Option<Hitbox>> + InteractiveElement + Sized
22{
23 fn test_support(self) -> ObservedElement<Self> {
28 #[cfg(feature = "test-support")]
29 {
30 crate::test_support::Observed::new(self)
31 }
32 #[cfg(not(feature = "test-support"))]
33 {
34 self
35 }
36 }
37}
38impl<E: Element<PrepaintState = Option<Hitbox>> + InteractiveElement> TestSupportExt for E {}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43 use gpui::div;
44
45 #[test]
46 fn observation_preserves_identity_and_native_type_in_normal_builds() {
47 let element = div().id("target").test_support().test_support();
48 assert_eq!(Element::id(&element), Some("target".into()));
49 #[cfg(not(feature = "test-support"))]
50 let _: gpui::Stateful<gpui::Div> = element;
51 }
52}