I'm trying to test a simple add-on for Google Docs that I've made but it seems that this page of documentation is related to the legacy Apps Script editor, and I cannot find out how to do with the new Apps Script editor.
My code, if it helps
const PASS = "PASSPHRASE";
function decrypt(text) {
var cipher = new cCryptoGS.Cipher(PASS, 'aes');
return cipher.decrypt(text)
}
function encrypt(text) {
var cipher = new cCryptoGS.Cipher(PASS, 'aes');
return cipher.encrypt(text)
}
function decryptDocument() {
var doc = DocumentApp.getActiveDocument();
var paragraphs = doc.getBody().getParagraphs();
return paragraphs.reduce((previous, current) => {
return previous + "\n" + decrypt(current.getText());
}, "");
}
function onOpen() {
DocumentApp.getUi()
.createMenu('Décodeur')
.addItem('Lancer le décodeur', 'showSidebar')
.addToUi();
}
function showSidebar() {
var html = HtmlService.createHtmlOutputFromFile('decoder')
.setTitle('Décodeur');
DocumentApp.getUi().showSidebar(html);
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<button onclick="decrypt()">Décoder le contenu</button>
<div id="decodedText">
</div>
</body>
<script>
var running = false;
function onSuccess(decodedText) {
running = false;
document.getElementById("decodedText").innerHTML = decodedText;
}
function onFailure(e) {
running = false;
console.error(e);
}
function cleanDiv() {
document.getElementById("decodedText").innerHTML = "";
}
function decrypt() {
running = true;
google.script.run.withSuccessHandler(onSuccess)
.withFailureHandler(onFailure)
.decryptDocument();
}
</script>
</html>
{
"timeZone": "America/New_York",
"dependencies": {
"libraries": [
{
"userSymbol": "cCryptoGS",
"version": "4",
"libraryId": "1IEkpeS8hsMSVLRdCMprij996zG6ek9UvGwcCJao_hlDMlgbWWvJpONrs"
}
]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
The only way to thoroughly test an editor add-on is by publishing by using the Google Workspace SDK.
When the OP created this question, the developer had to use the legacy editor to use the "Test as add-on" feature of the Google Apps Script. It might be OK to test features like an onOpen simple trigger but not other features like installable triggers. Nowadays, the old editor is no longer available, but the test as an add-on feature is available in the new editor. Still, there are some features that can't be tested using this feature.
Apparently, your editor add-on does not use installable triggers and other features that can't be tested with "Test as add-on." However, it's very likely that it will be good enough to test the simple triggers of your add-on.
Also, your add-on is missing the onInstall
simple trigger, which usually calls the onOpen
trigger when the add-on is installed from an opened document.
Reference
Related