diff --git a/tests/unit/ui/add-api-key-modal-enter-key.test.ts b/tests/unit/ui/add-api-key-modal-enter-key.test.ts
deleted file mode 100644
index 2532eb297e..0000000000
--- a/tests/unit/ui/add-api-key-modal-enter-key.test.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { describe, it } from "node:test";
-import assert from "node:assert/strict";
-import fs from "node:fs";
-import path from "node:path";
-
-describe("AddApiKeyModal Enter key submit (#10995)", () => {
- it("AddApiKeyModal attaches onKeyDown Enter handler to the API Key input", () => {
- const modalPath = path.resolve(
- process.cwd(),
- "src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal.tsx"
- );
- const content = fs.readFileSync(modalPath, "utf8");
- assert.ok(
- content.includes("onKeyDown"),
- "AddApiKeyModal must contain onKeyDown event handler for Enter key validation"
- );
- assert.ok(
- content.includes('e.key === "Enter"'),
- "onKeyDown handler must check for Enter key press"
- );
- assert.ok(
- content.includes("handleValidate()"),
- "Enter key press must invoke handleValidate()"
- );
- });
-});
diff --git a/tests/unit/ui/add-api-key-modal-enter-key.test.tsx b/tests/unit/ui/add-api-key-modal-enter-key.test.tsx
new file mode 100644
index 0000000000..1c28a13230
--- /dev/null
+++ b/tests/unit/ui/add-api-key-modal-enter-key.test.tsx
@@ -0,0 +1,104 @@
+// @vitest-environment jsdom
+//
+// #10995 — Enter key in AddApiKeyModal triggers key validation without requiring a mouse click on Check.
+import React, { act } from "react";
+import { createRoot } from "react-dom/client";
+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
+
+vi.mock("next-intl", () => ({
+ useTranslations: () => (key: string) => key,
+}));
+
+const { default: AddApiKeyModal } =
+ await import("../../../src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal");
+
+const containers: Array<{ root: ReturnType
; el: HTMLDivElement }> = [];
+
+function render(props: Record) {
+ const el = document.createElement("div");
+ document.body.appendChild(el);
+ const root = createRoot(el);
+ act(() => {
+ root.render(
+ undefined}
+ onClose={() => {}}
+ {...(props as any)}
+ />
+ );
+ });
+ containers.push({ root, el });
+ return el;
+}
+
+function setInputValue(input: HTMLInputElement, value: string) {
+ const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")!.set!;
+ act(() => {
+ setter.call(input, value);
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+}
+
+function dispatchKeyDown(element: HTMLElement, key: string) {
+ act(() => {
+ element.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
+ });
+}
+
+describe("AddApiKeyModal Enter key submit (#10995)", () => {
+ let originalFetch: typeof global.fetch;
+
+ beforeEach(() => {
+ originalFetch = global.fetch;
+ });
+
+ afterEach(() => {
+ global.fetch = originalFetch;
+ for (const { root, el } of containers) {
+ act(() => root.unmount());
+ el.remove();
+ }
+ containers.length = 0;
+ });
+
+ it("does not trigger validation on Enter when input is empty", () => {
+ const fetchMock = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => ({ valid: true }),
+ });
+ global.fetch = fetchMock as any;
+
+ const el = render({});
+ const input = el.querySelector('input[type="password"]');
+ expect(input).toBeTruthy();
+
+ dispatchKeyDown(input!, "Enter");
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
+
+ it("triggers validation on Enter key press when API key is provided", async () => {
+ const fetchMock = vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => ({ valid: true }),
+ });
+ global.fetch = fetchMock as any;
+
+ const el = render({});
+ const input = el.querySelector('input[type="password"]');
+ expect(input).toBeTruthy();
+
+ setInputValue(input!, "sk-test1234567890");
+ dispatchKeyDown(input!, "Enter");
+
+ expect(fetchMock).toHaveBeenCalledWith(
+ "/api/providers/validate",
+ expect.objectContaining({
+ method: "POST",
+ body: expect.stringContaining("sk-test1234567890"),
+ })
+ );
+ });
+});