Skip to content

Commit

Permalink
Remove TemplateRendererProxy mock
Browse files Browse the repository at this point in the history
  • Loading branch information
toasted-nutbread committed Dec 19, 2023
1 parent 6b07b1e commit e89f6e9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 75 deletions.
12 changes: 6 additions & 6 deletions ext/js/data/anki-note-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import {deferPromise} from '../core.js';
import {ExtensionError} from '../core/extension-error.js';
import {TemplateRendererProxy} from '../templates/template-renderer-proxy.js';
import {yomitan} from '../yomitan.js';
import {AnkiUtil} from './anki-util.js';

Expand All @@ -28,18 +27,19 @@ import {AnkiUtil} from './anki-util.js';
export class AnkiNoteBuilder {
/**
* Initiate an instance of AnkiNoteBuilder.
* @param {{japaneseUtil: import('../language/sandbox/japanese-util.js').JapaneseUtil}} details
* @param {import('../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil
* @param {import('../templates/template-renderer-proxy.js').TemplateRendererProxy|import('../templates/sandbox/template-renderer.js').TemplateRenderer} templateRenderer
* @example
* const japaneseUtil = new JapaneseUtil(null);
* const ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil});
* const ankiNoteBuilder = new AnkiNoteBuilder(japaneseUtil, new TemplateRendererProxy());
*/
constructor({japaneseUtil}) {
constructor(japaneseUtil, templateRenderer) {
/** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */
this._japaneseUtil = japaneseUtil;
/** @type {RegExp} */
this._markerPattern = AnkiUtil.cloneFieldMarkerPattern(true);
/** @type {TemplateRendererProxy} */
this._templateRenderer = new TemplateRendererProxy();
/** @type {import('../templates/template-renderer-proxy.js').TemplateRendererProxy|import('../templates/sandbox/template-renderer.js').TemplateRenderer} */
this._templateRenderer = templateRenderer;
/** @type {import('anki-note-builder').BatchedRequestGroup[]} */
this._batchedRequests = [];
/** @type {boolean} */
Expand Down
3 changes: 2 additions & 1 deletion ext/js/display/display-anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {AnkiNoteBuilder} from '../data/anki-note-builder.js';
import {AnkiUtil} from '../data/anki-util.js';
import {PopupMenu} from '../dom/popup-menu.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {TemplateRendererProxy} from '../templates/template-renderer-proxy.js';
import {yomitan} from '../yomitan.js';

export class DisplayAnki {
Expand All @@ -39,7 +40,7 @@ export class DisplayAnki {
/** @type {?string} */
this._ankiFieldTemplatesDefault = null;
/** @type {AnkiNoteBuilder} */
this._ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil});
this._ankiNoteBuilder = new AnkiNoteBuilder(japaneseUtil, new TemplateRendererProxy());
/** @type {?import('./display-notification.js').DisplayNotification} */
this._errorNotification = null;
/** @type {?EventListenerCollection} */
Expand Down
3 changes: 2 additions & 1 deletion ext/js/pages/settings/anki-templates-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {ExtensionError} from '../../core/extension-error.js';
import {AnkiNoteBuilder} from '../../data/anki-note-builder.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {JapaneseUtil} from '../../language/sandbox/japanese-util.js';
import {TemplateRendererProxy} from '../../templates/template-renderer-proxy.js';
import {yomitan} from '../../yomitan.js';

export class AnkiTemplatesController {
Expand Down Expand Up @@ -54,7 +55,7 @@ export class AnkiTemplatesController {
/** @type {?import('./modal.js').Modal} */
this._fieldTemplateResetModal = null;
/** @type {AnkiNoteBuilder} */
this._ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil: new JapaneseUtil(null)});
this._ankiNoteBuilder = new AnkiNoteBuilder(new JapaneseUtil(null), new TemplateRendererProxy());
}

/** */
Expand Down
9 changes: 5 additions & 4 deletions test/anki-note-builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
import {readFileSync} from 'fs';
import {fileURLToPath} from 'node:url';
import path from 'path';
import {describe, vi} from 'vitest';
import {describe} from 'vitest';
import {AnkiNoteBuilder} from '../ext/js/data/anki-note-builder.js';
import {JapaneseUtil} from '../ext/js/language/sandbox/japanese-util.js';
import {AnkiTemplateRenderer} from '../ext/js/templates/sandbox/anki-template-renderer.js';
import {createTranslatorTest} from './fixtures/translator-test.js';
import {createFindOptions} from './utilities/translator.js';

const dirname = path.dirname(fileURLToPath(import.meta.url));

vi.mock('../ext/js/templates/template-renderer-proxy.js', async () => await import('../test/mocks/template-renderer-proxy.js'));

/**
* @param {'terms'|'kanji'} type
* @returns {string[]}
Expand Down Expand Up @@ -111,6 +110,8 @@ async function getRenderResults(dictionaryEntries, type, mode, template, expect)
fields.push([marker, `{${marker}}`]);
}

const ankiTemplateRenderer = new AnkiTemplateRenderer();
await ankiTemplateRenderer.prepare();
const japaneseUtil = new JapaneseUtil(null);
const clozePrefix = 'cloze-prefix';
const clozeSuffix = 'cloze-suffix';
Expand All @@ -127,7 +128,7 @@ async function getRenderResults(dictionaryEntries, type, mode, template, expect)
}
break;
}
const ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil});
const ankiNoteBuilder = new AnkiNoteBuilder(japaneseUtil, ankiTemplateRenderer.templateRenderer);
const context = {
url: 'url:',
sentence: {
Expand Down
63 changes: 0 additions & 63 deletions test/mocks/template-renderer-proxy.js

This file was deleted.

0 comments on commit e89f6e9

Please sign in to comment.