174 lines
9.1 KiB
JavaScript
174 lines
9.1 KiB
JavaScript
// Real Electron localization smoke. Uses only a disposable disconnected profile; never captures audio.
|
|
// No locale emulation, fake devices, server connections, or changes to the owner's profile.
|
|
import { closeSettings, launchApp } from './lib/electron-app.mjs';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const outArg = process.argv.indexOf('--out');
|
|
const exeArg = process.argv.indexOf('--exe');
|
|
const exe = exeArg >= 0 ? process.argv[exeArg + 1] : undefined;
|
|
const out = path.resolve(root, outArg >= 0 ? process.argv[outArg + 1] : 'smoke-out/i18n');
|
|
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-i18n-'));
|
|
mkdirSync(out, { recursive: true });
|
|
const errors = [];
|
|
const steps = [];
|
|
let app;
|
|
let page;
|
|
let failed;
|
|
const record = (name, details = {}) => { steps.push({ name, ...details }); console.log(`[i18n] ${name}`, JSON.stringify(details)); };
|
|
const prefs = () => JSON.parse(readFileSync(path.join(profile, 'prefs.json'), 'utf8'));
|
|
const withoutLanguage = ({ language, ...rest }) => rest;
|
|
const state = () => page.evaluate(() => window.teamspeachDiagnostics.snapshot());
|
|
|
|
async function launch() {
|
|
app = await launchApp({ profile, exe });
|
|
page = await app.firstWindow();
|
|
page.on('pageerror', (error) => errors.push(error.message));
|
|
await page.setViewportSize({ width: 1280, height: 800 });
|
|
await page.waitForFunction(() => window.teamspeachDiagnostics);
|
|
}
|
|
async function checkBindings(language) {
|
|
const problems = await page.evaluate(async (locale) => {
|
|
const { t, getLanguage } = await import('./js/i18n.js');
|
|
const issues = [];
|
|
if (document.documentElement.lang !== locale || getLanguage() !== locale) issues.push('wrong active locale');
|
|
for (const el of document.querySelectorAll('[data-i18n]')) {
|
|
const expected = el.id === 'mic-test' ? [t('ui.stop.test'), t('audio.test.record')] : [t(el.dataset.i18n)];
|
|
if (!expected.includes(el.textContent)) issues.push(el.id || el.dataset.i18n);
|
|
}
|
|
for (const attr of ['title', 'aria-label', 'placeholder']) {
|
|
for (const el of document.querySelectorAll(`[data-i18n-${attr}]`)) {
|
|
// Dynamic mute/stream controls intentionally override their initial label.
|
|
if (['btn-mute', 'btn-deafen', 'stream-mute'].includes(el.id)) continue;
|
|
if (attr === 'title' && ['btn-away', 'btn-talk-power'].includes(el.id)) {
|
|
const keys = el.id === 'btn-away' ? ['admin.available', 'admin.away'] : ['admin.talk.pending', 'admin.talk.queue'];
|
|
if (!keys.some(key => el.title === t(key))) issues.push(`${el.id}:${attr}`);
|
|
continue;
|
|
}
|
|
if (el.getAttribute(attr) !== t(el.getAttribute(`data-i18n-${attr}`))) issues.push(`${el.id}:${attr}`);
|
|
}
|
|
}
|
|
return issues;
|
|
}, language);
|
|
assert.deepEqual(problems, []);
|
|
}
|
|
async function categories(language) {
|
|
await page.evaluate(() => document.querySelectorAll('.toast .icon-btn').forEach((button) => button.click()));
|
|
const panels = await page.locator('#settings-nav [data-panel]').evaluateAll(nodes => nodes.map(node => node.dataset.panel));
|
|
assert.ok(panels.length > 0, 'settings navigation is populated');
|
|
for (const panel of panels) {
|
|
await page.click(`#settings-nav [data-panel="${panel}"]`);
|
|
await page.evaluate(() => { document.querySelector('.settings-scroll').scrollTop = 0; });
|
|
await page.waitForFunction(() => !document.querySelector('#language-select').disabled);
|
|
if (panel === 'audio') await page.waitForFunction(() => document.querySelector('#input-device').options.length > 0);
|
|
if (panel === 'about') await page.waitForFunction(() => document.querySelector('#diag-list').children.length > 0);
|
|
await checkBindings(language);
|
|
{
|
|
await page.screenshot({ path: path.join(out, `${language}-${panel}-1280.png`) });
|
|
await page.setViewportSize({ width: 880, height: 560 });
|
|
await page.screenshot({ path: path.join(out, `${language}-${panel}-880.png`) });
|
|
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth || document.body.scrollWidth > innerWidth);
|
|
assert.equal(overflow, false, `${language}/${panel} horizontal overflow`);
|
|
if (panel === 'about') {
|
|
await page.locator('#update-status').scrollIntoViewIfNeeded();
|
|
await page.screenshot({ path: path.join(out, `${language}-updates-880.png`) });
|
|
}
|
|
await page.setViewportSize({ width: 1280, height: 800 });
|
|
}
|
|
}
|
|
await closeSettings(page);
|
|
for (const control of ['btn-mute', 'btn-deafen']) {
|
|
await page.click(`#${control}`, { button: 'right' });
|
|
await page.waitForSelector('.device-menu:not([aria-busy])');
|
|
const actual = await page.locator('.device-menu [role="menuitemradio"]').count();
|
|
assert.ok(actual > 0);
|
|
await page.evaluate(async (kind) => {
|
|
const { t } = await import('./js/i18n.js');
|
|
const menu = document.querySelector('.device-menu');
|
|
if (menu.getAttribute('aria-label') !== t(kind === 'btn-mute' ? 'ui.microphone' : 'ui.output.device')) throw new Error('Device menu title not localized');
|
|
if (menu.querySelector('.menu-item-secondary .menu-label').textContent !== t('ui.audio.settings')) throw new Error('Device menu action not localized');
|
|
}, control);
|
|
await page.screenshot({ path: path.join(out, `${language}-${control}-menu.png`) });
|
|
await page.keyboard.press('Escape');
|
|
}
|
|
await page.click('#btn-settings');
|
|
record('all rendered categories and device menus', { language, panels });
|
|
}
|
|
async function switchTo(language) {
|
|
await page.click('#settings-nav [data-panel="appearance"]');
|
|
await page.selectOption('#language-select', language);
|
|
await page.waitForFunction((value) => document.documentElement.lang === value && !document.querySelector('#language-select').disabled, language);
|
|
assert.equal(prefs().language, language);
|
|
}
|
|
|
|
try {
|
|
await launch();
|
|
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 20000 });
|
|
assert.equal(await page.locator('html').getAttribute('lang'), 'en');
|
|
await checkBindings('en');
|
|
await page.screenshot({ path: path.join(out, 'en-onboarding.png') });
|
|
await page.fill('#onboarding-nick', 'LocaleSmoke');
|
|
await page.click('#onboarding-submit');
|
|
await page.waitForSelector('#view-app', { state: 'visible' });
|
|
await page.screenshot({ path: path.join(out, 'en-connect.png') });
|
|
const before = await state();
|
|
assert.equal(before.conn, 'disconnected');
|
|
assert.equal(before.voice.capturing, false);
|
|
const originalPrefs = await page.evaluate(() => window.teamspeach.getPrefs());
|
|
await page.fill('#connect-address', 'example.invalid:9987');
|
|
await page.click('#btn-settings');
|
|
await categories('en');
|
|
// A visible application-owned toast must reformat without being re-created.
|
|
await page.evaluate(async () => {
|
|
const { toast } = await import('./js/toast.js');
|
|
const { t } = await import('./js/i18n.js');
|
|
toast(() => t('ui.uid.copied'));
|
|
});
|
|
await switchTo('ru');
|
|
const after = await state();
|
|
assert.deepEqual(after.profile, before.profile);
|
|
assert.equal(after.conn, before.conn);
|
|
assert.equal(after.voice.capturing, false);
|
|
assert.deepEqual(after.audio, before.audio);
|
|
assert.deepEqual(withoutLanguage(await page.evaluate(() => window.teamspeach.getPrefs())), withoutLanguage(originalPrefs));
|
|
assert.equal(await page.inputValue('#connect-address'), 'example.invalid:9987');
|
|
await page.evaluate(async () => {
|
|
const { t } = await import('./js/i18n.js');
|
|
const message = [...document.querySelectorAll('.toast-text')].at(-1);
|
|
if (!message || message.textContent !== t('ui.uid.copied')) throw new Error('Existing toast did not switch language');
|
|
});
|
|
await categories('ru');
|
|
await closeSettings(page);
|
|
await page.screenshot({ path: path.join(out, 'ru-connect.png') });
|
|
await app.close();
|
|
app = null;
|
|
await launch();
|
|
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
|
|
assert.equal(await page.locator('html').getAttribute('lang'), 'ru');
|
|
assert.deepEqual((await state()).profile, before.profile);
|
|
record('restart retains Russian and identity');
|
|
await page.click('#btn-settings');
|
|
await switchTo('en');
|
|
await checkBindings('en');
|
|
assert.equal((await state()).voice.capturing, false);
|
|
assert.deepEqual((await state()).profile, before.profile);
|
|
assert.deepEqual(errors, []);
|
|
record('switch back to English preserves disconnected state');
|
|
} catch (error) {
|
|
if (page) {
|
|
record('failure diagnostics', await page.evaluate(() => ({ body: document.body.innerText, state: window.teamspeachDiagnostics?.snapshot() })).catch(error => ({ error: String(error) })));
|
|
await page.screenshot({ path: path.join(out, 'failure.png') }).catch(() => {});
|
|
}
|
|
failed = error;
|
|
record('FAILED', { error: error.stack || String(error), pageErrors: errors });
|
|
} finally {
|
|
if (app) await app.close().catch(() => {});
|
|
rmSync(profile, { recursive: true, force: true });
|
|
writeFileSync(path.join(out, 'result.json'), JSON.stringify({ ok: !failed, steps, pageErrors: errors }, null, 2));
|
|
}
|
|
process.exitCode = failed ? 1 : 0;
|