Files
OmniRoute/tests/_setup/jsdomGlobal.ts
Dizzle d5dfcfff58 feat(combo): choose sort method for combo models (manual/provider/score/name) (#11812)
Lets the combo dashboard builder order models manually/by-provider/by-score/by-name — the choice is stored in config.modelSort and re-applied on load and after adding models. Score-based ordering fetches provider rankings from the existing /api/free-provider-rankings endpoint; the field is inert on execution (client-side hint only). 9/9 focused tests passing (schema, sort logic, and rendered component). Thanks!
2026-08-28 12:37:58 -03:00

50 lines
1.3 KiB
TypeScript

import { JSDOM } from "jsdom";
const dom = new JSDOM("<!doctype html><html><body></body></html>", { url: "http://localhost" });
for (const key of [
"window",
"document",
"HTMLElement",
"Element",
"Node",
"Event",
"CustomEvent",
"MouseEvent",
"KeyboardEvent",
] as const) {
try {
(globalThis as unknown as Record<string, unknown>)[key] = (
dom.window as unknown as Record<string, unknown>
)[key];
} catch {}
}
try {
Object.defineProperty(globalThis, "navigator", {
value: dom.window.navigator,
configurable: true,
writable: true,
});
} catch {}
try {
(globalThis as unknown as Record<string, unknown>).getComputedStyle =
dom.window.getComputedStyle.bind(dom.window);
} catch {}
if (typeof (globalThis as unknown as { matchMedia?: unknown }).matchMedia !== "function") {
(globalThis as unknown as { window: { matchMedia?: unknown } }).window.matchMedia = () =>
({
matches: false,
media: "",
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
}) as unknown as MediaQueryList;
(globalThis as unknown as Record<string, unknown>).matchMedia = (
globalThis as unknown as { window: { matchMedia: unknown } }
).window.matchMedia;
}