use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use ek_core::main_engine::MainEngine;
use ek_ui::plugin::UI_NAME;
use ek_ui::runtime::{Stage, StageApp, ui_kinds};
use ek_ui::state::UiShared;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
fn temp_store(tag: &str) -> ek_cfg::Store {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("tmp")
.join(format!("flow-{}", tag));
let _ = std::fs::remove_dir_all(&root);
ek_cfg::set_default_root_for_tests(root.clone());
ek_cfg::Store::with_root(root)
}
#[test]
#[allow(non_snake_case)]
fn U_S_FLOW_full_desktop_walk() {
let engine = Arc::new(MainEngine::new(None));
let shared = Arc::new(UiShared::new());
let store = temp_store("flow");
let app = StageApp::new_setup(
Arc::clone(&engine),
Arc::clone(&shared),
ui_kinds(&shared, true),
Some(store),
None,
);
let cell = Rc::new(RefCell::new(app));
let mut h = Harness::new_ui_state(
{
let c = Rc::clone(&cell);
move |ui, ()| {
c.borrow_mut().render_setup_panel(ui);
}
},
(),
);
let _ = h.run();
assert!(
h.query_by_label_contains("运维").is_none(),
"首屏不许出主界面"
);
assert!(h.query_by_label("启动运行").is_some());
cell.borrow_mut().set_selected("tq", false);
let _ = h.run();
h.get_by_label("启动运行").click_accesskit();
let _ = h.run();
{
let a = cell.borrow();
assert!(a.assembled(), "启动钮要先装配落壳");
assert_eq!(a.stage(), Stage::Running, "装配成功即起跑转运行相");
}
let names = engine.plugin_names();
println!("[flow] 装配在册:{}", names.join(","));
assert!(names.iter().any(|n| n == "dm") && names.iter().any(|n| n == "ctp"));
assert!(names.iter().any(|n| n == "cfg"), "装配清单必含 cfg: {names:?}");
assert!(shared.assembly_locked(), "全壳 Running 要置锁");
assert!(!shared.is_stop());
let mut h2 = Harness::new_ui_state(
{
let shared = Arc::clone(&shared);
move |ui, ()| {
ek_ui::render_body(ui.ctx(), &shared);
}
},
(),
);
let _ = h2.run();
assert!(
h2.query_by_label_contains("运维").is_some(),
"运行相主界面要在场"
);
let _ = h.run();
{
let a = cell.borrow();
assert!(a.picked().iter().any(|n| n == UI_NAME), "ui 行恒勾");
}
assert!(shared.assembly_locked(), "锁位扛帧");
drop(h2);
drop(h);
engine.close_all(std::time::Duration::from_secs(3));
println!("[flow] 收尾后在册:{}", engine.plugin_names().join(","));
let _ = std::fs::remove_dir_all(
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("tmp"),
);
}