dwarves-gui/tests/robot_dataview_room.rs
//! **ROBOT-UI: the Data view's symbol grid, call graph and 📄 source pane are the
//! code room's.**
//!
//! The shipped shell → forge → mock nornir. The wall binds the room's
//! `Knowledge.Symbols` as a grid and its `Viz.CallGraph` as a 3D graph beside the
//! tables that are still tables; a click on a call-graph node asks `Knowledge.Source`
//! for THAT item (by its moniker) and the source pane shows the server's span and
//! text. A refusing room gets no pane and is named.
mod common;
use common::*;
use facett_core::Facet;
use serde_json::json;
#[test]
fn the_wall_and_the_source_pane_show_the_rooms_answers_through_the_forge() {
let st = stand(full_room());
let mut app = shell(&st.host);
Facet::update_json(&mut app, &json!({ "set_tab": "Data view" }).to_string());
Facet::update_json(&mut app, "\"scan\"");
let d = Facet::state_json(&app)["data-view"].clone();
assert_eq!(d["scanned"], true, "{d}");
// the wall: the two tables the stand serves that are on the wall + the room's two panes
let bound: Vec<String> = serde_json::from_value(d["tables_bound"].clone()).unwrap();
for t in [
"room_symbols",
"room_calls",
"git_heat_facts",
"dep_graph_edges",
] {
assert!(bound.contains(&t.to_string()), "`{t}` is bound: {bound:?}");
}
let panes = d["deck"]["panes"].as_array().unwrap();
let pane = |title: &str| {
panes
.iter()
.find(|p| p["title"] == title)
.cloned()
.unwrap_or_else(|| panic!("no pane `{title}`: {panes:?}"))
};
let (sym, calls) = (symbols(), call_graph());
assert_eq!(
pane("code room: symbols")["rows"].as_u64(),
Some(sym["symbols"].as_array().unwrap().len() as u64)
);
assert_eq!(
pane("code room: call graph")["nodes"].as_u64(),
Some(calls["nodes"].as_array().unwrap().len() as u64)
);
assert_eq!(
pane("code room: call graph")["edges"].as_u64(),
Some(calls["edges"].as_array().unwrap().len() as u64)
);
// the reader's totals beside what is shown, and the room they were read from
assert_eq!(
(
d["room"]["symbols_shown"].as_u64(),
d["room"]["symbols_total"].as_u64()
),
(Some(3), Some(53))
);
assert_eq!(
(
d["room"]["call_edges_shown"].as_u64(),
d["room"]["call_edges_total"].as_u64()
),
(Some(2), Some(31))
);
assert_eq!(d["room"]["calls"]["room"], ROOM_LINE);
assert_eq!(
d["room"]["calls"]["evidence"],
"capped: 2 of 31 shown · a lower bound"
);
let graph = d["graph_panes"]
.as_array()
.unwrap()
.iter()
.find(|g| g["title"] == "code room: call graph")
.unwrap()
.clone();
assert_eq!(
graph["labels"],
json!(["shop::checkout", "shop::pay::charge", "shop::pay::audit"]),
"the reader's nodes, in its order"
);
assert!(asked(&st.room)
.iter()
.any(|a| a == &(WS.to_string(), "Viz.CallGraph".to_string())));
// the click: asked by the item's moniker, answered with the server's span and text
Facet::update_json(&mut app, r#"{"select_node":"shop::pay::charge"}"#);
let g = Facet::state_json(&app)["data-view"]["graph_source"].clone();
let want = source();
assert_eq!(
(g["state"].as_str(), g["moniker"].as_str()),
(Some("source"), Some("m:charge"))
);
assert_eq!(g["heading"], "shop/src/pay.rs:7-9 @ 0123456789");
assert_eq!(
g["lines"].as_u64(),
Some(want["lines"].as_array().unwrap().len() as u64)
);
assert_eq!(
(g["first_line"].as_str(), g["last_line"].as_str()),
(want["lines"][0].as_str(), want["lines"][2].as_str())
);
assert_eq!(
params_of(&st.room, "Knowledge.Source").map(|p| p["moniker"].clone()),
Some(json!("m:charge"))
);
// the room refuses: no code-room pane, the state named for each; the item's source too
for s in ["Knowledge.Symbols", "Viz.CallGraph", "Knowledge.Source"] {
st.room.set(s, refusal("not_consumed", NOT_CONSUMED));
}
Facet::update_json(&mut app, "\"scan\"");
let d = Facet::state_json(&app)["data-view"].clone();
let bound: Vec<String> = serde_json::from_value(d["tables_bound"].clone()).unwrap();
assert!(!bound.iter().any(|t| t.starts_with("room_")), "{bound:?}");
let notes: Vec<String> = serde_json::from_value(d["notes"].clone()).unwrap();
assert!(
notes.contains(&format!(
"code room: symbols [not_consumed]: {NOT_CONSUMED}"
)),
"{notes:?}"
);
assert!(
notes.contains(&format!(
"code room: call graph [not_consumed]: {NOT_CONSUMED}"
)),
"{notes:?}"
);
assert!(
d["room"]["symbols_shown"].is_null()
&& d["room"]["call_edges_shown"].is_null()
&& d["room"]["call_nodes"].is_null(),
"nothing is counted of a refusal: {}",
d["room"]
);
assert!(d["room"]["symbols_total"].is_null() && d["room"]["call_edges_total"].is_null());
// the item that WAS on screen is asked again — and is now a state, with no line of code
let g = &d["graph_source"];
assert_eq!(
(g["state"].as_str(), g["lines"].as_u64()),
(Some("not_consumed"), None),
"{g}"
);
assert!(g["heading"].is_null() && g["first_line"].is_null());
matrix("data_view_wall_and_source_pane_show_the_rooms_answers", true, "symbol grid rows, call-graph nodes/edges and the clicked item's span + text read back from state_json equal the room's answers");
}