aboutsummaryrefslogtreecommitdiff
path: root/test/fixtures/translator-test.js
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-06-20 19:27:02 +0200
committerGitHub <noreply@github.com>2024-06-20 17:27:02 +0000
commitd2c930a94d6e445053bcb5e5bb629851165425fc (patch)
tree94ff7034e7d3ab36ed663f353aeb5486bd294d1c /test/fixtures/translator-test.js
parent1a866b3997310a04fc146b91eb47a59a3f049589 (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/fixtures/translator-test.js')
-rw-r--r--test/fixtures/translator-test.js17
1 files changed, 11 insertions, 6 deletions
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<Translator>}
+ * @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<import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator}>>}
+ * @returns {Promise<import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator, styles: string}>>}
*/
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;
}