1package e2e23import (4 "os"5 "path/filepath"6 "testing"7)89// Golden screens for macros: the Data > Macros menu, recording, saving,10// the manager, an error from a script and the question before running11// macros from another computer.1213// recordOnBudget records, with relative references, a total row below14// the budget: a label, a formula and bold, saved as name with shortcut15// key (empty for none).16func recordOnBudget(s *session, name, key string) {17 s.keys("<ctrl+k>", "relative references", "<enter>")18 s.waitFor(" REC ")19 s.keys("<down>", "<left>", "Yearly", "<tab>", "=B7*12", "<enter>")20 s.keys("<up>", "<shift+right>", "<ctrl+b>")21 s.waitFor("Bold on")22 s.keys("<ctrl+k>", "stop and save", "<enter>")23 s.waitFor("Save macro as:")24 s.keys(name, "<enter>")25 s.waitFor("Shortcut Ctrl+Alt+Shift+")26 s.keys("<backspace>", key, "<enter>")27 s.waitFor("Saved macro " + name)28}2930// foreignBook is a saved budget with a macro made on another computer.31const foreignBook = `{32 "version": 2,33 "macroOrigin": "0123456789abcdef0123456789abcdef",34 "macros": [35 {"name": "Yearly", "key": "1", "api": 1, "source": "enter(\"Yearly\")\nmove(1, 0)\nenter(\"=B7*12\", origin=\"B8\")\n"}36 ],37 "cells": {38 "A1": "Household budget 2026",39 "A3": "Rent",40 "B3": "1450",41 "A7": "Total",42 "B7": "=SUM(B3:B5)"43 }44}45`4647var macroScreens = []screen{48 {name: "macro-menu", setup: func(s *session) {49 budget(s)50 s.keys("<alt+d>", "m")51 s.waitFor("Record macro with relative references")52 }},53 {name: "macro-recording", setup: func(s *session) {54 budget(s)55 s.keys("<ctrl+k>", "relative references", "<enter>")56 s.waitFor(" REC ")57 s.keys("<down>", "<left>", "Yearly", "<tab>")58 s.waitForBar("B8", "")59 }},60 {name: "macro-shortcut", setup: func(s *session) {61 budget(s)62 s.keys("<ctrl+k>", "relative references", "<enter>")63 s.waitFor(" REC ")64 s.keys("<down>", "<left>", "Yearly", "<enter>")65 s.keys("<ctrl+k>", "stop and save", "<enter>")66 s.waitFor("Save macro as:")67 s.keys("Yearly total", "<enter>")68 s.waitFor("Shortcut Ctrl+Alt+Shift+")69 }},70 {name: "macro-manager", setup: func(s *session) {71 budget(s)72 recordOnBudget(s, "Yearly total", "1")73 s.keys("<ctrl+home>")74 recordOnBudget(s, "Header row", "")75 s.keys("<ctrl+k>", "manage macros", "<enter>")76 s.waitFor("Write a macro")77 s.keys("<down>")78 }},79 {name: "macro-error", setup: func(s *session) {80 budget(s)81 recordOnBudget(s, "Yearly", "1")82 s.keys("<ctrl+end>", "<down>", "<down>", "<down>", "<home>", "<ctrl+alt+shift+1>")83 s.waitFor("goes off the sheet")84 }},85 {name: "macro-trust", files: func(t *testing.T, dir string) {86 if err := os.WriteFile(filepath.Join(dir, "budget.012"), []byte(foreignBook), 0o644); err != nil {87 t.Fatal(err)88 }89 }, setup: func(s *session) {90 s.keys("<ctrl+o>")91 s.waitFor("Open file:")92 s.keys("budget", "<enter>")93 s.waitFor("Household budget 2026")94 s.keys("<f5>", "A8", "<enter>", "<ctrl+alt+shift+1>")95 s.waitFor("Trust this file's macros?")96 }},97 {name: "macro-recording-narrow", opts: options{cols: 60, rows: 16}, setup: func(s *session) {98 budget(s)99 s.keys("<ctrl+k>", "relative references", "<enter>")100 s.waitFor(" REC ")101 }},102}103104func init() {105 light := map[string]bool{"macro-menu": true, "macro-recording": true, "macro-manager": true, "macro-error": true, "macro-trust": true}106 for _, sc := range macroScreens {107 screens = append(screens, sc)108 if light[sc.name] {109 sc.name += "-light"110 sc.opts.light = true111 screens = append(screens, sc)112 }113 }114}