|
|
|
@@ -0,0 +1,143 @@
|
|
|
|
|
//! A collection owns its scroll (16.3): one shown in a body that scrolls along its rows must take its natural height
|
|
|
|
|
//! or cap its rows, else the framework's debug assertion stops the pass. This opens every ribbon menu, every dialog,
|
|
|
|
|
//! every task pane and every File page over a deck whose selection brings up the contextual tabs, and draws each, so a
|
|
|
|
|
//! collection put back into a scrolling body fails here.
|
|
|
|
|
|
|
|
|
|
use deckcraft_engine::Session;
|
|
|
|
|
use deckcraft_model::ShapeId;
|
|
|
|
|
use egui::accesskit::Role;
|
|
|
|
|
use egui_kittest::Harness;
|
|
|
|
|
use egui_kittest::kittest::{NodeT, Queryable};
|
|
|
|
|
use serde_json::{Value, json};
|
|
|
|
|
|
|
|
|
|
use crate::{Services, SlideApp};
|
|
|
|
|
|
|
|
|
|
/// The sample deck with a shape, a picture, a table and a diagram added, each alone on a new slide, in that order;
|
|
|
|
|
/// returns their ids.
|
|
|
|
|
fn harness() -> (Harness<'static, SlideApp>, Vec<ShapeId>) {
|
|
|
|
|
let mut s = Session::new();
|
|
|
|
|
deckcraft_engine::sample::open_sample(&mut s).unwrap();
|
|
|
|
|
let png = deckcraft_render::Image { width: 2, height: 2, pixels: [255, 0, 0, 255].repeat(4) }.to_png();
|
|
|
|
|
let mut slides = Vec::new();
|
|
|
|
|
for (cmd, params) in [
|
|
|
|
|
("shape.insert", json!({"preset": "rect", "rect": [100.0, 100.0, 200.0, 120.0]})),
|
|
|
|
|
("insert.picture", json!({"data": deckcraft_engine::cmd::base64_encode(&png), "name": "a.png", "rect": [100, 100, 400, 200]})),
|
|
|
|
|
("insert.table", json!({"rows": 2, "cols": 2, "rect": [80, 80, 600, 160]})),
|
|
|
|
|
("insert.smartArt", json!({"kind": "process", "items": ["Plan", "Build", "Ship"]})),
|
|
|
|
|
] {
|
|
|
|
|
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
|
|
|
|
|
s.execute(cmd, ¶ms).unwrap();
|
|
|
|
|
slides.push(s.active().unwrap().doc.slides[s.active().unwrap().selection.slide].shapes[0].id);
|
|
|
|
|
}
|
|
|
|
|
let builder = Harness::builder().with_size(egui::vec2(1800.0, 1000.0)).with_step_dt(1.0 / 60.0);
|
|
|
|
|
let mut h = crate::test_harness::harness_with(s, Services::default(), builder, |_| {});
|
|
|
|
|
// The trial is about layout; a build without the craft-fonts input lacks some symbols' faces, and font coverage
|
|
|
|
|
// has its own tests.
|
|
|
|
|
h.ctx.set_missing_glyph_policy(egui::MissingGlyphPolicy::Tofu);
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
(h, slides)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Goes to the slide holding `id` and selects it; the ribbon's main actions may have added slides since.
|
|
|
|
|
fn select(h: &mut Harness<'_, SlideApp>, id: ShapeId) {
|
|
|
|
|
let session = &mut h.state_mut().session;
|
|
|
|
|
let slide = session.active().unwrap().doc.slides.iter().position(|slide| slide.shapes.iter().any(|shape| shape.id == id)).unwrap();
|
|
|
|
|
session.execute("slide.go", &json!({"index": slide})).unwrap();
|
|
|
|
|
session.execute("selection.select", &json!({"ids": [id.0]})).unwrap();
|
|
|
|
|
h.run_steps(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn dialog(h: &mut Harness<'_, SlideApp>, method: &str, params: Value) -> Result<Value, String> {
|
|
|
|
|
let ctx = h.ctx.clone();
|
|
|
|
|
crate::dialogs::control(h.state_mut(), &ctx, method, ¶ms).unwrap_or_else(|| Err(format!("{method} is not a dialog method")))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn close_dialogs(h: &mut Harness<'_, SlideApp>) {
|
|
|
|
|
while crate::dialogs::top_dialog(&h.ctx).is_some() {
|
|
|
|
|
dialog(h, "ui.dialog.close", json!({})).unwrap();
|
|
|
|
|
h.run_steps(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Names, in a failure, the surface that was being drawn when the pass panicked.
|
|
|
|
|
struct Opening(String);
|
|
|
|
|
|
|
|
|
|
impl Drop for Opening {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
if std::thread::panicking() {
|
|
|
|
|
eprintln!("the panic came while showing {}", self.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Opens each enabled menu button of the shown ribbon tab and draws its menu, closing it again.
|
|
|
|
|
fn open_tab_menus(h: &mut Harness<'_, SlideApp>, tab: &str) -> usize {
|
|
|
|
|
let shown = Opening(format!("the {tab} tab"));
|
|
|
|
|
h.state_mut().ui.tab = tab.into();
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
drop(shown);
|
|
|
|
|
let buttons: Vec<String> = h
|
|
|
|
|
.query_all_by_role(Role::Button)
|
|
|
|
|
.filter(|node| {
|
|
|
|
|
let node = node.accesskit_node();
|
|
|
|
|
node.has_popup().is_some() && !node.is_disabled()
|
|
|
|
|
})
|
|
|
|
|
.filter_map(|node| node.accesskit_node().label())
|
|
|
|
|
.collect();
|
|
|
|
|
for label in &buttons {
|
|
|
|
|
// A label shared by two buttons opens the first; the menus of both come from the same code.
|
|
|
|
|
let Some(button) = h.query_all_by_role_and_label(Role::Button, label).next() else { continue };
|
|
|
|
|
let _opening = Opening(format!("{tab} ▸ {label}"));
|
|
|
|
|
button.click();
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
h.key_press(egui::Key::Escape);
|
|
|
|
|
h.run_steps(2);
|
|
|
|
|
close_dialogs(h);
|
|
|
|
|
h.state_mut().ui.tab = tab.into();
|
|
|
|
|
h.run_steps(1);
|
|
|
|
|
}
|
|
|
|
|
buttons.len()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn no_collection_shares_a_scrolling_body() {
|
|
|
|
|
let (mut h, shapes) = harness();
|
|
|
|
|
let mut menus = 0;
|
|
|
|
|
for tab in ["Home", "Insert", "Draw", "Design", "Transitions", "Animations", "Slide Show", "Record", "Review", "View"] {
|
|
|
|
|
menus += open_tab_menus(&mut h, tab);
|
|
|
|
|
}
|
|
|
|
|
for (shape, tabs) in shapes.iter().zip([&["Shape Format"][..], &["Picture Format"], &["Table Design", "Layout"], &["SmartArt Design"]]) {
|
|
|
|
|
select(&mut h, *shape);
|
|
|
|
|
for tab in tabs {
|
|
|
|
|
menus += open_tab_menus(&mut h, tab);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert!(menus > 0, "the ribbon exposes menu buttons");
|
|
|
|
|
|
|
|
|
|
select(&mut h, shapes[0]);
|
|
|
|
|
for (id, _) in crate::dialogs::FORMS {
|
|
|
|
|
let _opening = Opening(format!("the {id} dialog"));
|
|
|
|
|
dialog(&mut h, "ui.dialog.open", json!({"id": id})).unwrap_or_else(|error| panic!("{id}: {error}"));
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
close_dialogs(&mut h);
|
|
|
|
|
}
|
|
|
|
|
for id in ["paragraph", "tabs", "hyperlink", "customShow", "spelling", "accessibility", "find", "about", "preferences", "autocorrect"] {
|
|
|
|
|
let _opening = Opening(format!("the {id} dialog"));
|
|
|
|
|
dialog(&mut h, "ui.dialog.open", json!({"id": id})).unwrap_or_else(|error| panic!("{id}: {error}"));
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
close_dialogs(&mut h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for pane in ["format", "background", "animation", "selection", "comments", "designer", "smartart", "thesaurus", "revisions"] {
|
|
|
|
|
let _opening = Opening(format!("the {pane} pane"));
|
|
|
|
|
h.state_mut().run("view.pane", json!({"pane": pane})).unwrap();
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
}
|
|
|
|
|
h.state_mut().run("view.pane", json!({"pane": null})).unwrap();
|
|
|
|
|
|
|
|
|
|
for page in crate::backstage::Page::ALL {
|
|
|
|
|
let _opening = Opening(format!("the File ▸ {} page", page.id()));
|
|
|
|
|
h.state_mut().open_backstage(page);
|
|
|
|
|
h.run_steps(3);
|
|
|
|
|
}
|
|
|
|
|
}
|