waybetter/packages/shell/tests/windowControls.test.ts
CRT b2a91ff7b3 Extract the wayBetter framework core from wayBetter for X
Site-agnostic parts of the X app, behind a small site adapter:

- crates/waybetter-host: webview-label security policy and tab rect
  clamp, account profiles with native-owned accounts (AccountRules),
  plugin store with bundled-plugin upgrades (PluginHost), signed
  data-only hotfix channel, update scheduling and crash handshake, tab
  payloads/link routing/tab-chrome validation, and (feature "tauri")
  webview helpers and the Windows system menu.
- packages/runtime: DOM hub, request hub, plugin API core, OKLab theme
  color model, split-view rail hiding, link routing and account
  reporting, each configured by a SiteAdapter.
- packages/shell: address bar, pane, link-drop, profile, palette and
  update-chip models, and window controls with the Tauri API injected.

Tests moved/adapted from the app: 45 Rust (headless), 40 TypeScript.
2026-09-28 03:01:33 +07:00

29 lines
1.3 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createWindowControls, type NativeWindow } from '../src/windowControls.ts';
test('window controls call the injected window and never throw', async () => {
const calls: string[] = [];
const failing = () => Promise.reject(new Error('no window'));
const win: NativeWindow = {
minimize: async () => { calls.push('minimize'); },
toggleMaximize: failing,
close: async () => { calls.push('close'); },
startResizeDragging: async direction => { calls.push(`resize:${direction}`); },
isMaximized: async () => true,
onResized: async () => () => {},
};
const invoked: unknown[] = [];
const controls = createWindowControls(async (command, args) => { invoked.push([command, args]); }, () => win);
await controls.minimize();
await controls.toggleMaximize();
await controls.close();
await controls.startResize('SouthEast');
await controls.systemMenu(10, 20);
let maximized: boolean | null = null;
await controls.onMaximizedChange(value => { maximized = value; });
await Promise.resolve();
assert.deepEqual(calls, ['minimize', 'close', 'resize:SouthEast']);
assert.deepEqual(invoked, [['window_system_menu', { x: 10, y: 20 }]]);
assert.equal(maximized, true);
});