summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/anki-note-builder.test.js2
-rw-r--r--test/database.test.js4
-rw-r--r--test/mocks/dictionary-importer-media-loader.js25
-rw-r--r--test/mocks/template-renderer-proxy.js63
4 files changed, 90 insertions, 4 deletions
diff --git a/test/anki-note-builder.test.js b/test/anki-note-builder.test.js
index 6901dde9..42ee2290 100644
--- a/test/anki-note-builder.test.js
+++ b/test/anki-note-builder.test.js
@@ -53,7 +53,7 @@ async function fetch(url2) {
};
}
vi.stubGlobal('fetch', fetch);
-vi.mock('../ext/js/templates/template-renderer-proxy.js');
+vi.mock('../ext/js/templates/template-renderer-proxy.js', async () => await import('../test/mocks/template-renderer-proxy.js'));
/**
* @returns {Promise<TranslatorVM>}
diff --git a/test/database.test.js b/test/database.test.js
index e7774d95..2fdea99c 100644
--- a/test/database.test.js
+++ b/test/database.test.js
@@ -22,15 +22,13 @@ import path from 'path';
import {beforeEach, describe, expect, test, vi} from 'vitest';
import {createDictionaryArchive} from '../dev/util.js';
import {DictionaryDatabase} from '../ext/js/language/dictionary-database.js';
-import {DictionaryImporterMediaLoader} from '../ext/js/language/dictionary-importer-media-loader.js';
import {DictionaryImporter} from '../ext/js/language/dictionary-importer.js';
+import {DictionaryImporterMediaLoader} from './mocks/dictionary-importer-media-loader.js';
const dirname = path.dirname(fileURLToPath(import.meta.url));
vi.stubGlobal('IDBKeyRange', IDBKeyRange);
-vi.mock('../ext/js/language/dictionary-importer-media-loader.js');
-
/**
* @param {string} dictionary
* @param {string} [dictionaryName]
diff --git a/test/mocks/dictionary-importer-media-loader.js b/test/mocks/dictionary-importer-media-loader.js
new file mode 100644
index 00000000..ffda29b3
--- /dev/null
+++ b/test/mocks/dictionary-importer-media-loader.js
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2023 Yomitan Authors
+ * Copyright (C) 2021-2022 Yomichan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+export class DictionaryImporterMediaLoader {
+ /** @type {import('dictionary-importer-media-loader').GetImageDetailsFunction} */
+ async getImageDetails(content) {
+ // Placeholder values
+ return {content, width: 100, height: 100};
+ }
+}
diff --git a/test/mocks/template-renderer-proxy.js b/test/mocks/template-renderer-proxy.js
new file mode 100644
index 00000000..106cdb35
--- /dev/null
+++ b/test/mocks/template-renderer-proxy.js
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2023 Yomitan Authors
+ * Copyright (C) 2021-2022 Yomichan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+import {AnkiTemplateRenderer} from '../../ext/js/templates/sandbox/anki-template-renderer.js';
+
+export class TemplateRendererProxy {
+ constructor() {
+ /** @type {?Promise<void>} */
+ this._preparePromise = null;
+ /** @type {AnkiTemplateRenderer} */
+ this._ankiTemplateRenderer = new AnkiTemplateRenderer();
+ }
+
+ /**
+ * @param {string} template
+ * @param {import('template-renderer').PartialOrCompositeRenderData} data
+ * @param {import('anki-templates').RenderMode} type
+ * @returns {Promise<import('template-renderer').RenderResult>}
+ */
+ async render(template, data, type) {
+ await this._prepare();
+ return this._ankiTemplateRenderer.templateRenderer.render(template, data, type);
+ }
+
+ /**
+ * @param {import('template-renderer').RenderMultiItem[]} items
+ * @returns {Promise<import('core').Response<import('template-renderer').RenderResult>[]>}
+ */
+ async renderMulti(items) {
+ await this._prepare();
+ return this._ankiTemplateRenderer.templateRenderer.renderMulti(items);
+ }
+
+ /**
+ * @returns {Promise<void>}
+ */
+ _prepare() {
+ if (this._preparePromise === null) {
+ this._preparePromise = this._prepareInternal();
+ }
+ return this._preparePromise;
+ }
+
+ /** */
+ async _prepareInternal() {
+ await this._ankiTemplateRenderer.prepare();
+ }
+}