Preserve explicit App approval, expose playback and transfer progress, and keep shared identity and native window presentation coherent. Retain terminal fallback, cancel external input safely, and reject withdrawn UDP preparation before adoption. Reuse exact Web artifacts across matched targets and extend the existing text participant with typed history, replies and reactions. Verified Rust/WASM/protocol checks, 1614 Web tests, Windows capture compilation and five external input lifecycle tests.
56 lines
2.6 KiB
TypeScript
56 lines
2.6 KiB
TypeScript
import { Children, isValidElement, type ComponentProps, type MouseEvent, type ReactNode } from "react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { Btn, Chip, SwitchItem } from "../src/client/components/living/primitives";
|
|
|
|
vi.mock("react", async importOriginal => ({
|
|
...await importOriginal<typeof import("react")>(),
|
|
useId: () => "control",
|
|
}));
|
|
|
|
vi.mock("../src/client/ui/copy", () => ({
|
|
useCopy: () => ({ t: (key: string) => key }),
|
|
}));
|
|
|
|
function button(node: ReactNode): ComponentProps<"button"> | undefined {
|
|
if (!isValidElement<{ children?: ReactNode }>(node)) return;
|
|
if (node.type === "button") return node.props;
|
|
return Children.toArray(node.props.children).map(button).find(Boolean);
|
|
}
|
|
|
|
const controls = {
|
|
button: (activate: () => void) => Btn({ icon: "play", title: "playback.play", hint: "hint-quality", onClick: activate }),
|
|
chip: (activate: () => void) => Chip({ selected: false, title: "720p", hint: "hint-quality", onClick: activate, children: "720p" }),
|
|
switch: (activate: () => void) => SwitchItem({ checked: false, label: "Setting", hint: "hint-quality", onChange: activate }),
|
|
};
|
|
|
|
describe("Hinted control activation", () => {
|
|
it("keeps a dialog invoker focused so native modal dismissal can return to it", () => {
|
|
const activate = vi.fn(), blur = vi.fn();
|
|
const control = button(Btn({ icon: "sliders", title: "host.settings.button", textTooltip: true,
|
|
hasPopup: "dialog", onClick: activate }))!;
|
|
control.onClick!({ detail: 1, currentTarget: { blur } } as unknown as MouseEvent<HTMLButtonElement>);
|
|
expect(activate).toHaveBeenCalledOnce();
|
|
expect(blur).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it.each(Object.entries(controls))("%s applies the chosen action before focus-leave commits a draft", (_name, render) => {
|
|
const changes: string[] = [];
|
|
let pendingDraft = true;
|
|
const control = button(render(() => { pendingDraft = false; changes.push("chosen action"); }))!;
|
|
const blur = vi.fn(() => { if (pendingDraft) changes.push("unconfirmed draft"); });
|
|
|
|
control.onClick!({ detail: 1, currentTarget: { blur } } as unknown as MouseEvent<HTMLButtonElement>);
|
|
|
|
expect(changes).toEqual(["chosen action"]);
|
|
expect(blur).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it.each(Object.entries(controls))("%s keeps keyboard focus when activated", (_name, render) => {
|
|
const activate = vi.fn();
|
|
const blur = vi.fn();
|
|
button(render(activate))!.onClick!({ detail: 0, currentTarget: { blur } } as unknown as MouseEvent<HTMLButtonElement>);
|
|
expect(activate).toHaveBeenCalledOnce();
|
|
expect(blur).not.toHaveBeenCalled();
|
|
});
|
|
});
|