1#[cfg(test)]
2mod tests {
3 use sequoia_reactive::Signal;
4
5 use crate::live::SignalLiveExt;
6 use crate::view::View;
7 use crate::views::{Column, Row, Text};
8
9 #[derive(Clone)]
10 struct Counter {
11 value: Signal<i32>,
12 }
13
14 impl View for Counter {
15 fn body(&self) -> impl View + 'static {
16 let label = self.value.clone();
17 let inc = self.value.clone();
18 Row::new()
19 .child(Text::with(move || label.get().to_string()))
20 .child(crate::views::Unit)
21 .child(crate::live_view::LiveOpacity::new(
22 crate::views::Unit,
23 inc.map_live(|v| *v as f32),
24 ))
25 }
26 }
27
28 #[test]
29 fn counter_component_composes() {
30 let c = Counter {
31 value: Signal::new(0),
32 };
33
34 let _ = c.body();
35 c.value.set(3);
36 assert_eq!(c.value.get_untracked(), 3);
37 let _ = Column::new().child(c);
38 }
39}