From d2c930a94d6e445053bcb5e5bb629851165425fc Mon Sep 17 00:00:00 2001 From: StefanVukovic99 Date: Thu, 20 Jun 2024 19:27:02 +0200 Subject: 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 --- test/utilities/anki.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'test/utilities') 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} */ -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) { -- cgit v1.2.3