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
+35 -1
View File
@@ -400,7 +400,10 @@ test('storage gauge uses browser estimate, separates Local Storage and reports q
const usage = context.Wegwichtel.StorageUsage;
await usage.refresh();
assert.equal(elements.get('[data-storage-site-meter]').value, 95 * 1024 * 1024);
assert.match(elements.get('[data-storage-site-text]').textContent, /95 %.*5,2 MB frei.*Fast voll/);
const freeSpace = (5 * 1024 * 1024 / 1000000).toLocaleString('de', { maximumFractionDigits: 1 });
const siteText = elements.get('[data-storage-site-text]').textContent;
assert.match(siteText, /95 %.*Fast voll/);
assert.ok(siteText.includes(`${freeSpace} MB frei`), siteText);
assert.match(elements.get('[data-storage-local-text]').textContent, /Richtwert.*wirklich hineinpasst/);
usage.reportError({ cause: { name: 'QuotaExceededError' } });
await usage.refresh();
@@ -409,3 +412,34 @@ test('storage gauge uses browser estimate, separates Local Storage and reports q
await usage.refresh();
assert.equal(elements.get('[data-storage-site-meter]').hidden, true);
});
test('storage gauge uses the selected language with both localized and fallback number formatting', async () => {
const source = await fs.readFile(path.join(root, 'public/js/storage-usage.js'), 'utf8');
for (const decimalSeparator of [',', '.']) {
const label = {};
const calls = [];
const context = {
document: { querySelectorAll: selector => selector === '[data-storage-usage]' ? [{
querySelector: selector => selector === '[data-storage-site-text]' ? label : null
}] : [] },
navigator: { storage: { estimate: async () => ({ usage: 95 * 1024 * 1024, quota: 100 * 1024 * 1024 }) } },
formatNumber(value, language, options) {
calls.push({ value, language, options });
return value.toFixed(1).replace('.', decimalSeparator);
}
};
const i18n = await loadI18n(context);
// Model a runner whose Intl data falls back to a dot, without changing host globals.
vm.runInNewContext('Number.prototype.toLocaleString = function (language, options) { return formatNumber(Number(this), language, options); };', context);
vm.runInNewContext(source, context);
await context.Wegwichtel.StorageUsage.refresh();
assert.ok(label.textContent.includes(`5${decimalSeparator}2 MB frei`));
assert.equal(calls[0].language, 'de');
assert.equal(calls[0].options.maximumFractionDigits, 1);
assert.equal(calls[0].value, 5 * 1024 * 1024 / 1000000);
i18n.register('en', {});
i18n.setLanguage('en', null);
await context.Wegwichtel.StorageUsage.refresh();
assert.equal(calls.at(-1).language, 'en');
}
});