mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-15 19:52:50 +03:00
* fix(vision): preserve images for text-only routes * fix(i18n): complete Vietnamese vision bridge copy * fix(ci): drain prerelease tag input --------- Co-authored-by: rinseaid <rinseaid@rinseaid.net>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import React, { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import ModalityBridgeVisionTab from "@/app/(dashboard)/dashboard/settings/components/modalityBridge/ModalityBridgeVisionTab";
|
|
|
|
vi.mock("next-intl", () => ({ useTranslations: () => (key: string) => key }));
|
|
|
|
function jsonResponse(data: unknown) {
|
|
return { ok: true, json: async () => data } as Response;
|
|
}
|
|
|
|
describe("VisionBridgeSettingsTab (Modality Bridge vision tab)", () => {
|
|
let container: HTMLDivElement;
|
|
let root: Root;
|
|
const fetchMock = vi.fn();
|
|
|
|
beforeEach(async () => {
|
|
(
|
|
globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
|
).IS_REACT_ACT_ENVIRONMENT = true;
|
|
fetchMock.mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
const url = String(input);
|
|
if (url.includes("/api/models")) {
|
|
return jsonResponse({ models: [] });
|
|
}
|
|
if (url.includes("/api/modality-bridge/stats")) {
|
|
return jsonResponse({ vision: { bridged: 0, cacheHits: 0, failures: 0 }, audio: {} });
|
|
}
|
|
if (init?.method === "PATCH") return jsonResponse({});
|
|
return jsonResponse({});
|
|
});
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
await act(async () => {
|
|
root.render(<ModalityBridgeVisionTab />);
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
act(() => root.unmount());
|
|
container.remove();
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("exposes the text-only reroute setting and persists a toggle", async () => {
|
|
expect(container.textContent).toContain("visionBridgeRerouteTextOnlyLabel");
|
|
const toggles = container.querySelectorAll('[role="switch"]');
|
|
const rerouteToggle = toggles.item(1) as HTMLButtonElement;
|
|
await act(async () => {
|
|
rerouteToggle.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
"/api/settings",
|
|
expect.objectContaining({
|
|
method: "PATCH",
|
|
body: JSON.stringify({ visionBridgeRerouteTextOnly: true }),
|
|
})
|
|
);
|
|
});
|
|
});
|