Files
mdg-filius/packages/editor/test/bridge.test.ts
T
julian.kiedaischandClaude Opus 5.5 63273916b5 feat(editor): F4.3 the editor's frame and surface; a switch's cloud read and written
packages/editor (React 18, Vite) draws a document as Java FILIUS does: Java's
default hardware icons, the device button of JSidebarButton, cables as
JCablePanel's quadratic curve between the buttons' middles, wireless cables
dashed, documentation items below. The surface moves with mouse and finger
(the pointer captured only once it moved) and zooms with Ctrl and the
wheel, a trackpad pinch, two fingers and the zoom bar; the first view shows
all. German and English catalogs with Java's device names, the dashboard's
colour tokens, the bridge with its origin check. packages/doc gets the
drawing's light view of a document.

Java's Switch.cloud (the Internet in the examples) was lost on reading; it
is now read, kept in the model and written, with FlsOracle and the corpus,
written and exported checks renewed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 09:05:25 +00:00

54 lines
2.5 KiB
TypeScript

// The bridge to the dashboard: only the expected origin, only this version,
// and the editor says when it listens.
import { describe, expect, it } from 'vitest';
import { BRIDGE_VERSION, startBridge } from '../src/bridge/dashboardBridge.js';
function fakeWindow() {
const posted: [unknown, string][] = [];
const listeners = new Set<(event: { origin: string; data: unknown }) => void>();
return {
posted,
window: {
parent: { postMessage: (message: unknown, origin: string) => posted.push([message, origin]) },
addEventListener: (_: 'message', listener: (event: { origin: string; data: unknown }) => void) => listeners.add(listener),
removeEventListener: (_: 'message', listener: (event: { origin: string; data: unknown }) => void) => listeners.delete(listener),
},
send: (origin: string, data: unknown) => {
for (const listener of listeners) listener({ origin, data });
},
listening: () => listeners.size,
};
}
describe('the bridge to the dashboard', () => {
it('says it is ready, to the dashboard only', () => {
const fake = fakeWindow();
startBridge(fake.window, 'https://dashboard.example', { onLocale: () => {}, onTheme: () => {} });
expect(fake.posted).toEqual([[{ v: BRIDGE_VERSION, type: 'ready' }, 'https://dashboard.example']]);
});
it('takes language and colours from the dashboard, and nothing from elsewhere', () => {
const fake = fakeWindow();
const got: unknown[] = [];
const stop = startBridge(fake.window, 'https://dashboard.example', {
onLocale: (locale) => got.push(['locale', locale]),
onTheme: (theme, tokens) => got.push(['theme', theme, tokens]),
});
fake.send('https://evil.example', { v: 1, type: 'setLocale', locale: 'en' });
fake.send('https://dashboard.example', { v: 2, type: 'setLocale', locale: 'en' });
fake.send('https://dashboard.example', { v: 1, type: 'setLocale', locale: 7 });
fake.send('https://dashboard.example', { v: 1, type: 'setTheme', theme: 'pink' });
fake.send('https://dashboard.example', null);
expect(got).toEqual([]);
fake.send('https://dashboard.example', { v: 1, type: 'setLocale', locale: 'en-GB' });
fake.send('https://dashboard.example', { v: 1, type: 'setTheme', theme: 'dark', tokens: { '--accent': '#123456', color: 'red', '--bad': 3 } });
expect(got).toEqual([
['locale', 'en-GB'],
['theme', 'dark', { '--accent': '#123456' }],
]);
stop();
expect(fake.listening()).toBe(0);
});
});