Updated tests with localization
Sonarqube Scanner / Prepare environment (push) Successful in 9s
Sonarqube Scanner / Build and test (push) Successful in 25s
Sonarqube Scanner / SonarQube analysis (push) Failing after 1m16s
Sonarqube Scanner / Deploy to Server (push) Successful in 9s

This commit is contained in:
Florian Zumpe
2026-10-01 10:47:43 +02:00
parent aff88eba1b
commit 2b42507f13
7 changed files with 47 additions and 13 deletions
+7 -3
View File
@@ -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');
});