Files
client/test/titlebar.test.js
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring.

Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
2026-11-01 19:43:18 +03:00

71 lines
4.4 KiB
JavaScript

'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { EventEmitter } = require('node:events');
const { titlebarOptions, overlayColors, registerTitlebarIpc, bindTitlebar } = require('../app/main/titlebar');
function fixture(platform = 'win32') {
const win = new EventEmitter();
const contents = new EventEmitter();
const frame = { url: 'app://teamspeach/index.html' };
const state = { maximized: false, minimized: false, fullscreen: false, focused: false };
const messages = [], overlays = [], handlers = new Map();
contents.mainFrame = frame;
contents.isDestroyed = () => false;
contents.send = (channel, payload) => messages.push({ channel, payload });
Object.assign(win, { webContents: contents, isDestroyed: () => false, isMaximized: () => state.maximized, isMinimized: () => state.minimized, isFullScreen: () => state.fullscreen, isFocused: () => state.focused, setTitleBarOverlay: value => overlays.push(value) });
const theme = Object.assign(new EventEmitter(), { shouldUseDarkColors: true });
registerTitlebarIpc({ handle: (channel, fn) => handlers.set(channel, fn) }, () => win, 'app://teamspeach', platform);
bindTitlebar(win, theme, platform);
return { win, frame, state, theme, messages, overlays, read: event => handlers.get('window:get-state')(event), event: { sender: contents, senderFrame: frame }, handlers };
}
// Official TS6: captions sit in the 44px window bar (--tsv-header-window-bar-height) on --ts-new-header-bg
// (dark #121A2C, light rgb(235,235,235)). The dark fill matches an official capture (smoke-official-parity-offscreen);
// the 44px height is the source token — the available captures are cropped at the top and do not prove it.
test('hidden native titlebar retains platform caption controls and the official window-bar palette', () => {
for (const platform of ['win32', 'linux']) assert.deepEqual(titlebarOptions(platform, true), { titleBarStyle: 'hidden', titleBarOverlay: { color: '#121a2c', symbolColor: '#ffffff', height: 44 } });
assert.deepEqual(titlebarOptions('darwin', false), { titleBarStyle: 'hidden', trafficLightPosition: { x: 16, y: 15 } });
assert.deepEqual(overlayColors(false), { color: '#ebebeb', symbolColor: '#494949', height: 44 });
});
test('state IPC rejects child frames, wrong webContents, lookalike origins, credentials and destroyed windows', () => {
const f = fixture();
assert.deepEqual(f.read(f.event), { platform: 'win32', ...f.state });
assert.equal(f.read({ ...f.event, senderFrame: { url: f.frame.url } }), null);
assert.equal(f.read({ ...f.event, sender: {} }), null);
assert.equal(f.read({ ...f.event, senderFrame: null }), null);
for (const url of ['https://teamspeach/index.html', 'app://teamspeach.evil/index.html', 'app://teamspeach:99/index.html', 'app://user@teamspeach/index.html', 'about:blank', 'broken']) {
f.frame.url = url;
assert.equal(f.read(f.event), null, url);
}
f.frame.url = 'app://teamspeach/index.html';
f.win.isDestroyed = () => true;
assert.equal(f.read(f.event), null);
assert.deepEqual([...f.handlers.keys()], ['window:get-state'], 'no remote window-action dispatcher');
});
test('native state transitions publish current state once, without toggling native methods', () => {
const f = fixture();
for (const [event, field, value] of [['maximize', 'maximized', true], ['unmaximize', 'maximized', false], ['minimize', 'minimized', true], ['restore', 'minimized', false], ['enter-full-screen', 'fullscreen', true], ['leave-full-screen', 'fullscreen', false], ['focus', 'focused', true], ['blur', 'focused', false]]) {
f.state[field] = value;
const before = f.messages.length;
f.win.emit(event);
assert.equal(f.messages.length, before + 1);
assert.deepEqual(f.messages.at(-1), { channel: 'window:state', payload: { platform: 'win32', ...f.state } });
assert.equal(f.read(f.event)[field], value);
}
f.win.webContents.emit('did-finish-load');
assert.equal(f.messages.length, 9);
});
test('native theme updates synchronize overlay and release listener on close', () => {
const f = fixture();
f.theme.emit('updated');
f.theme.shouldUseDarkColors = false;
f.theme.emit('updated');
assert.deepEqual(f.overlays, [overlayColors(true), overlayColors(false)]);
f.win.emit('closed');
assert.equal(f.theme.listenerCount('updated'), 0);
f.theme.emit('updated');
assert.equal(f.overlays.length, 2);
const mac = fixture('darwin');
mac.theme.emit('updated');
assert.deepEqual(mac.overlays, []);
});