Updated tests with localization
This commit is contained in:
+7
-3
@@ -26,18 +26,22 @@ test('language changes translate visible and spoken labels through textContent a
|
||||
const i18n = await loadI18n({});
|
||||
const make = key => ({ textContent: '', attributes: new Map(key), getAttribute(name) { return this.attributes.get(name); }, setAttribute(name, value) { this.attributes.set(name, value); } });
|
||||
const text = make([['data-i18n', 'app.strecke.wahlen']]);
|
||||
const label = make([['data-i18n-aria-label', 'app.strecke.wahlen']]);
|
||||
const attributes = ['aria-label', 'title', 'placeholder', 'alt'];
|
||||
const labels = new Map(attributes.map(attribute => [attribute, make([[`data-i18n-${attribute}`, 'app.strecke.wahlen']])]));
|
||||
const root = { documentElement: {}, querySelectorAll(selector) {
|
||||
if (selector === '[data-i18n]') return [text];
|
||||
if (selector === '[data-i18n-aria-label]') return [label];
|
||||
for (const [attribute, label] of labels) {
|
||||
if (selector === `[data-i18n-${attribute}]`) return [label];
|
||||
}
|
||||
return [];
|
||||
} };
|
||||
i18n.apply(root);
|
||||
assert.equal(text.textContent, 'Strecke wählen');
|
||||
assert.equal(label.attributes.get('aria-label'), 'Strecke wählen');
|
||||
for (const [attribute, label] of labels) assert.equal(label.attributes.get(attribute), 'Strecke wählen');
|
||||
i18n.register('en', { 'app.strecke.wahlen': '<Choose a trail>' });
|
||||
i18n.setLanguage('en', root);
|
||||
assert.equal(text.textContent, '<Choose a trail>');
|
||||
for (const [attribute, label] of labels) assert.equal(label.attributes.get(attribute), '<Choose a trail>');
|
||||
assert.equal(root.documentElement.lang, 'en');
|
||||
assert.equal(text.attributes.get('data-i18n'), 'app.strecke.wahlen');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user