({
+ useRouter: () => ({ push: vi.fn() }),
+}));
+
+vi.mock("next-intl", () => ({
+ useTranslations: () => (key: string) => key,
+}));
+
+vi.mock("@/lib/server/verify", () => ({
+ verifyTOTP: vi.fn(),
+}));
+
+vi.mock("@/lib/client", () => ({
+ handleServerActionResponse: vi.fn(),
+ completeFlowOrGetUrl: vi.fn(),
+}));
+
+vi.mock("qrcode.react", () => ({
+ QRCodeSVG: ({ value }: { value: string }) => ,
+}));
+
+describe("TotpRegister", () => {
+ afterEach(cleanup);
+
+ test("should autofocus the code input on mount", () => {
+ const { getByTestId } = render(
+ ,
+ );
+ expect(getByTestId("code-text-input")).toHaveFocus();
+ });
+});
diff --git a/apps/login/src/components/totp-register.tsx b/apps/login/src/components/totp-register.tsx
index 8a6424689..3a268ec6b 100644
--- a/apps/login/src/components/totp-register.tsx
+++ b/apps/login/src/components/totp-register.tsx
@@ -116,6 +116,7 @@ export function TotpRegister({ uri, loginName, sessionId, requestId, organizatio
({
+ useRouter: () => ({ push: vi.fn() }),
+}));
+
+vi.mock("next-intl", () => ({
+ useTranslations: () => (key: string) => key,
+}));
+
+vi.mock("@/lib/server/loginname", () => ({
+ sendLoginname: vi.fn(),
+}));
+
+describe("UsernameForm", () => {
+ afterEach(cleanup);
+
+ test("should autofocus the loginName input on mount", () => {
+ const { getByTestId } = render(
+ ,
+ );
+ expect(getByTestId("username-text-input")).toHaveFocus();
+ });
+});
diff --git a/apps/login/src/components/username-form.tsx b/apps/login/src/components/username-form.tsx
index c98131c54..08ed561ec 100644
--- a/apps/login/src/components/username-form.tsx
+++ b/apps/login/src/components/username-form.tsx
@@ -101,6 +101,7 @@ export function UsernameForm({
{
afterEach(cleanup);
+ describe("Input Focus", () => {
+ test("should autofocus the code input on mount", () => {
+ const { getByTestId } = render(
+ ,
+ );
+ expect(getByTestId("code-text-input")).toHaveFocus();
+ });
+ });
+
describe("Auto-submit Behavior", () => {
test("should call sendVerification automatically when submit=true", async () => {
render();
diff --git a/apps/login/src/components/verify-form.tsx b/apps/login/src/components/verify-form.tsx
index 5d303a8c4..3fd53cb07 100644
--- a/apps/login/src/components/verify-form.tsx
+++ b/apps/login/src/components/verify-form.tsx
@@ -138,6 +138,7 @@ export function VerifyForm({ userId, loginName, organization, requestId, code, i