use guiduck_scene::geom::Size; use super::*; #[test] fn progress_clamps_rather_than_overflowing() { let mut bar = Progress::new(); bar.set_value(1.4); assert_eq!( bar.get_value(), 1.0, "past the end is not drawn past the end" ); bar.set_value(-0.2); assert_eq!(bar.get_value(), 0.0); } #[test] fn progress_is_silent_when_set_to_what_it_already_is() { let mut bar = Progress::new(); bar.set_value(0.5); let _ = bar.take_dirt(); bar.set_value(0.5); assert!( bar.take_dirt().is_clean(), "a binding rewriting the same fraction costs no repaint" ); } #[test] fn progress_announces_a_percentage() { let mut bar = Progress::new(); bar.set_value(0.25); let mut node = accesskit::Node::new(accesskit::Role::ProgressIndicator); bar.accessibility(&mut node); assert_eq!(node.numeric_value(), Some(25.0)); } /// A rule takes its length from the layout and its thickness from the theme, /// so the same widget is a horizontal line in a column and a vertical one in /// a row. #[test] fn a_separator_is_led_by_its_layout() { let mut rule = Separator::new(); let mut text = crate::text::TextContext::hermetic([]); let across = rule.measure( &mut text, taffy::Size { width: Some(120.0), height: None, }, taffy::Size { width: AvailableSpace::MaxContent, height: AvailableSpace::MaxContent, }, ); assert_eq!(across.width, 120.0, "the layout gave the length"); assert!(across.height > 0.0, "the theme gave the thickness"); let mut paint = Fragment::default(); rule.paint(&mut paint, Size::new(120.0, across.height as f64)); assert!(!paint.items.is_empty(), "and it draws something"); }