use super::app::Tab;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct VizSurface {
pub tab: Tab,
pub id: &'static str,
pub label: &'static str,
pub has_remote: bool,
pub has_local: bool,
pub is_subpanel: bool,
}
impl VizSurface {
const fn tab_pane(tab: Tab, id: &'static str, label: &'static str) -> Self {
VizSurface { tab, id, label, has_remote: true, has_local: true, is_subpanel: false }
}
const fn subpanel(tab: Tab, id: &'static str, label: &'static str) -> Self {
VizSurface { tab, id, label, has_remote: true, has_local: true, is_subpanel: true }
}
}
pub fn viz_surfaces() -> Vec<VizSurface> {
let mut v: Vec<VizSurface> = Tab::ALL
.iter()
.map(|t| VizSurface::tab_pane(*t, t.id(), t.label()))
.collect();
v.push(VizSurface::subpanel(Tab::Nornir, "Nornir.populate_status", "Populate status (CloneEvents)"));
v.push(VizSurface::subpanel(Tab::Nornir, "Nornir.jobs", "Jobs (Viz.Jobs)"));
v
}
pub fn tab_pane_ids() -> Vec<&'static str> {
viz_surfaces().iter().filter(|s| !s.is_subpanel).map(|s| s.id).collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn registry_has_every_tab_plus_subpanels_with_unique_ids() {
let surfaces = viz_surfaces();
let tab_panes = surfaces.iter().filter(|s| !s.is_subpanel).count();
let subpanels = surfaces.iter().filter(|s| s.is_subpanel).count();
assert_eq!(tab_panes, Tab::ALL.len(), "one VizSurface per Tab::ALL variant");
assert_eq!(subpanels, 2, "the populate_status + jobs sub-panels are enumerated");
let mut ids: Vec<&str> = surfaces.iter().map(|s| s.id).collect();
let n = ids.len();
ids.sort_unstable();
ids.dedup();
assert_eq!(ids.len(), n, "every VizSurface id must be unique");
assert!(
surfaces.iter().any(|s| s.id == "Nornir.populate_status" && s.is_subpanel),
"populate_status sub-panel enumerated"
);
assert!(
surfaces.iter().any(|s| s.id == "Nornir.jobs" && s.is_subpanel),
"jobs sub-panel enumerated"
);
}
#[test]
fn tab_pane_ids_equal_tab_id() {
for s in viz_surfaces().iter().filter(|s| !s.is_subpanel) {
assert_eq!(s.id, s.tab.id(), "tab pane id must equal Tab::id()");
}
}
}