use egui::accesskit::Role;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use facett_core::Facet;
use facett_plotters::{
BoxPlotView, CandlestickView, ChartKind, ChartView, HeatmapView, Ohlc, Series, Tile, TreemapView,
ViolinView,
};
#[test]
fn chart_series_is_queryable_image_with_point_count() {
let mut v = ChartView::new(
"Revenue",
vec![
Series::new("north", vec![(0.0, 1.0), (1.0, 3.0), (2.0, 2.0)]),
Series::new("south", vec![(0.0, 2.0), (1.0, 1.0)]),
],
);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let n = harness.get_by_label("north").accesskit_node();
assert_eq!(n.role(), Role::Image, "a painted series must expose an Image role (FC-4)");
assert_eq!(n.numeric_value(), Some(3.0), "the series carries its point count as numeric_value");
let s = harness.get_by_label("south").accesskit_node();
assert_eq!(s.numeric_value(), Some(2.0));
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"ChartView",
"fc4_series_points",
n.numeric_value() == Some(3.0) && s.numeric_value() == Some(2.0),
"series north points=3, south points=2",
);
}
#[test]
fn chart_bar_cluster_is_queryable_with_value() {
let mut v = ChartView::new("Q", vec![Series::new("a", vec![(0.0, 5.0), (1.0, 9.0)])])
.with_kind(ChartKind::Bar);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let bar = harness.get_by_label("a · 1").accesskit_node();
assert_eq!(bar.role(), Role::Image, "a painted bar must expose an Image role (FC-4)");
assert_eq!(bar.numeric_value(), Some(9.0), "the bar carries its y value");
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"ChartView",
"fc4_bar_value",
bar.numeric_value() == Some(9.0),
"bar a·1 value=9.0",
);
}
#[test]
fn treemap_tile_is_queryable_image_with_weight() {
let mut v = TreemapView::new(
"Treemap",
vec![
Tile::new("alpha", 70.0),
Tile::new("beta", 20.0),
Tile::new("gamma", 10.0),
],
);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let n = harness.get_by_label("alpha · tile 0").accesskit_node();
assert_eq!(n.role(), Role::Image, "a painted treemap tile must expose an Image role (FC-4)");
assert_eq!(n.numeric_value(), Some(70.0), "the tile carries its weight as numeric_value");
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"TreemapView",
"fc4_tile_weight",
n.role() == Role::Image && n.numeric_value() == Some(70.0),
"tile 'alpha' Image node weight=70",
);
}
#[test]
fn boxplot_box_is_queryable_image_with_median() {
let mut v = BoxPlotView::new(
"Box",
vec![
("a".into(), vec![1.0, 2.0, 3.0, 4.0, 5.0]),
("b".into(), vec![10.0, 20.0, 30.0]),
],
);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let n = harness.get_by_label("a").accesskit_node();
assert_eq!(n.role(), Role::Image, "a painted box must expose an Image role (FC-4)");
assert_eq!(n.numeric_value(), Some(3.0), "the box carries its median as numeric_value");
let n2 = harness.get_by_label("b").accesskit_node();
assert_eq!(n2.numeric_value(), Some(20.0));
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"BoxPlotView",
"fc4_box_median",
n.numeric_value() == Some(3.0) && n2.numeric_value() == Some(20.0),
"box a median=3.0, b median=20.0",
);
}
#[test]
fn heatmap_cell_is_queryable_image_with_value() {
let mut v = HeatmapView::new("Heat", 2, 2, vec![1.0, 2.0, 3.0, 4.0])
.with_labels(vec!["x".into(), "y".into()], vec!["p".into(), "q".into()]);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let c00 = harness.get_by_label("x × p").accesskit_node();
assert_eq!(c00.role(), Role::Image, "a painted heatmap cell must expose an Image role (FC-4)");
assert_eq!(c00.numeric_value(), Some(1.0));
let c11 = harness.get_by_label("y × q").accesskit_node();
assert_eq!(c11.numeric_value(), Some(4.0));
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"HeatmapView",
"fc4_cell_value",
c00.numeric_value() == Some(1.0) && c11.numeric_value() == Some(4.0),
"cell x×p=1.0, y×q=4.0",
);
}
#[test]
fn candlestick_candle_is_queryable_image_with_close() {
let mut v = CandlestickView::new(
"Candles",
vec![
Ohlc::new("Mon", 10.0, 14.0, 9.0, 13.0),
Ohlc::new("Tue", 13.0, 15.0, 11.0, 12.0),
],
);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let mon = harness.get_by_label("Mon · bar 0").accesskit_node();
assert_eq!(mon.role(), Role::Image, "a painted candle must expose an Image role (FC-4)");
assert_eq!(mon.numeric_value(), Some(13.0), "the candle carries its close as numeric_value");
let tue = harness.get_by_label("Tue · bar 1").accesskit_node();
assert_eq!(tue.numeric_value(), Some(12.0));
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"CandlestickView",
"fc4_candle_close",
mon.numeric_value() == Some(13.0) && tue.numeric_value() == Some(12.0),
"Mon close=13.0, Tue close=12.0",
);
}
#[test]
fn violin_silhouette_is_queryable_image_with_median() {
let mut v = ViolinView::new(
"Violins",
vec![
("left".into(), vec![1.0, 2.0, 3.0, 4.0, 5.0]),
("right".into(), vec![10.0, 11.0, 12.0, 13.0, 14.0]),
],
);
let mut harness = Harness::new_ui(move |ui| v.ui(ui));
harness.run();
let left = harness.get_by_label("left").accesskit_node();
assert_eq!(left.role(), Role::Image, "a painted violin must expose an Image role (FC-4)");
assert_eq!(left.numeric_value(), Some(3.0), "the violin carries its median as numeric_value");
let right = harness.get_by_label("right").accesskit_node();
assert_eq!(right.numeric_value(), Some(12.0));
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(
"ViolinView",
"fc4_violin_median",
left.numeric_value() == Some(3.0) && right.numeric_value() == Some(12.0),
"violin left median=3.0, right median=12.0",
);
}