Update options-util tests and comment (#1806)

This commit is contained in:
toasted-nutbread 2021-07-06 22:59:24 -04:00 committed by GitHub
parent 1088c17503
commit 9935e154f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -853,6 +853,7 @@ class OptionsUtil {
async _updateVersion13(options) { async _updateVersion13(options) {
// Version 13 changes: // Version 13 changes:
// Handlebars templates updated to use formatGlossary. // Handlebars templates updated to use formatGlossary.
// Handlebars templates updated to use new media format.
await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v13.handlebars'); await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v13.handlebars');
return options; return options;
} }

View File

@ -661,7 +661,7 @@ async function testFieldTemplatesUpdate(extDir) {
const getUpdateAdditions = (startVersion, targetVersion) => { const getUpdateAdditions = (startVersion, targetVersion) => {
let value = ''; let value = '';
for (const {version, changes} of updates) { for (const {version, changes} of updates) {
if (version < startVersion || version > targetVersion || changes.length === 0) { continue; } if (version <= startVersion || version > targetVersion || changes.length === 0) { continue; }
if (value.length > 0) { value += '\n'; } if (value.length > 0) { value += '\n'; }
value += changes; value += changes;
} }
@ -936,22 +936,30 @@ async function testFieldTemplatesUpdate(extDir) {
oldVersion: 12, oldVersion: 12,
newVersion: 13, newVersion: 13,
old: ` old: `
{{#*inline "example"}}
{{~#if (op "<=" glossary.length 1)~}} {{~#if (op "<=" glossary.length 1)~}}
{{#each glossary}}{{#multiLine}}{{.}}{{/multiLine}}{{/each}} {{#each glossary}}{{#multiLine}}{{.}}{{/multiLine}}{{/each}}
{{~else if @root.compactGlossaries~}} {{~else if @root.compactGlossaries~}}
{{#each glossary}}{{#multiLine}}{{.}}{{/multiLine}}{{#unless @last}} | {{/unless}}{{/each}} {{#each glossary}}{{#multiLine}}{{.}}{{/multiLine}}{{#unless @last}} | {{/unless}}{{/each}}
{{~else~}} {{~else~}}
<ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#multiLine}}{{.}}{{/multiLine}}</li>{{/each}}</ul>
{{~/if~}}`.trimStart(), {{~/if~}}
{{/inline}}
{{~> (lookup . "marker") ~}}`.trimStart(),
expected: ` expected: `
{{#*inline "example"}}
{{~#if (op "<=" glossary.length 1)~}} {{~#if (op "<=" glossary.length 1)~}}
{{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}} {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{/each}}
{{~else if @root.compactGlossaries~}} {{~else if @root.compactGlossaries~}}
{{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{#unless @last}} | {{/unless}}{{/each}} {{#each glossary}}{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}{{#unless @last}} | {{/unless}}{{/each}}
{{~else~}} {{~else~}}
<ul>{{#each glossary}}<li>{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}</li>{{/each}}</ul> <ul>{{#each glossary}}<li>{{#formatGlossary ../dictionary}}{{{.}}}{{/formatGlossary}}</li>{{/each}}</ul>
{{~/if~}}`.trimStart() {{~/if~}}
{{/inline}}
{{~> (lookup . "marker") ~}}`.trimStart()
}, },
// hasMedia/getMedia update // hasMedia/getMedia update
{ {
@ -976,7 +984,9 @@ async function testFieldTemplatesUpdate(extDir) {
{{#*inline "clipboard-text"}} {{#*inline "clipboard-text"}}
{{~#if definition.clipboardText~}}{{definition.clipboardText}}{{~/if~}} {{~#if definition.clipboardText~}}{{definition.clipboardText}}{{~/if~}}
{{/inline}}`.trimStart(), {{/inline}}
{{~> (lookup . "marker") ~}}`.trimStart(),
expected: ` expected: `
{{#*inline "audio"}} {{#*inline "audio"}}
@ -999,7 +1009,9 @@ async function testFieldTemplatesUpdate(extDir) {
{{#*inline "clipboard-text"}} {{#*inline "clipboard-text"}}
{{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText" format="text"}}{{/getMedia}}{{/if~}} {{~#if (hasMedia "clipboardText")}}{{#getMedia "clipboardText" format="text"}}{{/getMedia}}{{/if~}}
{{/inline}}`.trimStart() {{/inline}}
{{~> (lookup . "marker") ~}}`.trimStart()
} }
]; ];