summaryrefslogtreecommitdiff
path: root/test/options-util.test.js
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-02-12 07:18:48 +0100
committerGitHub <noreply@github.com>2024-02-12 06:18:48 +0000
commit043ac79203abbc9c7f3aa971e2de8ddedb3c0e90 (patch)
tree6cb600115b9ea7388e8ed15fc2016697b31e9f8b /test/options-util.test.js
parentfd48f18f8aa05a362f3168cbddcc03659e7510db (diff)
add cumulative handlebars upgrades test (#672)
* add cumulative test * undo delete line * old templates from v2 to v1 * move test handlebars data to templates folder --------- Co-authored-by: Darius Jahandarie <djahandarie@gmail.com>
Diffstat (limited to 'test/options-util.test.js')
-rw-r--r--test/options-util.test.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/options-util.test.js b/test/options-util.test.js
index 8fe0e212..78ac0009 100644
--- a/test/options-util.test.js
+++ b/test/options-util.test.js
@@ -628,6 +628,42 @@ async function testUpdate() {
}
/** */
+async function testCumulativeFieldTemplatesUpdates() {
+ /**
+ * @param {string} templates
+ * @returns {Map<string, string>}
+ */
+ const getHandlebarsPartials = (templates) => {
+ const inlinePartialRegex = /{{~?#\*inline .*?"([^"]*)"~?}}.*?{{~?\/inline~?}}/gs;
+ const matches = templates.matchAll(inlinePartialRegex);
+ const partials = new Map();
+ for (const match of matches) {
+ const [template, name] = match;
+ partials.set(name, template);
+ }
+ return partials;
+ };
+ test('CumulativeFieldTemplatesUpdates', async () => {
+ const optionsUtil = new OptionsUtil();
+ await optionsUtil.prepare();
+
+ const options = /** @type {import('core').SafeAny} */ (createOptionsTestData1());
+
+ const oldAnkiFieldTemplates = fs.readFileSync(path.join(dirname, 'data', 'templates', 'old-default-anki-field-templates.handlebars'), {encoding: 'utf8'});
+ const defaultAnkiFieldTemplates = fs.readFileSync(path.join(dirname, '..', 'ext', 'data', 'templates', 'default-anki-field-templates.handlebars'), {encoding: 'utf8'});
+
+ options.profiles[0].options.anki.fieldTemplates = oldAnkiFieldTemplates;
+ const optionsUpdated = structuredClone(await optionsUtil.update(options));
+ const fieldTemplatesUpdated = optionsUpdated.profiles[0].options.anki.fieldTemplates || '';
+
+ const partialsUpdated = getHandlebarsPartials(fieldTemplatesUpdated);
+ const partialsExpected = getHandlebarsPartials(defaultAnkiFieldTemplates);
+
+ expect(partialsUpdated).toStrictEqual(partialsExpected);
+ });
+}
+
+/** */
async function testDefault() {
describe('Default', () => {
/** @type {((options: import('options-util').IntermediateOptions) => void)[]} */
@@ -1697,6 +1733,7 @@ async function main() {
await testUpdate();
await testDefault();
await testFieldTemplatesUpdate();
+ await testCumulativeFieldTemplatesUpdates();
}
await main();