test: add template tests

This commit is contained in:
windingwind 2025-01-06 11:49:10 +01:00
parent 0e42f90549
commit 2b0ef07fee
4 changed files with 347 additions and 4 deletions

View File

@ -62,7 +62,12 @@ function removeTemplate(keyName: string | undefined): void {
addon.data.template.data?.deleteKey(keyName);
}
function importTemplateFromClipboard(text?: string) {
function importTemplateFromClipboard(
text?: string,
options: {
quiet?: boolean;
} = {},
) {
if (!text) {
text = Zotero.Utilities.Internal.getClipboard("text/plain") || "";
}
@ -83,7 +88,10 @@ function importTemplateFromClipboard(text?: string) {
showHint("The copied template is invalid");
return;
}
if (!window.confirm(`Import template "${template.name}"?`)) {
if (
!options.quiet &&
!window.confirm(`Import template "${template.name}"?`)
) {
return;
}
setTemplate({ name: template.name, text: template.content });
@ -91,4 +99,5 @@ function importTemplateFromClipboard(text?: string) {
if (addon.data.template.editor.window) {
addon.data.template.editor.window.refresh();
}
return template.name;
}

View File

@ -1,7 +1,7 @@
import { config } from "../../package.json";
import { getAddon } from "../utils/global";
describe("Startup", function () {
it("should have plugin instance defined", function () {
assert.isNotEmpty(Zotero[config.addonRef]);
assert.isNotEmpty(getAddon());
});
});

326
test/tests/template.spec.ts Normal file

File diff suppressed because one or more lines are too long

8
test/utils/global.ts Normal file
View File

@ -0,0 +1,8 @@
import { config } from "../../package.json";
export { getAddon };
function getAddon(): import("../../src/addon").default {
// @ts-ignore - plugin instance
return Zotero[config.addonRef];
}