aboutsummaryrefslogtreecommitdiff
path: root/test/utilities/anki.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-05 06:16:00 -0500
committerGitHub <noreply@github.com>2024-02-05 11:16:00 +0000
commit576dece97e6546aea774d1bac4a05b7854c512a4 (patch)
treef9b9b1c167a0156221ecef275f23d53acf519dae /test/utilities/anki.js
parent71c3aff53173cc83a96d7d2715b7918bdbc2d8a5 (diff)
Reduce repeated anki field marker code (#632)
* Unify repeated code for getting anki field markers * Throw because type safety exists * Simplify * Update order * Update test data
Diffstat (limited to 'test/utilities/anki.js')
-rw-r--r--test/utilities/anki.js100
1 files changed, 16 insertions, 84 deletions
diff --git a/test/utilities/anki.js b/test/utilities/anki.js
index 4c6c6d57..9f9bfef3 100644
--- a/test/utilities/anki.js
+++ b/test/utilities/anki.js
@@ -16,10 +16,24 @@
*/
import {AnkiNoteBuilder} from '../../ext/js/data/anki-note-builder.js';
+import {getStandardFieldMarkers} from '../../ext/js/data/anki-template-util.js';
import {createAnkiNoteData} from '../../ext/js/data/sandbox/anki-note-data-creator.js';
import {AnkiTemplateRenderer} from '../../ext/js/templates/sandbox/anki-template-renderer.js';
/**
+ * @param {import('dictionary').DictionaryEntryType} type
+ * @returns {import('anki-note-builder').Field[]}
+ */
+function createTestFields(type) {
+ /** @type {import('anki-note-builder').Field[]} */
+ const fields = [];
+ for (const marker of getStandardFieldMarkers(type)) {
+ fields.push([marker, `{${marker}}`]);
+ }
+ return fields;
+}
+
+/**
* @param {import('dictionary').DictionaryEntry} dictionaryEntry
* @param {import('settings').ResultOutputMode} mode
* @returns {import('anki-templates').NoteData}
@@ -47,95 +61,13 @@ export function createTestAnkiNoteData(dictionaryEntry, mode) {
}
/**
- * @param {'terms'|'kanji'} type
- * @returns {string[]}
- */
-function getFieldMarkers(type) {
- switch (type) {
- case 'terms':
- return [
- 'audio',
- 'clipboard-image',
- 'clipboard-text',
- 'cloze-body',
- 'cloze-prefix',
- 'cloze-suffix',
- 'conjugation',
- 'dictionary',
- 'document-title',
- 'expression',
- 'frequencies',
- 'frequency-harmonic-rank',
- 'frequency-harmonic-occurrence',
- 'frequency-average-rank',
- 'frequency-average-occurrence',
- 'furigana',
- 'furigana-plain',
- 'glossary',
- 'glossary-brief',
- 'glossary-no-dictionary',
- 'part-of-speech',
- 'pitch-accents',
- 'pitch-accent-graphs',
- 'pitch-accent-positions',
- 'phonetic-transcriptions',
- 'reading',
- 'screenshot',
- 'search-query',
- 'selection-text',
- 'sentence',
- 'sentence-furigana',
- 'tags',
- 'url'
- ];
- case 'kanji':
- return [
- 'character',
- 'clipboard-image',
- 'clipboard-text',
- 'cloze-body',
- 'cloze-prefix',
- 'cloze-suffix',
- 'dictionary',
- 'document-title',
- 'frequencies',
- 'frequency-harmonic-rank',
- 'frequency-harmonic-occurrence',
- 'frequency-average-rank',
- 'frequency-average-occurrence',
- 'glossary',
- 'kunyomi',
- 'onyomi',
- 'screenshot',
- 'search-query',
- 'selection-text',
- 'sentence',
- 'sentence-furigana',
- 'stroke-count',
- 'tags',
- 'url'
- ];
- default:
- return [];
- }
-}
-
-/**
* @param {import('dictionary').DictionaryEntry[]} dictionaryEntries
- * @param {'terms'|'kanji'} type
* @param {import('settings').ResultOutputMode} mode
* @param {string} template
* @param {?import('vitest').ExpectStatic} expect
* @returns {Promise<import('anki').NoteFields[]>}
*/
-export async function getTemplateRenderResults(dictionaryEntries, type, mode, template, expect) {
- const markers = getFieldMarkers(type);
- /** @type {import('anki-note-builder').Field[]} */
- const fields = [];
- for (const marker of markers) {
- fields.push([marker, `{${marker}}`]);
- }
-
+export async function getTemplateRenderResults(dictionaryEntries, mode, template, expect) {
const ankiTemplateRenderer = new AnkiTemplateRenderer();
await ankiTemplateRenderer.prepare();
const clozePrefix = 'cloze-prefix';
@@ -173,7 +105,7 @@ export async function getTemplateRenderResults(dictionaryEntries, type, mode, te
template,
deckName: 'deckName',
modelName: 'modelName',
- fields,
+ fields: createTestFields(dictionaryEntry.type),
tags: ['yomitan'],
checkForDuplicates: true,
duplicateScope: 'collection',