aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-02 12:42:06 -0400
committerGitHub <noreply@github.com>2021-04-02 12:42:06 -0400
commit8179846e381eb0a87bf3bc266abec8f4400565bc (patch)
treeddb57d7870b461c9758f6de8a25dd76bbfaf81f7 /test
parent36b7e34cce776cb09a76c28ce8e78e864dabcdda (diff)
Refactor template rendering (#1583)
* Update _errorToJson to _serializeError * Remove async * Refactor render * Simplify _getModifiedData * Rename data => commonData * Rename templates => template for consistency * Improve errors check * Update tests
Diffstat (limited to 'test')
-rw-r--r--test/test-anki-note-builder.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js
index aa2cf572..b1fffbcd 100644
--- a/test/test-anki-note-builder.js
+++ b/test/test-anki-note-builder.js
@@ -55,7 +55,7 @@ async function createVM() {
const japaneseUtil = new JapaneseUtil(null);
this._templateRenderer = new TemplateRenderer(japaneseUtil);
this._templateRenderer.registerDataType('ankiNote', {
- modifier: ({data, marker}) => ankiNoteDataCreator.create(marker, data)
+ modifier: ({marker, commonData}) => ankiNoteDataCreator.create(marker, commonData)
});
}
@@ -122,7 +122,7 @@ function getFieldMarkers(type) {
}
}
-async function getRenderResults(dictionaryEntries, type, mode, templates, AnkiNoteBuilder, write) {
+async function getRenderResults(dictionaryEntries, type, mode, template, AnkiNoteBuilder, write) {
const markers = getFieldMarkers(type);
const fields = [];
for (const marker of markers) {
@@ -158,7 +158,7 @@ async function getRenderResults(dictionaryEntries, type, mode, templates, AnkiNo
definition: dictionaryEntry,
mode: null,
context,
- templates,
+ template,
deckName: 'deckName',
modelName: 'modelName',
fields,
@@ -193,7 +193,7 @@ async function main() {
const expectedResults1 = JSON.parse(fs.readFileSync(testResults1FilePath, {encoding: 'utf8'}));
const actualResults1 = [];
- const templates = fs.readFileSync(path.join(__dirname, '..', 'ext', 'data/templates/default-anki-field-templates.handlebars'), {encoding: 'utf8'});
+ const template = fs.readFileSync(path.join(__dirname, '..', 'ext', 'data/templates/default-anki-field-templates.handlebars'), {encoding: 'utf8'});
for (let i = 0, ii = tests.length; i < ii; ++i) {
const test = tests[i];
@@ -204,7 +204,7 @@ async function main() {
const {name, mode, text} = test;
const options = vm.buildOptions(optionsPresets, test.options);
const {dictionaryEntries} = clone(await vm.translator.findTerms(mode, text, options));
- const results = mode !== 'simple' ? clone(await getRenderResults(dictionaryEntries, 'terms', mode, templates, AnkiNoteBuilder, write)) : null;
+ const results = mode !== 'simple' ? clone(await getRenderResults(dictionaryEntries, 'terms', mode, template, AnkiNoteBuilder, write)) : null;
actualResults1.push({name, results});
if (!write) {
assert.deepStrictEqual(results, expected1.results);
@@ -216,7 +216,7 @@ async function main() {
const {name, text} = test;
const options = vm.buildOptions(optionsPresets, test.options);
const dictionaryEntries = clone(await vm.translator.findKanji(text, options));
- const results = clone(await getRenderResults(dictionaryEntries, 'kanji', null, templates, AnkiNoteBuilder, write));
+ const results = clone(await getRenderResults(dictionaryEntries, 'kanji', null, template, AnkiNoteBuilder, write));
actualResults1.push({name, results});
if (!write) {
assert.deepStrictEqual(results, expected1.results);