Files
client/scripts/smoke-tree-layout.mjs
T
omar f618d8bce9
ci / linux-arm64-cross (push) Successful in 3m22s
ci / linux-x64 (push) Successful in 3m32s
chat: add safe hybrid Markdown editing with strict CSP
2026-11-02 11:32:31 +03:00

176 lines
9.8 KiB
JavaScript

// Local fixture UI acceptance, not live-server evidence. The fixture is injected by this test only;
// no server, physical microphone, user profile or private media is opened.
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { launchApp, root, waitForAsync } from './lib/electron-app.mjs';
const args = process.argv.slice(2);
const out = path.resolve(root, args.includes('--out') ? args[args.indexOf('--out') + 1] : 'smoke-out/tree-layout');
mkdirSync(out, { recursive: true });
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-layout-'));
const result = { scope: 'Disposable Electron, local synthetic tree fixture; no live-server claims', steps: [], errors: [] };
let app;
let page;
let fixtureSnapshot;
let revision = 0;
const send = (event) => app.evaluate(({ BrowserWindow }, value) => BrowserWindow.getAllWindows()[0].webContents.send('core:event', { ...value, connectionId: 'c1' }), event);
async function launch() {
app = await launchApp({ exe: args.includes('--exe') ? args[args.indexOf('--exe') + 1] : undefined, profile, args: ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'] });
page = await app.firstWindow();
page.on('pageerror', (error) => result.errors.push(error.message));
await page.waitForFunction(() => Boolean(window.teamspeachDiagnostics), null, { timeout: 20000 });
await page.waitForSelector('#view-onboarding:not([hidden]), #view-app:not([hidden])');
if (await page.isVisible('#view-onboarding')) {
await page.fill('#onboarding-nick', 'LayoutFixtureProbe');
await page.click('#onboarding-submit');
}
await page.waitForSelector('#view-app', { state: 'visible' });
await page.setViewportSize({ width: 1280, height: 800 });
}
async function fixture() {
fixtureSnapshot = {
event: 'snapshot', rev: ++revision, own_client_id: 1, own_channel_id: 10,
server: { name: 'Local UI fixture — not a live server', version: 'fixture', welcome_message: '' }, server_groups: [], channel_groups: [],
channels: [
{ id: 10, parent_id: 0, depth: 0, name: 'Fixture voice channel', max_clients: -1, codec: 'opus_voice' },
{ id: 11, parent_id: 10, depth: 1, name: 'Child stays visible', max_clients: -1, codec: 'opus_voice' },
{ id: 12, parent_id: 0, depth: 0, name: 'Other channel', max_clients: -1, codec: 'opus_voice' },
],
clients: Array.from({ length: 8 }, (_, i) => ({ id: i + 1, uid: `fixture-${i}`, nickname: `Fixture member ${i + 1}`, channel_id: i === 7 ? 11 : 10,
client_type: 'normal', talk_power: 0, is_self: i === 0, input_hardware: true, input_muted: true, output_muted: true, server_groups: [] })),
};
await send({ event: 'state', state: 'connecting', address: 'fixture.invalid:9987' });
await send({ event: 'audio_state', input_muted: true, output_muted: true, transmitting: false });
await send(fixtureSnapshot);
await page.waitForSelector('#session-view', { state: 'visible' });
await page.locator('#tree [data-cid="12"] > .row-btn').click();
await send({ event: 'talking', client_id: 2, talking: true });
await page.evaluate(async () => {
const { S } = await import('./js/state.js');
window.__layoutAudioBaseline = JSON.stringify(window.teamspeachDiagnostics.snapshot().voice);
window.__layoutAudioObject = S.audio;
window.__layoutContexts = 0;
if (!window.__layoutOriginalAudioContext) {
window.__layoutOriginalAudioContext = window.AudioContext;
window.AudioContext = new Proxy(window.AudioContext, { construct(target, values) { window.__layoutContexts++; return Reflect.construct(target, values); } });
}
});
}
const collapse = () => page.locator('#tree [data-cid="10"] .channel-collapse');
const members = () => page.locator('#tree .member-row').count();
const width = () => page.locator('#server-panel').evaluate((el) => Math.round(el.getBoundingClientRect().width));
const shot = (name) => page.screenshot({ path: path.join(out, name) });
async function unchanged() {
assert.deepEqual(await page.evaluate(async () => {
const { S } = await import('./js/state.js');
return { own: S.snap.own_channel_id, selected: S.selectedChannelId, sameAudio: S.audio === window.__layoutAudioObject,
sameVoice: JSON.stringify(window.teamspeachDiagnostics.snapshot().voice) === window.__layoutAudioBaseline, contexts: window.__layoutContexts };
}), { own: 10, selected: 12, sameAudio: true, sameVoice: true, contexts: 0 });
}
try {
await launch();
await fixture();
assert.equal(await members(), 8);
await shot('01-expanded-wide-dark.png');
await collapse().click();
assert.equal(await collapse().getAttribute('aria-expanded'), 'false');
assert.equal(await members(), 1);
assert.equal(await page.locator('#tree .channel-row').count(), 3);
assert.equal(await page.locator('#tree [data-cid="10"] .channel-preview .avatar').count(), 5);
assert.equal(await page.locator('#tree .channel-preview-count').textContent(), '+2');
await unchanged();
await shot('02-collapsed-wide-dark.png');
await collapse().press('Space');
assert.equal(await members(), 8);
await collapse().press('Enter');
assert.equal(await members(), 1);
// A membership/talking snapshot while collapsed must update the summary, not reopen it.
fixtureSnapshot.clients.find((client) => client.id === 7).channel_id = 11;
fixtureSnapshot.rev = ++revision;
await send(fixtureSnapshot);
await send({ event: 'talking', client_id: 3, talking: true });
await page.waitForFunction(() => document.querySelector('#tree .channel-preview [data-key="3"]')?.dataset.talking === 'true');
assert.equal(await members(), 2);
assert.equal(await page.locator('#tree .channel-preview-count').textContent(), '+1');
assert.equal(await page.locator('#tree .channel-preview [data-key="3"]').getAttribute('data-talking'), 'true');
await collapse().click();
assert.equal(await members(), 8);
await unchanged();
result.steps.push('Direct-member pointer/Space/Enter collapse, descendants, live fixture membership/talking update, five-avatar bound and unchanged voice/selection');
const separator = page.locator('#sidebar-splitter');
const before = await width();
const bounds = await separator.boundingBox();
await page.mouse.move(bounds.x + bounds.width / 2, bounds.y + 200);
await page.mouse.down();
await page.mouse.move(bounds.x + 180, bounds.y + 200, { steps: 12 });
assert.equal(await page.locator('body').evaluate((el) => el.classList.contains('is-resizing')), true);
await page.mouse.up();
assert.ok(await width() > before + 150);
assert.equal(await page.locator('body').evaluate((el) => el.classList.contains('is-resizing')), false);
await separator.press('Home');
assert.equal(await width(), Number(await separator.getAttribute('aria-valuemin')));
await separator.press('End');
assert.equal(await width(), Number(await separator.getAttribute('aria-valuemax')));
await page.setViewportSize({ width: 900, height: 650 });
await page.waitForTimeout(100);
assert.ok(await width() <= 534);
assert.equal(await page.locator('#tree .channel-row').count(), 3);
assert.equal(await page.locator('#chat-input').isVisible(), true);
await page.locator('#chat-input').fill('Selectable local fixture text');
await page.locator('#chat-input').press('ControlOrMeta+A');
assert.deepEqual(await page.evaluate(async () => { const editor = (await import('./js/chat.js')).composerEditor(); return { value: editor.value, selected: editor.selectionEnd - editor.selectionStart, native: getSelection().toString() }; }),
{ value: 'Selectable local fixture text', selected: 29, native: 'Selectable local fixture text' });
await shot('03-narrow-clamped-dark.png');
await separator.press('Enter');
assert.equal(await width(), 280);
await waitForAsync(page, async () => (await (await import('./js/core.js')).tp.getPrefs()).sidebarWidth === 0);
await page.setViewportSize({ width: 1280, height: 800 });
await page.waitForTimeout(100);
assert.equal(await width(), 346);
await page.setViewportSize({ width: 900, height: 650 });
await page.waitForTimeout(100);
assert.equal(await width(), 280);
await separator.press('ArrowRight');
assert.equal(await width(), 296);
await separator.dblclick();
assert.equal(await width(), 280);
await separator.press('ArrowRight');
await collapse().click();
await unchanged();
await waitForAsync(page, async () => (await (await import('./js/core.js')).tp.getPrefs()).sidebarWidth === 296);
result.steps.push('Pointer capture drag, Home/End/arrow/Enter/double-click, narrow resize clamp, copyable composer, no AudioContext rebuild');
await page.evaluate(async () => {
const { tp } = await import('./js/core.js');
const { setLanguage } = await import('./js/i18n.js');
await tp.setPrefs({ theme: 'light', language: 'ru' });
setLanguage('ru');
});
await shot('04-collapsed-narrow-light-ru.png');
assert.match(await collapse().getAttribute('aria-label'), /Показать участников/);
await app.close(); app = null;
await launch();
await fixture();
assert.equal(await width(), 296);
assert.equal(await collapse().getAttribute('aria-expanded'), 'false');
assert.equal(await members(), 1);
await collapse().click();
assert.equal(await members(), 8);
await unchanged();
await shot('05-restored-wide-light-ru.png');
result.steps.push('Disposable-profile reopen retains sidebar width and server-scoped collapse; expansion recovers every member');
assert.deepEqual(result.errors, []);
result.ok = true;
} catch (error) {
result.ok = false;
result.error = String(error.stack || error);
} finally {
if (app) await app.close().catch(() => {});
rmSync(profile, { recursive: true, force: true });
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
}
console.log(JSON.stringify(result, null, 2));
process.exitCode = result.ok ? 0 : 1;