2bc41aeb8602
tests.rs
use super::*;
use crate::theme;
#[test]
fn help_f1_opens_discover_without_a_document() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let (_, help) = menu_tree().into_iter().find(|(title, _)| *title == "Help").unwrap();
assert!(help.iter().any(|item| matches!(item, Item::Cmd("VectorCraft Help…", "help.discover", _))));
assert_eq!(shortcut_of("help.discover"), Some("F1"));
assert!(enabled(&app, "help.discover"));
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
ctx.run_ui(egui::RawInput { events: vec![key(egui::Key::F1)], ..Default::default() }, |ui| {
crate::shortcuts::handle(&mut app, ui.ctx());
})
.textures_delta
.clear();
assert!(crate::panel_docking::showing(&app.ui, "discover"));
assert!(app.session.active().is_none());
app.run("help.discover", json!({})).unwrap();
assert!(crate::panel_docking::showing(&app.ui, "discover"));
let tools = app.run("help.discover.search", json!({"query": "rectangle"})).unwrap();
let tool = tools["results"].as_array().unwrap().iter().position(|hit| hit["kind"] == "tool" && hit["id"] == "rectangle").unwrap();
let active_tool = app.session.tool_id();
let picked = app.run("help.discover.choose", json!({"index": tool})).unwrap();
assert_eq!(picked["result"]["id"], "rectangle");
assert!(app.ui.learn_locate.is_some());
assert_eq!(app.session.tool_id(), active_tool);
for _ in 0..2 {
ctx.run_ui(egui::RawInput::default(), |ui| crate::panels::discover::show(&mut app, ui)).textures_delta.clear();
}
ctx.run_ui(egui::RawInput { events: vec![key(egui::Key::Escape)], ..Default::default() }, |ui| {
crate::shortcuts::handle(&mut app, ui.ctx());
crate::panels::discover::show(&mut app, ui);
})
.textures_delta
.clear();
assert!(!crate::panel_docking::showing(&app.ui, "discover"));
app.run("help.discover", json!({})).unwrap();
app.run("help.discover.back", json!({})).unwrap();
assert_eq!(app.ui.discover.query, "rectangle");
assert!(app.ui.discover.selected.is_none());
crate::keymap::set_override(&mut app.ui.shortcut_overrides, "tool:rectangle", "Shift+9");
crate::shortcut_editor::sync(&app.ui);
let tools = app.run("help.discover.search", json!({"query": "rectangle"})).unwrap();
assert!(tools["results"].as_array().unwrap().iter().any(|hit| hit["kind"] == "tool" && hit["id"] == "rectangle" && hit["shortcut"] == "Shift+9"));
crate::shortcut_editor::sync(&crate::state::UiState::default());
let commands = app.run("help.discover.search", json!({"query": "file.newDialog"})).unwrap();
let command = commands["results"].as_array().unwrap().iter().position(|hit| hit["id"] == "file.newDialog").unwrap();
app.run("help.discover.choose", json!({"index": command})).unwrap();
assert!(app.ui.dialog.is_none());
assert!(app.session.active().is_none());
let tutorial = crate::panels::learn::catalog::SKILLS[0].tutorials.first().unwrap();
let found = app.run("help.discover.search", json!({"query": tutorial.title})).unwrap();
let index = found["results"].as_array().unwrap().iter().position(|hit| hit["kind"] == "tutorial" && hit["id"] == tutorial.id).unwrap();
app.run("help.discover.choose", json!({"index": index})).unwrap();
assert!(app.session.active().is_none());
let text = crate::tests_labels::painted_text(&mut app, crate::panels::discover::show);
assert!(text.contains(tutorial.title), "{text}");
app.ui.discover.focus = true;
ctx.run_ui(egui::RawInput::default(), |ui| crate::panels::discover::show(&mut app, ui)).textures_delta.clear();
ctx.run_ui(egui::RawInput { events: vec![key(egui::Key::Escape)], ..Default::default() }, |ui| {
crate::shortcuts::handle(&mut app, ui.ctx());
crate::panels::discover::show(&mut app, ui);
})
.textures_delta
.clear();
assert!(!crate::panel_docking::showing(&app.ui, "discover"));
app.run("file.new", json!({})).unwrap();
app.run("help.discover", json!({})).unwrap();
app.select_tool(vectorcraft_tools::addons::polygonal_lasso::ID);
let view = app.view_info();
for (x, y) in [(40.0, 40.0), (80.0, 40.0)] {
let down = vectorcraft_tools::PointerEvent::new(vectorcraft_tools::PointerKind::Down, x, y);
let up = vectorcraft_tools::PointerEvent::new(vectorcraft_tools::PointerKind::Up, x, y);
app.session.pointer(&down, view).unwrap();
app.session.pointer(&up, view).unwrap();
}
assert!(app.session.tool_ends_on_escape(view));
let canvas_ctx = egui::Context::default();
canvas_ctx
.run_ui(egui::RawInput { events: vec![key(egui::Key::Escape)], ..Default::default() }, |ui| {
crate::shortcuts::handle(&mut app, ui.ctx());
})
.textures_delta
.clear();
assert!(!app.session.tool_ends_on_escape(view));
assert!(crate::panel_docking::showing(&app.ui, "discover"));
}
/// With the toolbars hidden by Tab, choosing a tool in Help, or a tool's link in a tutorial Help
/// shows, marks nothing and the status bar says why.
#[test]
fn discover_says_why_a_tool_cannot_be_marked() {
fn texts(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec<egui::Event>) -> Vec<(String, egui::Rect)> {
let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| crate::panels::discover::show(app, ui));
out.textures_delta.clear();
fn collect(s: &egui::Shape, out: &mut Vec<(String, egui::Rect)>) {
match s {
egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())),
egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)),
_ => {}
}
}
let mut texts = vec![];
for c in &out.shapes {
collect(&c.shape, &mut texts);
}
texts
}
fn click(ctx: &egui::Context, app: &mut VectorcraftApp, label: &str) {
texts(ctx, app, vec![]);
let drawn = texts(ctx, app, vec![]);
let pos = drawn.iter().find(|(t, _)| t == label).unwrap_or_else(|| panic!("`{label}` not drawn: {drawn:?}")).1.center();
let button = |pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
for e in [egui::Event::PointerMoved(pos), button(true), button(false)] {
texts(ctx, app, vec![e]);
}
}
crate::i18n::set_current(crate::i18n::Lang::EN);
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("window.dock", json!({})).unwrap();
assert!(app.ui.tab_hid.is_some() && !app.ui.toolbar);
let reason = app.run("learn.locateTool", json!({"tool": "rectangle"})).unwrap()["reason"].as_str().unwrap().to_string();
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
let found = app.run("help.discover.search", json!({"query": "rectangle"})).unwrap();
let hit = found["results"].as_array().unwrap().iter().find(|hit| hit["kind"] == "tool" && hit["id"] == "rectangle").unwrap().clone();
app.status("");
click(&ctx, &mut app, hit["label"].as_str().unwrap());
assert_eq!(app.ui.discover.selected.map(|i| app.ui.discover.results[i].id.as_str()), Some("rectangle"));
assert!(app.ui.learn_locate.is_none());
assert_eq!(app.ui.status, reason);
let (tutorial, tool) = crate::panels::learn::catalog::SKILLS
.iter()
.flat_map(|skill| skill.tutorials.iter())
.find_map(|t| t.steps.iter().find_map(|s| s.tool).map(|tool| (t, tool)))
.unwrap();
let found = app.run("help.discover.search", json!({"query": tutorial.title})).unwrap();
let index = found["results"].as_array().unwrap().iter().position(|hit| hit["kind"] == "tutorial" && hit["id"] == tutorial.id).unwrap();
app.run("help.discover.choose", json!({"index": index})).unwrap();
app.status("");
click(&ctx, &mut app, vectorcraft_tools::tool_info(tool).unwrap().label);
assert!(app.ui.learn_locate.is_none());
assert_eq!(app.ui.status, reason);
}
#[test]
fn discover_rejects_invalid_search_and_selection_parameters() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("help.discover.search", json!({"query": "rectangle"})).unwrap();
let before = app.ui.discover.query.clone();
for params in
[json!({}), json!({"query": null}), json!({"query": false}), json!({"query": "rectangle", "unknown": 1}), json!({"query": "a".repeat(1025)})]
{
assert!(app.run("help.discover.search", params).is_err());
assert_eq!(app.ui.discover.query, before);
}
for index in [json!(-1), json!(1.5), json!(1000000), json!("0"), Value::Null] {
assert!(app.run("help.discover.choose", json!({"index": index})).is_err());
}
for params in [json!(5), json!("rectangle"), json!([1]), json!(true)] {
for id in ["help.discover", "help.discover.search", "help.discover.choose", "help.discover.back"] {
assert!(app.run(id, params.clone()).is_err(), "{id} {params}");
}
assert_eq!(app.ui.discover.query, before);
}
app.run("help.discover.search", json!({"query": " "})).unwrap();
assert!(app.ui.discover.results.is_empty());
assert!(app.run("help.discover.choose", json!({"index": 0})).is_err());
}
/// A kept command result follows its menu item: Show Grid reads Hide Grid once the grid shows.
#[test]
fn discover_command_results_follow_their_menu_label() {
crate::i18n::set_current(crate::i18n::Lang::EN);
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let found = app.run("help.discover.search", json!({"query": "view.grid"})).unwrap();
let index = found["results"].as_array().unwrap().iter().position(|hit| hit["id"] == "view.grid" && hit["path"][0] == "View").unwrap();
assert_eq!(found["results"][index]["label"], "Show Grid");
app.run("help.discover.choose", json!({"index": index})).unwrap();
app.run("view.grid", json!({})).unwrap();
let back = app.run("help.discover", json!({})).unwrap();
assert_eq!(back["selected"], index);
assert_eq!(back["results"][index]["label"], "Hide Grid");
}
/// A menu entry's shown path translates the menus' own names and keeps a Scripts folder's name, as
/// the menus draw it; Help shows that path.
#[test]
fn menu_entry_shown_paths_keep_script_folder_names() {
let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let de = crate::i18n::Lang::from_code("de").unwrap();
assert_ne!(crate::i18n::tr(de, "File"), "File");
let script = json!({"path": "File/a.jsx"});
let folder = vec![Item::Cmd("a", crate::scripts_menu::COMMAND, script)];
let items = vec![Item::Sub("Scripts", vec![Item::Sub("File", folder), Item::Cmd("Other Script…", "ui.runScript", Value::Null)])];
let mut out = vec![];
crate::i18n::set_current(de);
flatten(&app, vec!["File".into()], vec![crate::i18n::t("File").into()], &items, &mut out);
crate::i18n::set_current(crate::i18n::Lang::EN);
let script = out.iter().find(|e| e.command.as_deref() == Some(crate::scripts_menu::COMMAND)).unwrap();
assert_eq!(script.path, ["File", "Scripts", "File"]);
assert_eq!(script.shown_path, [crate::i18n::tr(de, "File"), crate::i18n::tr(de, "Scripts"), "File"]);
}
/// Outside macOS the window's menu bar has no VectorCraft menu, so Help lists no command under it.
#[test]
fn discover_leaves_out_menus_the_window_does_not_show() {
crate::i18n::set_current(crate::i18n::Lang::EN);
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let app_menu: Vec<String> =
menu_entries(&app).into_iter().filter(|e| e.path.first().is_some_and(|t| t == "VectorCraft")).filter_map(|e| e.command).collect();
assert!(!app_menu.is_empty());
for id in app_menu {
let found = app.run("help.discover.search", json!({"query": id})).unwrap();
let listed = found["results"].as_array().unwrap().iter().any(|hit| hit["path"][0] == "VectorCraft");
assert_eq!(listed, cfg!(target_os = "macos"), "{id}: {found}");
}
}
/// Help finds a command by the label its menu shows in the UI language, also where the menu names
/// an effect by its own id (Effect › Pathfinder › Add reads Réunion in French).
#[test]
fn discover_finds_commands_by_their_shown_menu_label() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let fr = crate::i18n::Lang::from_code("fr").unwrap();
let shown = crate::i18n::tr_id(fr, "pathfinder.add", "Add");
assert_ne!(shown, crate::i18n::tr(fr, "Add"));
crate::i18n::set_current(fr);
let found = app.run("help.discover.search", json!({"query": shown}));
let effect = crate::i18n::tr(fr, "Effect").to_string();
crate::i18n::set_current(crate::i18n::Lang::EN);
let found = found.unwrap();
let hits = found["results"].as_array().unwrap();
assert!(
hits.iter().any(|hit| hit["kind"] == "command"
&& hit["id"].as_str().is_some_and(|id| id.starts_with("effect."))
&& hit["label"] == shown
&& hit["path"][0] == effect),
"{found}"
);
}
#[test]
fn discover_results_show_the_current_shortcut_and_language_after_a_change() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let found = app.run("help.discover.search", json!({"query": "file.newDialog"})).unwrap();
let index = found["results"].as_array().unwrap().iter().position(|hit| hit["id"] == "file.newDialog").unwrap();
assert_eq!(found["results"][index]["shortcut"], "Cmd+N");
app.run("help.discover.choose", json!({"index": index})).unwrap();
app.run("window.panel.close", json!({"panel": "discover"})).unwrap();
app.run("shortcuts.set", json!({"id": "file.newDialog", "shortcut": "Cmd+Alt+Shift+F9"})).unwrap();
let reopened = app.run("help.discover", json!({})).unwrap();
assert_eq!(reopened["query"], "file.newDialog");
assert_eq!(reopened["selected"], index);
assert_eq!(reopened["results"][index]["id"], "file.newDialog");
assert_eq!(reopened["results"][index]["shortcut"], "Cmd+Alt+Shift+F9");
let picked = app.run("help.discover.choose", json!({"index": index})).unwrap();
assert_eq!(picked["result"]["shortcut"], "Cmd+Alt+Shift+F9");
assert_eq!(picked["location"]["shortcut"], "Cmd+Alt+Shift+F9");
app.run("shortcuts.set", json!({"id": "file.newDialog", "shortcut": "Cmd+Alt+Shift+F8"})).unwrap();
let text = crate::tests_labels::painted_text(&mut app, crate::panels::discover::show);
assert!(text.contains(&pretty_shortcut("Cmd+Alt+Shift+F8")), "{text}");
assert!(!text.contains(&pretty_shortcut("Cmd+Alt+Shift+F9")), "{text}");
let de = crate::i18n::Lang::from_code("de").unwrap();
assert_ne!(crate::i18n::tr(de, "New…"), "New…");
crate::i18n::set_current(de);
let back = app.run("help.discover.back", json!({})).unwrap();
crate::i18n::set_current(crate::i18n::Lang::EN);
assert_eq!(back["query"], "file.newDialog");
assert_eq!(back["results"][index]["label"], crate::i18n::tr(de, "New…"));
assert_eq!(back["results"][index]["path"][0], crate::i18n::tr(de, "File"));
crate::shortcut_editor::sync(&crate::state::UiState::default());
}
#[test]
fn help_bar_toggle_is_independent_and_saved_in_workspaces() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
assert!(app.ui.help_bar);
assert_eq!(checked(&app, "window.helpBar", &Value::Null), Some(true));
assert_eq!(run_ui_command(&mut app, "window.helpBar", &Value::Null).unwrap().unwrap(), json!(false));
assert!(app.ui.status_bar);
assert_eq!(checked(&app, "window.helpBar", &Value::Null), Some(false));
let saved = crate::workspaces::capture(&app.ui, "No help");
let saved: crate::workspaces::Workspace = serde_json::from_value(serde_json::to_value(saved).unwrap()).unwrap();
app.ui.help_bar = true;
app.ui.status_bar = false;
crate::workspaces::apply(&mut app.ui, &saved);
assert!(!app.ui.help_bar && app.ui.status_bar);
assert_eq!(run_ui_command(&mut app, "window.helpBar", &Value::Null).unwrap().unwrap(), json!(true));
let legacy: crate::workspaces::Workspace = serde_json::from_value(json!({"name":"Old workspace"})).unwrap();
assert!(legacy.help_bar);
let restored: crate::state::UiState = serde_json::from_value(serde_json::to_value(&app.ui).unwrap()).unwrap();
assert!(restored.help_bar);
let (_, window) = menu_tree().into_iter().find(|(title, _)| *title == "Window").unwrap();
assert!(window.iter().any(|item| matches!(item, Item::Cmd("Help Bar", "window.helpBar", _))));
}
/// One headless frame of the in-window menu bar; returns its titles (left to right) as
/// (rect, id of the title's popup).
fn bar_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) -> Vec<(egui::Rect, egui::Id)> {
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 700.0));
let mut layer = None;
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| {
layer = Some(ui.layer_id());
menu_bar(app, ui);
});
out.textures_delta.clear();
let layer = layer.unwrap();
let mut titles: Vec<(egui::Rect, egui::Id)> = ctx.viewport(|vp| {
vp.prev_pass
.widgets
.get_layer(layer)
.filter(|w| w.sense.senses_click() && w.rect.top() < 30.0)
// `egui::Popup::default_response_id` of the title's response.
.map(|w| (w.rect, w.id.with("popup")))
.collect()
});
titles.sort_by(|a, b| a.0.left().total_cmp(&b.0.left()));
titles
}
fn open_titles(ctx: &egui::Context, titles: &[(egui::Rect, egui::Id)]) -> Vec<usize> {
(0..titles.len()).filter(|&i| egui::Popup::is_id_open(ctx, titles[i].1)).collect()
}
/// File ends with Exit, running the app's own quit flow (unsaved documents are asked about).
#[test]
fn file_ends_with_exit() {
let tree = menu_tree();
let (_, file) = tree.iter().find(|(t, _)| *t == "File").unwrap();
let last = file.iter().rev().find(|i| !matches!(i, Item::Sep)).unwrap();
assert!(matches!(last, Item::Cmd("Exit", "app.quit", _)), "{last:?}");
}
/// Help starts with Search Commands…, the command search's own command, showing its shortcut,
/// then a separator; the menus list it once.
#[test]
fn help_starts_with_search_commands() {
let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let tree = menu_tree();
let (_, help) = tree.iter().find(|(t, _)| *t == "Help").unwrap();
assert!(matches!(help[0], Item::Cmd("Search Commands…", "help.commandPalette", _)), "{:?}", help[0]);
assert!(matches!(help[1], Item::Sep), "{:?}", help[1]);
let Some(Entry::Item(row)) = entry(&app, &help[0]) else { panic!("Search Commands… is not shown") };
assert!(row.enabled);
assert_eq!(row.shortcut, shortcut_of("help.commandPalette"));
assert!(row.shortcut.is_some(), "the search's shortcut shows next to the item");
fn count(items: &[Item]) -> usize {
items
.iter()
.map(|it| match it {
Item::Cmd(_, "help.commandPalette", _) => 1,
Item::Sub(_, children) => count(children),
_ => 0,
})
.sum()
}
assert_eq!(tree.iter().map(|(_, items)| count(items)).sum::<usize>(), 1);
}
/// No application menu in the window (as in Illustrator): the bar starts at File.
#[test]
fn the_bar_starts_at_file() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
theme::apply(&ctx, Default::default());
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 700.0));
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), ..Default::default() }, |ui| {
menu_bar(&mut app, ui);
});
out.textures_delta.clear();
fn texts(s: &egui::Shape, out: &mut Vec<String>) {
match s {
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)),
_ => {}
}
}
let mut shown = vec![];
out.shapes.iter().for_each(|c| texts(&c.shape, &mut shown));
let titles = ["File", "Edit", "Object", "Type", "Select", "Effect", "View", "Window", "Help"];
for t in titles {
assert!(shown.iter().any(|s| s == t), "{t} missing from {shown:?}");
}
assert!(!shown.iter().any(|s| s == "VectorCraft"), "{shown:?}");
}
#[test]
fn hovering_another_title_switches_the_open_menu() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
theme::apply(&ctx, Default::default());
bar_frame(&mut app, &ctx, vec![]);
let titles = bar_frame(&mut app, &ctx, vec![]);
// No application menu in the window: the bar starts at File on every platform.
assert_eq!(titles.len(), menu_tree().len() - 1);
let (file, edit, object) = (titles[0].0.center(), titles[1].0.center(), titles[2].0.center());
let frames = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
let mut t = bar_frame(app, &ctx, events);
for _ in 0..2 {
t = bar_frame(app, &ctx, vec![]);
}
t
};
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
// Nothing open: hovering a title opens nothing.
let t = frames(&mut app, vec![egui::Event::PointerMoved(edit)]);
assert!(open_titles(&ctx, &t).is_empty());
// Click File, then move onto Edit and on to Object: each opens in turn, alone.
frames(&mut app, vec![egui::Event::PointerMoved(file)]);
frames(&mut app, vec![button(file, true)]);
let t = frames(&mut app, vec![button(file, false)]);
assert_eq!(open_titles(&ctx, &t), vec![0], "a click opens File");
let t = frames(&mut app, vec![egui::Event::PointerMoved(edit)]);
assert_eq!(open_titles(&ctx, &t), vec![1], "hovering Edit opens it and closes File");
let t = frames(&mut app, vec![egui::Event::PointerMoved(object)]);
assert_eq!(open_titles(&ctx, &t), vec![2], "hovering Object opens it and closes Edit");
// A pointer resting on a title doesn't switch: File opened another way (the keyboard)
// stays open while the pointer stays still over Object.
egui::Popup::open_id(&ctx, t[0].1);
let t = frames(&mut app, vec![]);
assert_eq!(open_titles(&ctx, &t), vec![0], "a still pointer leaves the open menu alone");
}
#[test]
fn opening_the_file_menu_reads_the_scripts_folder_again() {
let dir = std::env::temp_dir().join(format!("vc-menu-bar-scripts-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let mut session = vectorcraft_engine::Session::new();
session.attach_scripts_dir(dir.clone());
let mut app = VectorcraftApp::new(session, crate::Services::default());
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
theme::apply(&ctx, Default::default());
// The scripts File › Scripts lists.
let listed = || {
let (_, file) = menu_tree().into_iter().find(|(title, _)| *title == "File").unwrap();
let scripts = file.iter().find_map(|item| match item {
Item::Sub("Scripts", items) => Some(items.clone()),
_ => None,
});
scripts
.unwrap()
.iter()
.filter_map(|item| if let Item::Cmd(label, crate::scripts_menu::COMMAND, _) = item { Some(*label) } else { None })
.collect::<Vec<_>>()
};
// One frame of the bar, then the listing a read it started gave.
let frame = |app: &mut VectorcraftApp| {
let titles = bar_frame(app, &ctx, vec![]);
crate::scripts_menu::wait();
titles
};
std::fs::write(dir.join("a.js"), "").unwrap();
frame(&mut app);
let titles = frame(&mut app);
assert!(listed().is_empty(), "the bar reads nothing while its menus are closed");
egui::Popup::open_id(&ctx, titles[0].1);
frame(&mut app);
assert_eq!(listed(), ["a"]);
// While File stays open the folder is not read again.
std::fs::write(dir.join("b.js"), "").unwrap();
frame(&mut app);
assert_eq!(listed(), ["a"]);
// Nor when another menu opens; the next time File opens it is.
egui::Popup::open_id(&ctx, titles[1].1);
let t = frame(&mut app);
assert_eq!((open_titles(&ctx, &t), listed()), (vec![1], vec!["a"]));
egui::Popup::open_id(&ctx, titles[0].1);
frame(&mut app);
assert_eq!(listed(), ["a", "b"]);
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn a_popup_covering_a_title_does_not_switch_menus() {
let ctx = egui::Context::default();
let p = egui::pos2(90.0, 12.0);
let mut reaches = (true, false);
// The popup becomes hit-testable once egui has laid it out: draw a few frames.
for _ in 0..3 {
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(300.0, 200.0))), ..Default::default() };
let mut out = ctx.run_ui(raw, |ui| {
let ctx = ui.ctx().clone();
let covered = ui.interact(egui::Rect::from_center_size(p, egui::vec2(80.0, 24.0)), egui::Id::unique("covered"), egui::Sense::click());
let q = p + egui::vec2(0.0, 100.0);
let free = ui.interact(egui::Rect::from_center_size(q, egui::vec2(80.0, 24.0)), egui::Id::unique("free"), egui::Sense::click());
egui::Area::new(egui::Id::unique("popup")).order(egui::Order::Foreground).fixed_pos(p - egui::vec2(10.0, 10.0)).show(&ctx, |ui| {
ui.allocate_space(egui::vec2(20.0, 20.0));
});
reaches = (pointer_reaches_title(&ctx, &covered, p), pointer_reaches_title(&ctx, &free, q));
});
out.textures_delta.clear();
}
assert_eq!(reaches, (false, true));
}
#[test]
fn names_in_menus_are_not_interface_labels() {
for (id, label) in [
("file.openRecent1", "Layers.svg"),
("view.goto2", "Layers"),
("type.recentFont1", "Regular"),
("text.setStyle", "Black"),
("window.workspace", "Layers"),
("plugin.dialog", "Group"),
("window.userSwatchLibrary3", "Default"),
] {
assert!(shows_a_name(id, label), "{id} {label}");
}
for (id, label) in [("object.group", "Group"), ("window.workspace", "Essentials"), ("effect.apply", "Drop Shadow")] {
assert!(!shows_a_name(id, label), "{id} {label}");
}
}
#[test]
fn last_effect_dialog_and_view_toggles() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
assert!(!enabled(&app, "effect.last"));
app.last_effect = Some(("distort.roughen".into(), json!({"size": 9})));
assert!(enabled(&app, "effect.last"));
assert_eq!(dynamic_label(&app, "effect.last", "Last Effect…"), "Last Effect: Roughen…");
app.run("effect.last", json!({})).unwrap();
let d = app.ui.dialog.as_ref().unwrap();
assert_eq!((d.kind.as_str(), d.str("__effect"), d.f64("size", 0.0)), ("effect", "distort.roughen".to_string(), 9.0));
for (id, on, off) in [
("view.textThreads", "Hide Text Threads", "Show Text Threads"),
("view.gradientAnnotator", "Hide Gradient Annotator", "Show Gradient Annotator"),
("view.livePaintGaps", "Show Live Paint Gaps", "Hide Live Paint Gaps"),
("type.hiddenCharacters", "Show Hidden Characters", "Hide Hidden Characters"),
("view.template", "Hide Template", "Show Template"),
] {
assert_eq!(dynamic_label(&app, id, ""), on);
app.run(id, json!({})).unwrap();
assert_eq!(dynamic_label(&app, id, ""), off);
}
}
/// Edit › Undo and Edit › Redo name the step in the UI language as the History panel lists it
/// (`panels::history::step_name`), including a step named after an effect whose catalog holds
/// only the effect's menu row with an ellipsis, as Japanese does for Feather.
#[test]
fn undo_and_redo_name_the_step_as_the_history_panel_does() {
let ja = crate::i18n::Lang::from_code("ja").expect("ja registered");
crate::i18n::set_current(ja);
let mut app = app_with_a_rectangle();
app.run("effect.apply", json!({"effect": "stylize.feather"})).unwrap();
assert_eq!(app.session.active().unwrap().history.undo.last().map(|h| h.label.as_str()), Some("Feather"));
let shown = |app: &VectorcraftApp, id: &'static str| {
let item = c(if id == "edit.undo" { "Undo" } else { "Redo" }, id);
match entry(app, &item) {
Some(Entry::Item(row)) => row.label.to_string(),
_ => panic!("{id} is not a menu item"),
}
};
let step = |template: &str, name: &str| {
let name = crate::panels::history::step_name(ja, name).unwrap_or_else(|| name.to_string());
crate::i18n::fmt(crate::i18n::tr(ja, template), &[("name", &name)])
};
assert_eq!(shown(&app, "edit.undo"), step("Undo {name}", "Feather"));
app.run("edit.undo", json!({})).unwrap();
assert_eq!(shown(&app, "edit.redo"), step("Redo {name}", "Feather"));
assert_eq!(shown(&app, "edit.undo"), step("Undo {name}", "Rectangle"), "a step with a plain row");
crate::i18n::set_current(crate::i18n::Lang::EN);
assert_eq!(shown(&app, "edit.redo"), "Redo Feather");
}
/// Type › Optical Margin Alignment runs `type.opticalMarginAlignment`, needs a selection, and
/// is checked while the selected type has it on. Its check, and Type Orientation's, read the
/// type inside a selected group too.
#[test]
fn optical_margin_alignment_is_a_checked_type_menu_item() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let ids: Vec<&str> = menu_tree()
.into_iter()
.filter(|(menu, _)| *menu == "Type")
.flat_map(|(_, items)| items)
.filter_map(|item| match item {
Item::Cmd("Optical Margin Alignment", id, _) => Some(id),
_ => None,
})
.collect();
assert_eq!(ids, ["type.opticalMarginAlignment"]);
let id = "type.opticalMarginAlignment";
assert_eq!(checked(&app, id, &Value::Null), Some(false));
assert!(!enabled(&app, id));
let text = app.run("text.create", json!({"x": 10, "y": 10, "text": "“Hi”"})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [text]})).unwrap();
assert!(enabled(&app, id));
assert_eq!(checked(&app, id, &Value::Null), Some(false));
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(true));
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(false));
// With the type in a selected group, the checks show the type the commands change.
app.run("object.group", json!({})).unwrap();
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(true));
app.run("type.orientation.vertical", json!({})).unwrap();
assert_eq!(checked(&app, "type.orientation.vertical", &Value::Null), Some(true));
assert_eq!(checked(&app, "type.orientation.horizontal", &Value::Null), Some(false));
}
/// Type › Dynamic Text runs `type.dynamicText`, is enabled for point type and for type on a path
/// and area type that are in no thread, and is checked while the selected type has it on.
#[test]
fn dynamic_text_is_a_checked_type_menu_item() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let ids: Vec<&str> = menu_tree()
.into_iter()
.filter(|(menu, _)| *menu == "Type")
.flat_map(|(_, items)| items)
.filter_map(|item| match item {
Item::Cmd("Dynamic Text", id, _) => Some(id),
_ => None,
})
.collect();
assert_eq!(ids, ["type.dynamicText"]);
let id = "type.dynamicText";
assert_eq!(checked(&app, id, &Value::Null), Some(false));
assert!(!enabled(&app, id));
let point = app.run("text.create", json!({"x": 10, "y": 10, "text": "Point"})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [point]})).unwrap();
assert!(enabled(&app, id), "point type, which it turns into area type with Block on");
assert_eq!(checked(&app, id, &Value::Null), Some(false), "point type");
let path = app.run("path.create", json!({"d": "M60 150 L340 150"})).unwrap()["id"].clone();
let t = app.run("text.createInPath", json!({"path": path, "mode": "onPath", "text": "Along", "at": [60, 150]})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [t]})).unwrap();
assert!(enabled(&app, id));
assert_eq!(checked(&app, id, &Value::Null), Some(false));
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(true));
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(false));
let frame = app.run("shape.rectangle", json!({"x": 60, "y": 200, "width": 200, "height": 100})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [t, frame]})).unwrap();
app.run("text.thread.create", json!({})).unwrap();
app.run("select.set", json!({"ids": [t]})).unwrap();
assert!(!enabled(&app, id), "type on a path in a thread");
// Area type takes Block, and the item is checked while it is on.
let area = app.run("text.create", json!({"x": 10, "y": 400, "text": "Block", "area": {"width": 100, "height": 50}})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [area]})).unwrap();
assert!(enabled(&app, id), "area type");
assert_eq!(checked(&app, id, &Value::Null), Some(false));
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(true));
// Point type first: unchecked, as the item turns it on.
app.run("select.set", json!({"ids": [point, area]})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(false), "point type first");
app.run(id, json!({})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(true), "both on");
}
/// Type › Type on a Path › Center on Top and Center on Bottom run `type.pathCenter.top` and
/// `.bottom`, which the command palette also runs without params, and are enabled for type on a
/// closed path only.
#[test]
fn center_on_top_and_bottom_are_type_on_a_path_items() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let items: Vec<(&str, &str)> = menu_tree()
.into_iter()
.filter(|(menu, _)| *menu == "Type")
.flat_map(|(_, items)| items)
.filter_map(|item| match item {
Item::Sub("Type on a Path", children) => Some(children),
_ => None,
})
.flatten()
.filter_map(|item| match item {
Item::Cmd(label, id, Value::Null) if id.starts_with("type.pathCenter") => Some((label, id)),
_ => None,
})
.collect();
let ids = ["type.pathCenter.top", "type.pathCenter.bottom"];
assert_eq!(items, [("Center on Top", ids[0]), ("Center on Bottom", ids[1])]);
let palette = crate::palette::items();
for (label, id) in items {
assert!(palette.iter().any(|(l, i, _)| l == &format!("Type › Type on a Path › {label}") && i == id), "{label}");
}
let line = app.run("path.create", json!({"d": "M60 150 L340 150"})).unwrap()["id"].clone();
let open = app.run("text.createInPath", json!({"path": line, "mode": "onPath", "text": "Along", "at": [60, 150]})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [open]})).unwrap();
assert!(ids.iter().all(|id| !enabled(&app, id)), "type on an open path");
let square = app.run("path.create", json!({"d": "M60 200 L160 200 L160 300 L60 300 Z"})).unwrap()["id"].clone();
let closed = app.run("text.createInPath", json!({"path": square, "mode": "onPath", "text": "Round", "at": [60, 200]})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [closed]})).unwrap();
assert!(ids.iter().all(|id| enabled(&app, id)));
app.run("select.set", json!({"ids": [closed, open]})).unwrap();
assert!(ids.iter().all(|id| !enabled(&app, id)), "type on a closed path and on an open one");
// A palette pick runs the command with no params.
app.run("select.set", json!({"ids": [closed]})).unwrap();
crate::palette::run_pick(&mut app, ids[0]);
let doc = &app.session.active().unwrap().doc;
let start = match &doc.node(vectorcraft_doc::NodeId(closed.as_u64().unwrap())).unwrap().kind {
vectorcraft_doc::NodeKind::Text(t) => match t.kind {
vectorcraft_doc::TextKind::OnPath { start, .. } => start,
ref k => panic!("{k:?}"),
},
k => panic!("{k:?}"),
};
// Once round, the middle of the top edge an eighth of the way round.
assert!((start - 0.625).abs() < 1e-6, "{start}");
}
/// Type › Size ends with a separator and Other…, which runs `type.highlightFontSize`: dimmed
/// without selected type, enabled with it, and never checked.
#[test]
fn type_size_ends_with_other() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let id = "type.highlightFontSize";
assert!(!enabled(&app, id), "no document");
app.run("file.new", json!({})).unwrap();
let items: Vec<Item> = menu_tree()
.into_iter()
.filter(|(menu, _)| *menu == "Type")
.flat_map(|(_, items)| items)
.filter_map(|item| match item {
Item::Sub("Size", children) => Some(children),
_ => None,
})
.flatten()
.collect();
let n = items.len();
assert!(n > 2, "{n} items");
assert!(matches!(items[n - 2], Item::Sep), "a separator comes before Other…");
assert!(matches!(&items[n - 1], Item::Cmd("Other…", c, p) if *c == id && p.is_null()), "Other… comes last");
assert!(items[..n - 2].iter().all(|i| matches!(i, Item::Cmd(_, "text.setStyle", _))), "the sizes come first");
assert!(!enabled(&app, id), "nothing selected");
let path = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [path]})).unwrap();
assert!(!enabled(&app, id), "a path selected");
let text = app.run("text.create", json!({"x": 10, "y": 100, "text": "Size"})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [text]})).unwrap();
assert!(enabled(&app, id), "type selected");
assert_eq!(checked(&app, id, &Value::Null), None);
}
/// Type › Dynamic Text Presets › Circle, Arch and Bow run `type.dynamicTextPreset` with their
/// preset, enabled for point type and type on a path but not for area type alone.
#[test]
fn dynamic_text_presets_are_a_type_submenu() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let items: Vec<(&str, &str, Value)> = menu_tree()
.into_iter()
.filter(|(menu, _)| *menu == "Type")
.flat_map(|(_, items)| items)
.filter_map(|item| match item {
Item::Sub("Dynamic Text Presets", children) => Some(children),
_ => None,
})
.flatten()
.filter_map(|item| match item {
Item::Cmd(label, id, p) => Some((label, id, p)),
_ => None,
})
.collect();
let id = "type.dynamicTextPreset";
assert_eq!(items, [("Circle", id, json!({"preset": "circle"})), ("Arch", id, json!({"preset": "arch"})), ("Bow", id, json!({"preset": "bow"}))]);
assert!(!enabled(&app, id));
let area = app.run("text.create", json!({"x": 10, "y": 200, "text": "Area", "area": {"width": 100, "height": 50}})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [area]})).unwrap();
assert!(!enabled(&app, id), "area type");
let point = app.run("text.create", json!({"x": 10, "y": 10, "text": "Point"})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [point]})).unwrap();
assert!(enabled(&app, id));
app.run(id, json!({"preset": "arch"})).unwrap();
// Now type on a path with Dynamic Text on, so Type › Dynamic Text is checked.
assert!(enabled(&app, id));
assert_eq!(checked(&app, "type.dynamicText", &Value::Null), Some(true));
}
/// Type › Optical Margin Alignment menu check uses `shared_text_flag`; mixed values stay unchecked.
#[test]
fn optical_margin_alignment_menu_unchecked_when_shared_flag_none() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let off = app.run("text.create", json!({"x": 10, "y": 40, "text": "Off"})).unwrap()["id"].clone();
let on = app.run("text.create", json!({"x": 10, "y": 80, "text": "On"})).unwrap()["id"].clone();
app.run("type.opticalMarginAlignment", json!({"on": true, "id": on})).unwrap();
app.run("select.set", json!({"ids": [off, on]})).unwrap();
let id = "type.opticalMarginAlignment";
assert_eq!(crate::panels::character::shared_text_flag(&app, |t| t.optical_margin), None);
assert_eq!(checked(&app, id, &Value::Null), Some(false));
app.run("select.set", json!({"ids": [on]})).unwrap();
assert_eq!(checked(&app, id, &Value::Null), Some(true));
}
/// Type › Orientation menu checks use `shared_text_flag`; mixed values leave both unchecked.
#[test]
fn type_orientation_menu_unchecked_when_shared_vertical_none() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let h = app.run("text.create", json!({"x": 10, "y": 40, "text": "H"})).unwrap()["id"].clone();
let v = app.run("text.create", json!({"x": 10, "y": 80, "text": "V", "vertical": true})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [h, v]})).unwrap();
assert_eq!(crate::panels::character::shared_text_flag(&app, |t| t.vertical), None);
assert_eq!(checked(&app, "type.orientation.vertical", &Value::Null), Some(false));
assert_eq!(checked(&app, "type.orientation.horizontal", &Value::Null), Some(false));
app.run("select.set", json!({"ids": [v]})).unwrap();
assert_eq!(checked(&app, "type.orientation.vertical", &Value::Null), Some(true));
assert_eq!(checked(&app, "type.orientation.horizontal", &Value::Null), Some(false));
}
#[test]
fn type_orientation_menu_unchecked_for_three_object_mixed_selections() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let v0 = app.run("text.create", json!({"x": 10, "y": 40, "text": "v0", "vertical": true})).unwrap()["id"].clone();
let h1 = app.run("text.create", json!({"x": 10, "y": 80, "text": "h1"})).unwrap()["id"].clone();
let h2 = app.run("text.create", json!({"x": 10, "y": 120, "text": "h2"})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [v0.clone(), h1.clone(), h2.clone()]})).unwrap();
assert_eq!(checked(&app, "type.orientation.vertical", &Value::Null), Some(false));
assert_eq!(checked(&app, "type.orientation.horizontal", &Value::Null), Some(false));
let h0 = app.run("text.create", json!({"x": 10, "y": 160, "text": "h0"})).unwrap()["id"].clone();
let v1 = app.run("text.create", json!({"x": 10, "y": 200, "text": "v1", "vertical": true})).unwrap()["id"].clone();
let v2 = app.run("text.create", json!({"x": 10, "y": 240, "text": "v2", "vertical": true})).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [h0.clone(), v1.clone(), v2.clone()]})).unwrap();
assert_eq!(checked(&app, "type.orientation.vertical", &Value::Null), Some(false));
assert_eq!(checked(&app, "type.orientation.horizontal", &Value::Null), Some(false));
app.run("select.set", json!({"ids": [v0.clone(), v1.clone(), v2.clone()]})).unwrap();
assert_eq!(checked(&app, "type.orientation.vertical", &Value::Null), Some(true));
assert_eq!(checked(&app, "type.orientation.horizontal", &Value::Null), Some(false));
}
#[test]
fn panel_ids_are_case_insensitive_and_labels_work() {
assert_eq!(normalize_panel("layers"), Some("layers"));
assert_eq!(normalize_panel("Layers"), Some("layers"));
assert_eq!(normalize_panel("LAYERS"), Some("layers"));
assert_eq!(normalize_panel("Swatches"), Some("swatches"));
assert_eq!(normalize_panel("swatches"), Some("swatches"));
assert_eq!(normalize_panel("Color Guide"), Some("colorGuide"));
assert_eq!(normalize_panel("colorguide"), Some("colorGuide"));
assert_eq!(normalize_panel(" Stroke "), Some("stroke"));
assert_eq!(normalize_panel("nope"), None);
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
app.run("window.panel", json!({"panel": "Layers"})).unwrap();
assert_eq!(app.ui.dock_tab, crate::state::DockTab::Layers);
app.run("window.panel", json!({"panel": "Swatches"})).unwrap();
assert_eq!(app.ui.open_panel.as_deref(), Some("swatches"));
assert!(checked(&app, "window.panel", &json!({"panel": "Swatches"})).unwrap());
assert!(app.run("window.panel", json!({"panel": "nope"})).is_err());
// A collapsed dock pops the panel out of its icon, by canonical id.
app.ui.dock_collapsed = true;
app.run("window.panel", json!({"panel": "Layers"})).unwrap();
assert_eq!(app.ui.open_panel.as_deref(), Some("layers"));
assert!(checked(&app, "window.panel", &json!({"panel": "Layers"})).unwrap());
app.ui.dock_collapsed = false;
}
/// #4542: Edit › Color Settings… and Assign Profile… show the Separations Preview panel, which
/// isn't in an icon column, and leave it showing when it already does.
#[test]
fn color_settings_and_assign_profile_show_the_separations_panel() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let shown = |app: &VectorcraftApp| checked(app, "window.panel", &json!({"panel": "separations"})).unwrap();
assert!(!shown(&app));
for id in ["edit.colorSettings", "edit.colorSettings", "edit.assignProfile"] {
app.run(id, json!({})).unwrap();
assert!(shown(&app), "{id} shows the panel");
}
}
/// Edit › Refresh Monitor Profile, after Assign Profile…, asks the desktop app's next frame to read
/// the display's profile; it is off and refused with the preference off or nothing to read it.
#[test]
fn refresh_monitor_profile_asks_for_a_reading_of_the_display_profile() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let entries = menu_entries(&app);
let at = |label: &str| entries.iter().position(|e| e.label == label && e.path == ["Edit"]);
assert_eq!(at("Refresh Monitor Profile"), at("Assign Profile…").map(|i| i + 1));
let e = &entries[at("Refresh Monitor Profile").unwrap()];
assert_eq!((e.command.as_deref(), e.shortcut.as_str()), (Some("view.refreshMonitorProfile"), ""));
// Nothing reads the display's profile (the web build, tests).
assert!(!enabled(&app, "view.refreshMonitorProfile"));
assert_eq!(app.run("view.refreshMonitorProfile", json!({})).unwrap_err(), "this build doesn't read display profiles");
app.display_profile.attach_reader();
assert!(enabled(&app, "view.refreshMonitorProfile"));
assert_eq!(app.run("view.refreshMonitorProfile", json!({})).unwrap(), json!({"requested": true}));
assert!(app.display_profile.take_request());
// With the preference off nothing is asked for.
app.session.prefs.monitor_profile_display = false;
assert!(!enabled(&app, "view.refreshMonitorProfile"));
assert_eq!(app.run("view.refreshMonitorProfile", json!({})).unwrap_err(), "turn on Use Monitor Profile for Canvas first");
assert!(!app.display_profile.read_requested());
}
#[test]
fn saved_views_store_and_restore_the_view() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
{
let v = app.view_mut().unwrap();
v.zoom = 3.0;
v.center = vectorcraft_geom::Point::new(120.0, 80.0);
}
app.run("view.saved.new", json!({"name": "Detail"})).unwrap();
assert!(enabled(&app, "view.goto1") && !enabled(&app, "view.goto2"));
assert_eq!(dynamic_label(&app, "view.goto1", ""), "Detail");
app.view_mut().unwrap().zoom = 0.5;
app.run("view.goto1", json!({})).unwrap();
let v = app.view().unwrap();
assert_eq!((v.zoom, v.center.x, v.center.y), (3.0, 120.0, 80.0));
// Unused slots stay out of the menu listing agents see.
assert!(!menu_entries(&app).iter().any(|e| e.command.as_deref() == Some("view.goto2")));
}
/// Effect › 3D and Materials › 3D (Classic) › Extrude & Bevel (Classic)… opens its effect dialog,
/// after Materials…, and nowhere else.
#[test]
fn classic_extrude_bevel_is_in_the_3d_classic_submenu() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let entries = menu_entries(&app);
let classic: Vec<_> = entries.iter().filter(|e| e.params.get("effect").and_then(Value::as_str) == Some("threeD.classicExtrude")).collect();
assert_eq!(classic.len(), 1, "listed once");
let e = classic[0];
assert_eq!(e.path, ["Effect", "3D and Materials", "3D (Classic)"]);
assert_eq!((e.label.as_str(), e.command.as_deref()), ("Extrude & Bevel (Classic)…", Some("effect.dialog")));
let at = |label: &str| entries.iter().position(|x| x.label == label && x.path.get(1).is_some_and(|p| p == "3D and Materials"));
assert!(at("Materials…").unwrap() < at("Extrude & Bevel (Classic)…").unwrap());
}
/// Effect › 3D and Materials › 3D (Classic) › Revolve (Classic)… opens its effect dialog, after
/// Extrude & Bevel (Classic)…, and nowhere else.
#[test]
fn classic_revolve_is_in_the_3d_classic_submenu() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let entries = menu_entries(&app);
let classic: Vec<_> = entries.iter().filter(|e| e.params.get("effect").and_then(Value::as_str) == Some("threeD.classicRevolve")).collect();
assert_eq!(classic.len(), 1, "listed once");
let e = classic[0];
assert_eq!(e.path, ["Effect", "3D and Materials", "3D (Classic)"]);
assert_eq!((e.label.as_str(), e.command.as_deref()), ("Revolve (Classic)…", Some("effect.dialog")));
let at = |label: &str| entries.iter().position(|x| x.label == label && x.path.get(1).is_some_and(|p| p == "3D and Materials"));
assert!(at("Extrude & Bevel (Classic)…").unwrap() < at("Revolve (Classic)…").unwrap());
}
/// Effect › 3D and Materials › 3D (Classic) › Rotate (Classic)… opens its effect dialog, after
/// Revolve (Classic)…, and nowhere else.
#[test]
fn classic_rotate_is_in_the_3d_classic_submenu() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let entries = menu_entries(&app);
let classic: Vec<_> = entries.iter().filter(|e| e.params.get("effect").and_then(Value::as_str) == Some("threeD.classicRotate")).collect();
assert_eq!(classic.len(), 1, "listed once");
let e = classic[0];
assert_eq!(e.path, ["Effect", "3D and Materials", "3D (Classic)"]);
assert_eq!((e.label.as_str(), e.command.as_deref()), ("Rotate (Classic)…", Some("effect.dialog")));
let at = |label: &str| entries.iter().position(|x| x.label == label && x.path.get(1).is_some_and(|p| p == "3D and Materials"));
assert!(at("Revolve (Classic)…").unwrap() < at("Rotate (Classic)…").unwrap());
}
/// A document's 25 views are all listed at the bottom of the View menu, by name, and the last
/// one brings back its zoom, centre and rotation after the view changed.
#[test]
fn every_saved_view_is_listed_at_the_bottom_of_the_view_menu() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
for i in 1..=25 {
{
let v = app.view_mut().unwrap();
(v.zoom, v.center, v.rotation) = (i as f64 / 4.0, vectorcraft_geom::Point::new(10.0 * i as f64, -5.0 * i as f64), i as f64);
}
invoke(&mut app, "view.saved.new", json!({}));
crate::dialogs::confirm(&mut app).unwrap();
}
assert_eq!(app.session.active().unwrap().doc.views.len(), 25);
let entries = menu_entries(&app);
let at = |id: &str| entries.iter().position(|e| e.command.as_deref() == Some(id));
let (edit, first, last) = (at("view.saved.edit").unwrap(), at("view.goto1").unwrap(), at("view.goto25").unwrap());
assert!(edit < first && last == first + 24, "listed in order after Edit Views…");
assert!(enabled(&app, "view.goto25"));
assert_eq!(display_label(&app, "view.goto25", "Saved View"), "View 25");
// The document's 26th view is refused, so there is never one the menu leaves out.
invoke(&mut app, "view.saved.new", json!({}));
assert!(crate::dialogs::confirm(&mut app).is_err());
app.ui.dialog = None;
{
let v = app.view_mut().unwrap();
(v.zoom, v.center, v.rotation) = (1.0, vectorcraft_geom::Point::new(0.0, 0.0), 0.0);
}
assert_eq!(app.run("view.goto25", json!({})).unwrap()["name"], "View 25");
let v = app.view().unwrap();
assert_eq!((v.zoom, v.center.x, v.center.y, v.rotation), (6.25, 250.0, -125.0, 25.0));
}
/// Edit Views… is off without a saved view and opens its list on the document's views, the
/// way Edit Selection… does.
#[test]
fn edit_views_opens_its_dialog_on_the_saved_views() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
assert!(!enabled(&app, "view.saved.edit"));
invoke(&mut app, "view.saved.edit", json!({}));
assert!(app.ui.dialog.is_none());
assert!(app.ui.status.contains("No saved views"), "{}", app.ui.status);
app.run("view.saved.new", json!({"name": "Detail"})).unwrap();
app.run("view.saved.new", json!({"name": "Page"})).unwrap();
assert!(enabled(&app, "view.saved.edit"));
invoke(&mut app, "view.saved.edit", json!({}));
let d = app.ui.dialog.clone().expect("Edit Views dialog");
assert_eq!((d.kind.as_str(), d.str("orig1"), d.str("name1")), ("editViews", "Page".into(), "Page".into()));
// Deleting a view takes its slot out of the menu.
let mut d = d;
d.fields.insert("deleted0".into(), json!(true));
app.ui.dialog = Some(d);
crate::dialogs::confirm(&mut app).unwrap();
assert_eq!(dynamic_label(&app, "view.goto1", ""), "Page");
assert!(shown_state(&app, "view.goto2", &Value::Null).is_none());
}
fn app_with_a_rectangle() -> VectorcraftApp {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
app
}
/// Edit › Undo and Edit › Redo name a step named after a style as the History panel lists it:
/// the template's translation with the style's name in it.
#[test]
fn undo_and_redo_name_a_style_step_around_the_style_name() {
let mut app = app_with_a_rectangle();
let text = app.run("text.create", json!({"x": 0, "y": 40, "text": "Hello"})).unwrap()["id"].clone();
app.run("charStyle.new", json!({"name": "Brush"})).unwrap();
app.run("charStyle.apply", json!({"name": "Brush", "id": text})).unwrap();
let ja = crate::i18n::Lang::from_code("ja").expect("ja registered");
crate::i18n::set_current(ja);
let step = |template: &str| {
let applied = crate::i18n::fmt(crate::i18n::tr(ja, "Apply {name}"), &[("name", "Brush")]);
crate::i18n::fmt(crate::i18n::tr(ja, template), &[("name", &applied)])
};
assert_eq!(display_label(&app, "edit.undo", "Undo"), step("Undo {name}"));
app.run("edit.undo", json!({})).unwrap();
assert_eq!(display_label(&app, "edit.redo", "Redo"), step("Redo {name}"));
crate::i18n::set_current(crate::i18n::Lang::EN);
assert_eq!(display_label(&app, "edit.redo", "Redo"), "Redo Apply Brush");
}
#[test]
fn save_selection_asks_for_a_name() {
let mut app = app_with_a_rectangle();
invoke(&mut app, "select.save", json!({}));
let d = app.ui.dialog.clone().expect("Save Selection dialog");
assert_eq!(
(d.kind.as_str(), d.str("__command"), d.str("__label"), d.str("name")),
("command", "select.save".into(), "Save Selection".into(), "Selection 1".into())
);
// OK saves under the name typed.
let mut d = d;
d.fields.insert("name".into(), json!("Logo"));
app.ui.dialog = Some(d);
crate::dialogs::confirm(&mut app).unwrap();
assert_eq!(app.run("select.savedList", json!({})).unwrap(), json!(["Logo"]));
// The next one starts from the first free name.
invoke(&mut app, "select.save", json!({}));
assert_eq!(app.ui.dialog.as_ref().map(|d| d.str("name")), Some("Selection 1".into()));
}
#[test]
fn saved_selections_are_listed_at_the_bottom_of_the_select_menu() {
let mut app = app_with_a_rectangle();
app.run("shape.ellipse", json!({"x": 40, "y": 0, "width": 10, "height": 10})).unwrap();
// Nothing saved: no slot is listed or enabled.
assert!(!enabled(&app, "select.recall1"));
assert!(!menu_entries(&app).iter().any(|e| e.command.as_deref() == Some("select.recall1")));
app.run("select.save", json!({"name": "Ellipse"})).unwrap();
app.run("select.none", json!({})).unwrap();
app.run("select.all", json!({})).unwrap();
app.run("select.save", json!({"name": "Everything"})).unwrap();
assert!(enabled(&app, "select.recall1") && enabled(&app, "select.recall2") && !enabled(&app, "select.recall3"));
assert_eq!(dynamic_label(&app, "select.recall2", "Saved Selection"), "Everything");
// A name is shown as it is, not translated.
assert_eq!(display_label(&app, "select.recall2", "Saved Selection"), "Everything");
assert!(menu_entries(&app).iter().any(|e| e.command.as_deref() == Some("select.recall2")));
assert!(!menu_entries(&app).iter().any(|e| e.command.as_deref() == Some("select.recall3")));
// Choosing one selects its objects again.
app.run("select.none", json!({})).unwrap();
let r = app.run("select.recall2", json!({})).unwrap();
assert!(r["count"].as_u64().unwrap() >= 1);
assert_eq!(app.session.active().unwrap().selection.len(), 2);
// A deleted selection's slot leaves the menus.
app.run("select.editSaved", json!({"name": "Ellipse", "delete": true})).unwrap();
assert!(!enabled(&app, "select.recall2"));
assert!(shown_state(&app, "select.recall2", &Value::Null).is_none());
assert!(shown_state(&app, "select.recall1", &Value::Null).is_some());
}
#[test]
fn update_selection_follows_save_selection_and_needs_a_recall() {
let mut app = app_with_a_rectangle();
let entries = menu_entries(&app);
let at = |id: &str| entries.iter().position(|e| e.command.as_deref() == Some(id));
assert_eq!(at("select.update").map(|i| i - 1), at("select.save"));
app.run("select.save", json!({"name": "Box"})).unwrap();
assert!(!enabled(&app, "select.update"));
app.run("shape.ellipse", json!({"x": 40, "y": 0, "width": 10, "height": 10})).unwrap();
app.run("select.recall1", json!({})).unwrap();
assert!(enabled(&app, "select.update"));
app.run("select.all", json!({})).unwrap();
invoke(&mut app, "select.update", json!({}));
app.run("select.none", json!({})).unwrap();
assert_eq!(app.run("select.recall1", json!({})).unwrap()["count"], 2);
}
#[test]
fn select_same_link_block_series_selects_a_thread_from_the_menu() {
let mut app = app_with_a_rectangle();
let entry = menu_entries(&app).into_iter().find(|e| e.command.as_deref() == Some("select.same.linkBlockSeries")).expect("menu entry");
assert_eq!((entry.path, entry.label.as_str()), (vec!["Select".to_string(), "Same".to_string()], "Link Block Series"));
// A rectangle selected: no type, so the item is off.
assert!(!enabled(&app, "select.same.linkBlockSeries"));
let frame = |app: &mut VectorcraftApp, x: i32| {
app.run("text.create", json!({"x": x, "y": 40, "text": "words ".repeat(40), "area": {"width": 60, "height": 30}})).unwrap()["id"].clone()
};
let (a, b) = (frame(&mut app, 0), frame(&mut app, 100));
app.run("select.set", json!({"ids": [a.clone(), b.clone()]})).unwrap();
app.run("text.thread.create", json!({})).unwrap();
app.run("select.set", json!({"ids": [b.clone()]})).unwrap();
assert!(enabled(&app, "select.same.linkBlockSeries"));
invoke(&mut app, "select.same.linkBlockSeries", json!({}));
let ids: Vec<u64> = app.session.active().unwrap().selection.objects.iter().map(|i| i.0).collect();
assert_eq!(json!(ids), json!([a, b]));
}
#[test]
fn select_same_text_fill_and_stroke_color_follows_text_stroke_color_in_the_menu() {
let mut app = app_with_a_rectangle();
let entries = menu_entries(&app);
let at = |id: &str| entries.iter().position(|e| e.command.as_deref() == Some(id));
let entry = at("select.same.textFillAndStrokeColor").map(|i| &entries[i]).expect("menu entry");
assert_eq!((entry.path.clone(), entry.label.as_str()), (vec!["Select".to_string(), "Same".to_string()], "Text Fill & Stroke Color"));
assert_eq!(at("select.same.textStrokeColor").map(|i| i + 1), at("select.same.textFillAndStrokeColor"));
let text = |app: &mut VectorcraftApp, y: i32, fill: &str, stroke: &str| {
let id = app.run("text.create", json!({"x": 0, "y": y, "text": "type"})).unwrap()["id"].clone();
app.run("text.setRangeStyle", json!({"id": id.clone(), "start": 0, "end": 4, "fill": fill, "stroke": stroke})).unwrap();
id
};
let a = text(&mut app, 40, "#ff0000", "#0000ff");
let b = text(&mut app, 80, "#ff0000", "#0000ff");
let _ = text(&mut app, 120, "#ff0000", "#00ff00");
app.run("select.set", json!({"ids": [a.clone()]})).unwrap();
invoke(&mut app, "select.same.textFillAndStrokeColor", json!({}));
let ids: Vec<u64> = app.session.active().unwrap().selection.objects.iter().map(|i| i.0).collect();
assert_eq!(json!(ids), json!([a, b]));
}
#[test]
fn edit_selection_opens_its_dialog_on_the_saved_selections() {
let mut app = app_with_a_rectangle();
// Nothing saved yet: the item is off, and invoking it (palette, shortcut) only says so.
assert!(!enabled(&app, "select.editSaved"));
invoke(&mut app, "select.editSaved", json!({}));
assert!(app.ui.dialog.is_none());
assert!(app.ui.status.contains("No saved selections"), "{}", app.ui.status);
app.run("select.save", json!({"name": "Logo"})).unwrap();
assert!(enabled(&app, "select.editSaved"));
invoke(&mut app, "select.editSaved", json!({}));
let d = app.ui.dialog.clone().expect("Edit Selection dialog");
assert_eq!((d.kind.as_str(), d.str("orig0"), d.str("name0")), (crate::dialogs::edit_selection::KIND, "Logo".into(), "Logo".into()));
}
#[test]
fn recent_fonts_and_corner_widget_toggle() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let fams = vectorcraft_text::FontDb::global().families();
let (a, b) = (fams[0].clone(), fams[fams.len() - 1].clone());
app.run("text.create", json!({"x": 10, "y": 10, "text": "Hi"})).unwrap();
app.run("text.setStyle", json!({"font": a})).unwrap();
app.run("text.setStyle", json!({"font": b})).unwrap();
assert_eq!(app.ui.recent_fonts, vec![b.clone(), a.clone()]);
assert_eq!(dynamic_label(&app, "type.recentFont2", "Recent Font"), a);
assert!(enabled(&app, "type.recentFont2") && !enabled(&app, "type.recentFont3"));
app.run("type.recentFont2", json!({})).unwrap();
assert_eq!(app.ui.recent_fonts[0], a);
assert_eq!(dynamic_label(&app, "view.cornerWidget", ""), "Hide Corner Widget");
app.run("view.cornerWidget", json!({})).unwrap();
assert_eq!(dynamic_label(&app, "view.cornerWidget", ""), "Show Corner Widget");
}
/// Hide Shape Widgets (`view.shapeWidgets`, the shape tools' Control bar button) flips its label and
/// the setting, `on` sets it, a non-boolean `on` is an error that leaves it, the setting is saved
/// with the interface state, and state saved before the setting existed loads with the widgets on.
#[test]
fn shape_widgets_command_toggles_and_takes_on() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
assert!(app.ui.view.shape_widgets, "on by default");
assert_eq!(dynamic_label(&app, "view.shapeWidgets", ""), "Hide Shape Widgets");
assert_eq!(app.run("view.shapeWidgets", json!({})).unwrap(), json!(false));
assert_eq!(dynamic_label(&app, "view.shapeWidgets", ""), "Show Shape Widgets");
assert!(!app.view_info().shape_widgets);
assert_eq!(app.run("view.shapeWidgets", json!({"on": false})).unwrap(), json!(false));
assert!(app.run("view.shapeWidgets", json!({"on": "yes"})).is_err());
assert!(!app.ui.view.shape_widgets, "a bad `on` changes nothing");
assert_eq!(app.run("view.shapeWidgets", json!({"on": true})).unwrap(), json!(true));
assert!(app.view_info().shape_widgets);
app.ui.view.shape_widgets = false;
let mut saved = serde_json::to_value(&app.ui).unwrap();
let loaded: crate::UiState = serde_json::from_value(saved.clone()).unwrap();
assert!(!loaded.view.shape_widgets, "the setting is saved");
saved["view"].as_object_mut().unwrap().remove("shape_widgets");
let older: crate::UiState = serde_json::from_value(saved).unwrap();
assert!(older.view.shape_widgets, "older saved state shows the widgets");
assert!(UI_COMMANDS.iter().any(|c| c.0 == "view.shapeWidgets" && c.2.is_empty()), "no default key");
}
/// View › Precise Cursors has no menu item or default key, but the command (assignable in Keyboard Shortcuts)
/// writes General › Use Precise Cursors, the value the dialog and the saved preferences read.
#[test]
fn precise_cursors_command_toggles_the_preference() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
assert!(!app.session.prefs.use_precise_cursors);
assert_eq!(app.run("view.preciseCursors", json!({})).unwrap(), json!(true));
assert!(app.session.prefs.use_precise_cursors);
assert_eq!(app.ui.engine_prefs["usePreciseCursors"], json!(true), "saved with the UI state");
assert!(UI_COMMANDS.iter().any(|c| c.0 == "view.preciseCursors" && c.2.is_empty()), "assignable, no default key");
assert_eq!(app.run("view.preciseCursors", json!({})).unwrap(), json!(false));
assert!(!app.session.prefs.use_precise_cursors);
}
/// The command is listed in Edit › Keyboard Shortcuts without a key and takes one the user types; with the
/// key it is the command that runs.
#[test]
fn precise_cursors_command_is_listed_and_assignable_in_the_shortcut_editor() {
use crate::shortcut_editor as ed;
let e = ed::entry("view.preciseCursors").expect("listed in the editor");
assert_eq!((e.label.as_str(), e.group.as_str(), e.is_tool), ("Use Precise Cursors", "View", false));
assert_eq!(ed::default_of("view.preciseCursors"), None, "no default key");
let mut overrides = craft_keymap::Overrides::new();
assert_eq!(ed::effective_in(&overrides, "view.preciseCursors"), None);
assert_eq!(ed::assign(&mut overrides, "view.preciseCursors", Some("Cmd+Alt+Shift+Q"), false), Ok(vec![]));
let chord = ed::effective_in(&overrides, "view.preciseCursors").expect("assigned");
assert_eq!(ed::normalize(&chord), ed::normalize("Cmd+Alt+Shift+Q"));
// A key another command holds is refused, so the new command can't take it over silently.
assert!(ed::assign(&mut overrides, "view.preciseCursors", Some("Cmd+Alt+Shift+P"), false).is_err());
assert_eq!(ed::assign(&mut overrides, "view.preciseCursors", None, false), Ok(vec![]));
assert_eq!(ed::effective_in(&overrides, "view.preciseCursors"), None, "cleared again");
}
/// The command is a preference, not an edit: no undo step, no unsaved changes, with a document open.
#[test]
fn precise_cursors_command_is_not_an_edit() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let steps = |app: &VectorcraftApp| {
let st = app.session.active().unwrap();
(st.history.undo.len(), st.history.redo.len(), st.is_dirty())
};
let before = steps(&app);
assert!(!before.2);
app.run("view.preciseCursors", json!({})).unwrap();
assert!(app.session.prefs.use_precise_cursors);
assert_eq!(steps(&app), before);
}
/// Selection & Anchor Display › Zoom to Selection (#394): Zoom In and Zoom Out bring the
/// selection to the middle; off, they keep the view's centre.
#[test]
fn zoom_to_selection_centres_the_selection() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 20, "width": 40, "height": 20})).unwrap();
let center = |app: &VectorcraftApp| app.view().unwrap().center;
let start = center(&app);
app.run("prefs.set", json!({"key": "zoomToSelection", "value": false})).unwrap();
app.run("view.zoomIn", json!({})).unwrap();
assert_eq!(center(&app), start, "off: the view's centre stays");
app.run("prefs.set", json!({"key": "zoomToSelection", "value": true})).unwrap();
app.run("view.zoomOut", json!({})).unwrap();
assert_eq!(center(&app), vectorcraft_geom::Point::new(30.0, 30.0), "on: the selection's centre");
}
/// Preferences › Type › Number of Recent Fonts (#394): Type › Recent Fonts lists that many.
#[test]
fn number_of_recent_fonts_sets_how_many_are_listed() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
app.ui.recent_fonts = (1..=15).map(|i| format!("Font {i}")).collect();
let listed = |app: &VectorcraftApp| RECENT_FONT_IDS.iter().filter(|id| enabled(app, id)).count();
assert_eq!(listed(&app), 10, "10 by default");
for n in [15, 2] {
app.run("prefs.set", json!({"key": "recentFontsCount", "value": n})).unwrap();
assert_eq!(listed(&app), n);
}
assert_eq!(dynamic_label(&app, "type.recentFont2", "Recent Font"), "Font 2");
assert!(app.run("type.recentFont3", json!({})).is_err(), "past the count");
}
#[test]
fn recent_files_track_opens_and_saves() {
let dir = std::env::temp_dir().join(format!("dc-recent-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let mut app = VectorcraftApp::new(
vectorcraft_engine::Session::new(),
crate::Services {
read: Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string()))),
write: Some(Box::new(|p: &str, b: &[u8]| std::fs::write(p, b).map_err(|e| e.to_string()))),
..Default::default()
},
);
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
let (a, b) = (dir.join("a.vectorcraft"), dir.join("b.vectorcraft"));
for p in [&a, &b, &a] {
app.run("file.saveAs", json!({"path": p.to_string_lossy()})).unwrap();
}
assert_eq!(app.ui.recent_files, [a.to_string_lossy(), b.to_string_lossy()]);
assert_eq!(dynamic_label(&app, "file.openRecent2", ""), "b.vectorcraft");
assert!(enabled(&app, "file.openRecent2") && !enabled(&app, "file.openRecent3"));
app.run("file.openRecent2", json!({})).unwrap();
assert_eq!(app.session.documents().len(), 2);
assert_eq!(app.ui.recent_files[0], b.to_string_lossy(), "reopening moves it to the top");
app.run("file.clearRecent", json!({})).unwrap();
assert!(app.ui.recent_files.is_empty() && app.run("file.openRecent1", json!({})).is_err());
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn every_bound_menu_command_exists() {
fn walk(items: &[Item], bad: &mut Vec<String>) {
for it in items {
match it {
Item::Cmd(_, id, _)
if vectorcraft_engine::find_command(id).is_none()
&& !UI_COMMANDS.iter().any(|c| c.0 == *id)
&& !id.starts_with("object.path.") =>
{
bad.push(id.to_string());
}
Item::Sub(_, ch) => walk(ch, bad),
_ => {}
}
}
}
let mut bad = vec![];
for (_, items) in menu_tree() {
walk(&items, &mut bad);
}
assert!(bad.is_empty(), "menu items bound to unknown commands: {bad:?}");
}
#[test]
fn shortcut_pretty() {
if cfg!(target_os = "macos") {
assert_eq!(pretty_shortcut("Cmd+Shift+]"), "⇧⌘]");
assert_eq!(pretty_shortcut("Cmd+Alt+2"), "⌥⌘2");
}
assert_eq!(pretty_shortcut(""), "");
}
/// #543: Object › Image Trace › Make and Make and Expand trace with the Default preset at once,
/// with no form asking for a preset's name.
#[test]
fn image_trace_make_traces_with_the_default_preset() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
for cmd in ["imageTrace.make", "imageTrace.makeAndExpand"] {
let e = menu_entries(&app).into_iter().find(|e| e.command.as_deref() == Some(cmd)).unwrap();
assert_eq!(e.path, ["Object", "Image Trace"]);
assert_eq!(click_target(&e.label, cmd, &e.params), (cmd.to_string(), json!({"preset": "Default"})), "{}", e.label);
}
}
#[test]
fn expand_appearance_is_an_object_menu_item_only() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let paths: Vec<Vec<String>> =
menu_entries(&app).into_iter().filter(|e| e.command.as_deref() == Some("effect.expandAppearance")).map(|e| e.path).collect();
assert_eq!(paths, [vec!["Object".to_string()]]);
}
/// Object › Distribute follows Object › Align and lists the Align panel's Distribute Objects and
/// Distribute Spacing buttons, each item running the button's command: dimmed with nothing
/// selected, spacing three objects evenly, and with a key object sending the Distribute Spacing value.
#[test]
fn object_distribute_runs_the_distribute_buttons() {
let object = menu_tree().into_iter().find(|(t, _)| *t == "Object").map(|(_, items)| items).unwrap_or_default();
let subs: Vec<&str> = object.iter().filter_map(|it| if let Item::Sub(l, _) = it { Some(*l) } else { None }).collect();
let align = subs.iter().position(|l| *l == "Align").unwrap_or_else(|| panic!("Object › Align: {subs:?}"));
assert_eq!(subs.get(align + 1), Some(&"Distribute"), "{subs:?}");
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
let items = |app: &VectorcraftApp| -> Vec<MenuEntry> { menu_entries(app).into_iter().filter(|e| e.path == ["Object", "Distribute"]).collect() };
let listed: Vec<(String, Option<String>)> = items(&app).into_iter().map(|e| (e.label, e.command)).collect();
let expected: Vec<(String, Option<String>)> = [
("Horizontal Distribute Left", "align.distributeHorizontalLeft"),
("Horizontal Distribute Center", "align.distributeHorizontalCenter"),
("Horizontal Distribute Right", "align.distributeHorizontalRight"),
("Vertical Distribute Top", "align.distributeVerticalTop"),
("Vertical Distribute Center", "align.distributeVerticalCenter"),
("Vertical Distribute Bottom", "align.distributeVerticalBottom"),
("Horizontal Distribute Space", "align.distributeHorizontalSpace"),
("Vertical Distribute Space", "align.distributeVerticalSpace"),
]
.into_iter()
.map(|(l, id)| (l.to_string(), Some(id.to_string())))
.collect();
assert_eq!(listed, expected);
assert!(items(&app).iter().all(|e| !e.enabled), "nothing selected");
let ids: Vec<Value> = [0, 30, 100]
.into_iter()
.map(|x| app.run("shape.rectangle", json!({"x": x, "y": 10, "width": 10, "height": 10})).unwrap()["id"].clone())
.collect();
app.run("select.set", json!({"ids": ids})).unwrap();
let lefts = |app: &VectorcraftApp| -> Vec<f64> {
let doc = &app.session.active().unwrap().doc;
ids.iter().map(|id| doc.node(vectorcraft_doc::NodeId(id.as_u64().unwrap())).unwrap().geometric_bounds().unwrap().x0).collect()
};
let click = |app: &mut VectorcraftApp, label: &str| {
let e = items(app).into_iter().find(|e| e.label == label).unwrap_or_else(|| panic!("{label}"));
assert!(e.enabled, "{label}");
let (id, p) = click_target(&e.label, e.command.as_deref().unwrap_or_default(), &e.params);
invoke(app, &id, p);
};
click(&mut app, "Horizontal Distribute Left");
assert_eq!(lefts(&app), [0.0, 50.0, 100.0], "{}", app.ui.status);
app.ui.align_spacing = 5.0;
app.run("select.key", json!({"id": ids[0]})).unwrap();
click(&mut app, "Horizontal Distribute Space");
assert_eq!(lefts(&app), [0.0, 15.0, 30.0], "{}", app.ui.status);
}
/// Isolation keeps the Lock and Hide actions available for selected members.
#[test]
fn lock_and_hide_menus_are_enabled_in_isolation_mode() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({})).unwrap();
let a = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap()["id"].clone();
let b = app.run("shape.rectangle", json!({"x": 80, "y": 10, "width": 50, "height": 50})).unwrap()["id"].clone();
app.run("select.none", json!({})).unwrap();
let lock_unselected = |app: &VectorcraftApp| crate::menus::enabled(app, "object.lock.unselected");
assert!(!lock_unselected(&app), "nothing selected");
app.run("select.set", json!({"ids": [a, b.clone()]})).unwrap();
assert!(lock_unselected(&app), "selection present");
let g = app.run("object.group", json!({})).unwrap()["id"].clone();
let lock_and_hide: Vec<String> = menu_entries(&app)
.into_iter()
.filter(|e| {
let path: Vec<&str> = e.path.iter().map(String::as_str).collect();
matches!(path[..], ["Object", "Lock" | "Hide"]) || path == ["Object"] && matches!(e.label.as_str(), "Unlock All" | "Show All")
})
.filter_map(|e| e.command)
.collect();
assert_eq!(
lock_and_hide,
[
"object.lock",
"object.lock.above",
"object.lock.otherLayers",
"object.unlockAll",
"object.hide",
"object.hide.above",
"object.hide.otherLayers",
"object.hide.unselected",
"object.showAll"
]
);
let shown = |app: &VectorcraftApp| -> Vec<bool> {
let entries = menu_entries(app);
lock_and_hide
.iter()
.chain([&"object.group".to_string()])
.map(|id| entries.iter().any(|e| e.command.as_ref() == Some(id) && e.enabled))
.collect()
};
app.run("object.isolate", json!({"id": g.clone()})).unwrap();
app.run("select.set", json!({"ids": [b]})).unwrap();
assert_eq!(shown(&app), [true; 10], "in isolation mode");
assert!(lock_unselected(&app), "shortcut command remains enabled in isolation");
assert!(crate::menus::enabled(&app, "object.hide.unselected"), "Hide Unselected remains enabled in isolation");
let chord = crate::shortcut_editor::default_of("object.hide.unselected").expect("default Hide Unselected shortcut");
assert_eq!(crate::shortcut_editor::normalize(chord), crate::shortcut_editor::normalize("Cmd+Alt+Shift+3"));
app.run("object.exitIsolation", json!({})).unwrap();
app.run("select.set", json!({"ids": [g]})).unwrap();
assert_eq!(shown(&app), [true; 10], "after Exit Isolation Mode");
}
#[test]
fn menus_are_as_wide_as_their_items() {
// Items size the popup to the widest label and shortcut instead of the widest a menu may be.
let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0));
let tree = menu_tree();
let (_, file) = tree.iter().find(|(t, _)| *t == "File").unwrap();
let id = egui::Id::unique("test-menu");
for _ in 0..3 {
let input = egui::RawInput { screen_rect: Some(screen), ..Default::default() };
let mut out = ctx.run_ui(input, |ui| {
egui::Area::new(id).show(ui.ctx(), |ui| {
egui::containers::menu::menu_style(ui.style_mut());
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| menu_body(&app, ui, file, &mut None));
});
});
out.textures_delta.clear();
}
let w = ctx.memory(|m| m.area_rect(id)).unwrap().width();
assert!((230.0..340.0).contains(&w), "File menu is {w} pt wide");
}
#[test]
fn long_menus_scroll_inside_a_short_window() {
// The Window menu is taller than a 600 pt window: it stops above the bottom edge and
// scrolls instead of running off screen.
let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let tree = menu_tree();
let (_, window) = tree.iter().find(|(t, _)| *t == "Window").unwrap();
let id = egui::Id::unique("test-long-menu");
let rect = |height: f32| {
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, height));
for _ in 0..3 {
let input = egui::RawInput { screen_rect: Some(screen), ..Default::default() };
let mut out = ctx.run_ui(input, |ui| {
egui::Area::new(id).fixed_pos(egui::pos2(300.0, 30.0)).show(ui.ctx(), |ui| {
egui::containers::menu::menu_style(ui.style_mut());
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| menu_body(&app, ui, window, &mut None));
});
});
out.textures_delta.clear();
}
ctx.memory(|m| m.area_rect(id)).unwrap()
};
let short = rect(600.0);
assert!(short.bottom() <= 600.0, "Window menu ends at {} in a 600 pt window", short.bottom());
// With room to spare it shows whole, taller than the short window allowed.
let tall = rect(3000.0);
assert!(tall.height() > short.height() + 100.0, "{} vs {}", tall.height(), short.height());
assert!(tall.bottom() < 3000.0);
}
/// Object › Unlock All and Object › Show All clicked with Shift+Alt held run with
/// `scope: "group"`; clicked without them, or with only one of the two, they run on the whole
/// document as before.
#[test]
fn unlock_all_and_show_all_clicked_with_shift_alt_act_within_the_group() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let tree = menu_tree();
let (_, object) = tree.iter().find(|(t, _)| *t == "Object").unwrap();
let id = egui::Id::unique("test-object-menu");
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 3000.0));
let frame = |events: Vec<egui::Event>, modifiers: egui::Modifiers| {
let mut clicked = None;
let events = std::iter::once(egui::Event::ModifiersChanged(modifiers)).chain(events).collect();
let input = egui::RawInput { screen_rect: Some(screen), events, ..Default::default() };
let mut out = ctx.run_ui(input, |ui| {
egui::Area::new(id).fixed_pos(egui::pos2(0.0, 0.0)).show(ui.ctx(), |ui| {
egui::containers::menu::menu_style(ui.style_mut());
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| menu_body(&app, ui, object, &mut clicked));
});
});
out.textures_delta.clear();
(clicked, out.shapes)
};
// Where the menu draws `label`.
fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
match s {
egui::Shape::Text(t) if t.galley.text() == label => Some(t.pos + t.galley.rect.center().to_vec2()),
egui::Shape::Vec(v) => v.iter().find_map(|s| find(s, label)),
_ => None,
}
}
let click = |label: &str, modifiers: egui::Modifiers| {
let (_, shapes) = frame(vec![], Default::default());
let at = shapes.iter().find_map(|c| find(&c.shape, label)).unwrap_or_else(|| panic!("{label} is not in the Object menu"));
let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers };
frame(vec![egui::Event::PointerMoved(at)], modifiers);
frame(vec![button(true)], modifiers);
frame(vec![button(false)], modifiers).0
};
frame(vec![], Default::default());
let shift_alt = egui::Modifiers { shift: true, alt: true, ..Default::default() };
let group = json!({"scope": "group"});
for (label, command) in [("Unlock All", "object.unlockAll"), ("Show All", "object.showAll")] {
assert_eq!(click(label, shift_alt), Some((command.to_string(), group.clone())), "{label} with Shift+Alt");
for held in [egui::Modifiers::NONE, egui::Modifiers::SHIFT, egui::Modifiers::ALT] {
assert_eq!(click(label, held), Some((command.to_string(), json!({}))), "{label} with {held:?}");
}
}
}
/// #4116: Window › New Window is enabled with a document open and opens a second view of it; with
/// no document open it is greyed out.
#[test]
fn new_window_opens_a_view_of_the_current_document() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
assert!(!enabled(&app, "window.newWindow"), "no document to open a window on");
assert_eq!(app.run("window.newWindow", json!({})).unwrap_err(), "no document open");
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
assert!(enabled(&app, "window.newWindow"));
assert_eq!(app.run("window.newWindow", json!({})).unwrap(), json!({"index": 0, "view": 2}));
assert_eq!(app.session.documents().len(), 1, "the same document, in a second window");
}
/// #4143: Window menu panels and panel submenus are listed in alphabetical order according to the
/// active interface language (e.g. French), rather than staying frozen in English alphabetical order.
#[test]
fn window_menu_panels_are_sorted_alphabetically_in_active_language() {
use crate::i18n::{Lang, current, name_sort_key, set_current, tr, tr_id};
let prev = current();
// 1. In English: panels between separator 2 and 3 are alphabetical.
set_current(Lang::EN);
let tree = menu_tree();
let (_, window) = tree.iter().find(|(t, _)| *t == "Window").unwrap();
let seps: Vec<usize> = window.iter().enumerate().filter(|(_, it)| matches!(it, Item::Sep)).map(|(i, _)| i).collect();
assert!(seps.len() >= 3, "Window menu should have at least 3 separators");
let panels = &window[seps[1] + 1..seps[2]];
let item_display = |it: &Item, lang: Lang| -> String {
match it {
Item::Cmd(l, id, _) => tr_id(lang, id, l).to_string(),
Item::Sub(l, _) | Item::Todo(l, _) | Item::Header(l) => tr(lang, l).to_string(),
Item::Sep => String::new(),
}
};
let en_keys: Vec<String> = panels.iter().map(|it| name_sort_key(&item_display(it, Lang::EN))).collect();
assert!(en_keys.windows(2).all(|w| w[0] <= w[1]), "English panels must be alphabetical: {en_keys:?}");
// 2. In French: panels are sorted alphabetically by their French names.
let fr = Lang::from_code("fr").unwrap();
set_current(fr);
let tree_fr = menu_tree();
let (_, window_fr) = tree_fr.iter().find(|(t, _)| *t == "Window").unwrap();
let seps_fr: Vec<usize> = window_fr.iter().enumerate().filter(|(_, it)| matches!(it, Item::Sep)).map(|(i, _)| i).collect();
let panels_fr = &window_fr[seps_fr[1] + 1..seps_fr[2]];
let fr_labels: Vec<String> = panels_fr.iter().map(|it| item_display(it, fr)).collect();
let fr_keys: Vec<String> = fr_labels.iter().map(|l| name_sort_key(l)).collect();
assert!(fr_keys.windows(2).all(|w| w[0] <= w[1]), "French panels must be alphabetical: {fr_labels:?}");
// Specific French placements:
// Calques (Layers) is under C, Plans de travail (Artboards) is under P, Nuancier (Swatches) is under N.
let pos = |name: &str| fr_labels.iter().position(|l| l == name).unwrap_or_else(|| panic!("missing {name} in {fr_labels:?}"));
assert!(pos("Aspect") < pos("Calques"), "Aspect before Calques");
assert!(pos("Calques") < pos("Dégradé"), "Calques before Dégradé");
assert!(pos("Nuancier") < pos("Plans de travail"), "Nuancier before Plans de travail");
assert!(pos("Plans de travail") < pos("Texte"), "Plans de travail before Texte");
// 3. Type submenu is also alphabetical in French.
let type_sub = panels_fr
.iter()
.find_map(|it| match it {
Item::Sub(l, items) if *l == "Type" => Some(items),
_ => None,
})
.unwrap();
let type_labels: Vec<String> = type_sub.iter().map(|it| item_display(it, fr)).collect();
let type_keys: Vec<String> = type_labels.iter().map(|l| name_sort_key(l)).collect();
assert!(type_keys.windows(2).all(|w| w[0] <= w[1]), "Type submenu must be alphabetical: {type_labels:?}");
assert_eq!(type_labels, vec!["Caractère", "Glyphes", "OpenType", "Paragraphe", "Styles de caractère", "Styles de paragraphe", "Tabulations",]);
// 4. In Polish: Łącza (Links) folds to L and sorts before Warstwy and Zmienne.
let pl = Lang::from_code("pl").unwrap();
set_current(pl);
let tree_pl = menu_tree();
let (_, window_pl) = tree_pl.iter().find(|(t, _)| *t == "Window").unwrap();
let seps_pl: Vec<usize> = window_pl.iter().enumerate().filter(|(_, it)| matches!(it, Item::Sep)).map(|(i, _)| i).collect();
let panels_pl = &window_pl[seps_pl[1] + 1..seps_pl[2]];
let pl_labels: Vec<String> = panels_pl.iter().map(|it| item_display(it, pl)).collect();
let pl_keys: Vec<String> = pl_labels.iter().map(|l| name_sort_key(l)).collect();
assert!(pl_keys.windows(2).all(|w| w[0] <= w[1]), "Polish panels must be alphabetical: {pl_labels:?}");
let pos_pl = |name: &str| pl_labels.iter().position(|l| l == name).unwrap_or_else(|| panic!("missing {name} in {pl_labels:?}"));
assert!(pos_pl("Łącza") < pos_pl("Warstwy"), "Łącza before Warstwy");
assert!(pos_pl("Warstwy") < pos_pl("Zmienne"), "Warstwy before Zmienne");
set_current(prev);
}
/// A command reports the same failed valid tool choice as `tool.select`, rather than success
/// with the old tool. The existing failure hook exercises the activation error boundary.
#[test]
fn selection_tools_toggle_propagates_a_failed_valid_choice() {
let failure = "selection tool choice failed";
let mut failures = Vec::new();
for (from, to) in [("selection", "directSelection"), ("directSelection", "selection")] {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
assert!(vectorcraft_tools::tool_info(from).is_some() && vectorcraft_tools::tool_info(to).is_some());
app.run("tool.select", json!({"tool": from})).unwrap();
// The real successful command chooses the other valid selection tool.
assert_eq!(app.run("tool.switchSelectionTools", json!({})).unwrap(), json!({"tool": to}));
app.run("tool.select", json!({"tool": from})).unwrap();
app.ui.touch_drawing_tool = Some("paintbrush".into());
let snapshot = |app: &VectorcraftApp| {
let st = app.session.active().unwrap();
(serde_json::to_value(st.doc.as_ref()).unwrap(), st.selection.clone(), st.history.undo.len(), st.history.redo.len())
};
let before = snapshot(&app);
let groups = app.ui.group_tool.clone();
let drawing = app.ui.touch_drawing_tool.clone();
app.fail_next_tool_choice = Some(failure.into());
let result = app.run("tool.switchSelectionTools", json!({}));
assert!(app.fail_next_tool_choice.is_none(), "the valid activation consumed the failure hook");
assert_eq!(app.session.tool_id(), from, "a failed choice keeps the current tool");
assert_eq!(snapshot(&app), before, "failed choice preserves document, selection and history");
assert_eq!(app.ui.group_tool, groups, "failed choice does not remember the requested tool");
assert_eq!(app.ui.touch_drawing_tool, drawing);
// The hook is one-shot: ordinary success and the return direction still work afterwards.
assert_eq!(app.run("tool.switchSelectionTools", json!({})).unwrap(), json!({"tool": to}));
assert_eq!(app.run("tool.switchSelectionTools", json!({})).unwrap(), json!({"tool": from}));
assert_eq!(snapshot(&app), before, "successful selection toggles do not edit the artwork");
failures.push(result);
}
assert_eq!(failures, vec![Err(failure.to_string()), Err(failure.to_string())], "both failed valid choices must reach the command caller");
}
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.