From b6ac72147e3dcd78c66d99c4ca3370b40fe48840 Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Thu, 18 Jun 2026 10:06:50 -0300 Subject: [PATCH] test(auth): align login tests with disabled submit behavior --- e2e/auth/login.spec.ts | 14 ++++++++---- .../app/(auth)/login.integration.test.tsx | 22 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/e2e/auth/login.spec.ts b/e2e/auth/login.spec.ts index 26bbafe6..af8c9e71 100644 --- a/e2e/auth/login.spec.ts +++ b/e2e/auth/login.spec.ts @@ -44,13 +44,19 @@ test.describe("Login page", () => { await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible(); }); - test("shows client-side validation errors on empty submit", async ({ page }) => { + test("disables submit until email and password are valid", async ({ page }) => { await page.goto("/login"); - await page.getByRole("button", { name: "Sign In" }).click(); + const submitButton = page.getByRole("button", { name: "Sign In" }); - await expect(page.getByText("Email is required")).toBeVisible(); - await expect(page.getByText("Password is required")).toBeVisible(); + await expect(submitButton).toBeDisabled(); + + await page.locator("#login-email").fill("not-an-email"); + await page.locator("#login-password").fill("secret123"); + await expect(submitButton).toBeDisabled(); + + await page.locator("#login-email").fill("user@seahavenind.com"); + await expect(submitButton).toBeEnabled(); }); test("shows error message for invalid credentials", async ({ page }) => { diff --git a/src/test/app/(auth)/login.integration.test.tsx b/src/test/app/(auth)/login.integration.test.tsx index c590374b..e9dcf009 100644 --- a/src/test/app/(auth)/login.integration.test.tsx +++ b/src/test/app/(auth)/login.integration.test.tsx @@ -52,7 +52,7 @@ describe("LoginPage integration", () => { vi.mocked(authApi.getSession).mockResolvedValue(null); }); - it("shows validation errors on empty submit", async () => { + it("keeps submit disabled until email and password are valid", async () => { renderWithProviders(, { route: "/login" }); await waitFor(() => { @@ -61,14 +61,20 @@ describe("LoginPage integration", () => { const form = document.querySelector("form"); expect(form).not.toBeNull(); - await userEvent.click(within(form!).getByRole("button", { name: /sign in/i })); - await waitFor(() => { - expect(screen.getByText("Email is required")).toBeInTheDocument(); - }); - expect(screen.getByText("Password is required")).toBeInTheDocument(); - expect(screen.getByRole("heading", { name: "Welcome back" })).toBeInTheDocument(); - expect(authApi.login).not.toHaveBeenCalled(); + const submitButton = within(form!).getByRole("button", { name: /sign in/i }); + const emailInput = within(form!).getByLabelText("Email"); + const passwordInput = within(form!).getByLabelText("Password"); + + expect(submitButton).toBeDisabled(); + + await userEvent.type(emailInput, "not-an-email"); + await userEvent.type(passwordInput, "secret123"); + expect(submitButton).toBeDisabled(); + + await userEvent.clear(emailInput); + await userEvent.type(emailInput, "user@seahavenind.com"); + expect(submitButton).toBeEnabled(); }); it("logs in successfully and navigates to dashboard", async () => {