UI: the Macros dialog offers Trust Scripts for scripts from a file

The Macros dialog that replaces the scripts-only list keeps its Trust
Scripts row (#2178): scripts that came with an opened file are listed as
disabled until the row's button trusts them for the session, and Run
works after it. A test covers the row, the trust and the run, and the
macro page describes it.
This commit is contained in:
prxnvt
2026-10-25 06:48:57 -04:00
parent aa86b0c327
commit 73b0edd085
2 changed files with 36 additions and 0 deletions
+34
View File
@@ -249,3 +249,37 @@ fn view_macros_record_macro_toggles_recording() {
assert!(h.state().dialog.is_none());
assert!(!h.state().session.is_recording());
}
#[test]
fn the_macros_dialog_offers_trust_for_scripts_that_came_with_a_file() {
let mut s = Session::new();
s.new_workbook();
s.execute("automate.newScript", json!({"name": "Mark", "commands": [{"command": "cell.set", "params": {"cell": "D4", "input": "script"}}]}))
.unwrap();
// As when the workbook was opened with its scripts (#2178).
s.active_mut().unwrap().scripts_trusted = false;
let mut app = SheetApp::new(s, Default::default());
app.ui.ribbon_tab = "Automate".into();
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state(
|ui, app: &mut SheetApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
app,
);
h.run_steps(3);
h.state_mut().open_dialog("macros", json!({}));
h.run_steps(2);
assert!(h.query_by_label_contains("came from a file and are disabled").is_some());
h.get_by_label("Trust Scripts").click();
// The dialog shrinks without the row: let it settle before the next click.
h.run_steps(4);
assert!(h.state().session.doc().unwrap().scripts_trusted);
assert!(h.query_by_label("Trust Scripts").is_none(), "the row goes once the scripts are trusted");
h.get_by_label("Mark (script, 1 step)").click();
h.run_steps(2);
h.get_by_label("Run").click();
h.run_steps(3);
assert_eq!(value(&h, "D4"), Value::Text("script".into()));
}
+2
View File
@@ -276,6 +276,8 @@ other macros open; a macro that was left out is not in the saved file.
Macro opens the step editor on a new macro.
- **Macros dialog** (Automate › Macros, View › Macros, Alt+F8). It lists the workbook's macros
(with their shortcuts), then its Automate scripts, and says when the file carries a VBA project.
Scripts that came with an opened file stay disabled until Trust Scripts (`automate.trustScripts`)
trusts them for the session.
Run runs the selected macro on the selection or the selected script; Step Into, Edit and Create
open the step editor; Delete asks first; Options sets a macro's shortcut letter and description. The dialog keeps the result of `view.macros`,
as before macros existed.