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/fixtures/translator-test.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'test/fixtures') diff --git a/test/fixtures/translator-test.js b/test/fixtures/translator-test.js index 5c024472..857e8a98 100644 --- a/test/fixtures/translator-test.js +++ b/test/fixtures/translator-test.js @@ -34,7 +34,7 @@ vi.stubGlobal('chrome', chrome); /** * @param {string} dictionaryDirectory * @param {string} dictionaryName - * @returns {Promise} + * @returns {Promise<{translator: Translator, styles: string}>} */ export async function createTranslatorContext(dictionaryDirectory, dictionaryName) { // Dictionary @@ -46,36 +46,41 @@ export async function createTranslatorContext(dictionaryDirectory, dictionaryNam const dictionaryDatabase = new DictionaryDatabase(); await dictionaryDatabase.prepare(); - const {errors} = await dictionaryImporter.importDictionary( + const {errors, result} = await dictionaryImporter.importDictionary( dictionaryDatabase, testDictionaryData, {prefixWildcardsSupported: true}, ); expect(errors.length).toEqual(0); + expect(result).not.toBeNull(); + + const styles = result?.styles ?? ''; // Setup translator const translator = new Translator(dictionaryDatabase); translator.prepare(); - return translator; + return {translator, styles}; } /** * @param {string|undefined} htmlFilePath * @param {string} dictionaryDirectory * @param {string} dictionaryName - * @returns {Promise>} + * @returns {Promise>} */ export async function createTranslatorTest(htmlFilePath, dictionaryDirectory, dictionaryName) { const test = createDomTest(htmlFilePath); - const translator = await createTranslatorContext(dictionaryDirectory, dictionaryName); - /** @type {import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator}>} */ + const {translator, styles} = await createTranslatorContext(dictionaryDirectory, dictionaryName); + /** @type {import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator, styles: string}>} */ // eslint-disable-next-line sonarjs/prefer-immediate-return const result = test.extend({ window: async ({window}, use) => { await use(window); }, // eslint-disable-next-line no-empty-pattern translator: async ({}, use) => { await use(translator); }, + // eslint-disable-next-line no-empty-pattern + styles: async ({}, use) => { await use(styles); }, }); return result; } -- cgit v1.2.3