diff options
author | StefanVukovic99 <stefanvukovic44@gmail.com> | 2024-06-20 19:27:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 17:27:02 +0000 |
commit | d2c930a94d6e445053bcb5e5bb629851165425fc (patch) | |
tree | 94ff7034e7d3ab36ed663f353aeb5486bd294d1c /test/utilities/anki.js | |
parent | 1a866b3997310a04fc146b91eb47a59a3f049589 (diff) |
support css file in dictionaries (#1080)
* get styles in db
* get styles in settings
* use styles
* fix test
* scope
* fix comma separated
* escape dict name in css selector
* g regex
* get styles in anki
* fix tests
* more specificity
* whitespace
* test importing
* test handlebars
* add styles to glossary-first
Diffstat (limited to 'test/utilities/anki.js')
-rw-r--r-- | test/utilities/anki.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/test/utilities/anki.js b/test/utilities/anki.js index 6471015a..ed7b6c60 100644 --- a/test/utilities/anki.js +++ b/test/utilities/anki.js @@ -36,11 +36,16 @@ function createTestFields(type) { /** * @param {import('dictionary').DictionaryEntry} dictionaryEntry * @param {import('settings').ResultOutputMode} mode + * @param {string} styles * @returns {import('anki-templates').NoteData} * @throws {Error} */ -export function createTestAnkiNoteData(dictionaryEntry, mode) { +export function createTestAnkiNoteData(dictionaryEntry, mode, styles = '') { const marker = '{marker}'; + const dictionaryStylesMap = new Map(); + if (styles !== '') { + dictionaryStylesMap.set('Test Dictionary 2', styles); + } /** @type {import('anki-templates-internal').CreateDetails} */ const data = { dictionaryEntry, @@ -56,6 +61,7 @@ export function createTestAnkiNoteData(dictionaryEntry, mode) { fullQuery: 'fullQuery', }, media: {}, + dictionaryStylesMap, }; return createAnkiNoteData(marker, data); } @@ -65,9 +71,10 @@ export function createTestAnkiNoteData(dictionaryEntry, mode) { * @param {import('settings').ResultOutputMode} mode * @param {string} template * @param {?import('vitest').ExpectStatic} expect + * @param {string} styles * @returns {Promise<import('anki').NoteFields[]>} */ -export async function getTemplateRenderResults(dictionaryEntries, mode, template, expect) { +export async function getTemplateRenderResults(dictionaryEntries, mode, template, expect, styles = '') { const ankiTemplateRenderer = new AnkiTemplateRenderer(); await ankiTemplateRenderer.prepare(); const clozePrefix = 'cloze-prefix'; @@ -97,6 +104,10 @@ export async function getTemplateRenderResults(dictionaryEntries, mode, template query: 'query', fullQuery: 'fullQuery', }; + const dictionaryStylesMap = new Map(); + if (styles) { + dictionaryStylesMap.set('Test Dictionary 2', styles); + } /** @type {import('anki-note-builder').CreateNoteDetails} */ const details = { dictionaryEntry, @@ -114,6 +125,7 @@ export async function getTemplateRenderResults(dictionaryEntries, mode, template compactTags: false, requirements: [], mediaOptions: null, + dictionaryStylesMap, }; const {note: {fields: noteFields}, errors} = await ankiNoteBuilder.createNote(details); for (const error of errors) { |