Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions src/features/auth/SignUpPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it } from "vitest";
import { BrowserRouter } from "react-router-dom";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: 🟠 Major

Tests are mostly presence checks; add behavior assertions (e.g., sign-in link target and validation) and use MemoryRouter for isolation.

render(<MemoryRouter><SignUpPage /></MemoryRouter>);
expect(screen.getByRole('link',{name:/sign in/i})).toHaveAttribute('href','/signin');

import { SignUpPage } from "./SignUpPage";

const renderSignUpPage = () => {
return render(
<BrowserRouter>
<SignUpPage />
</BrowserRouter>,
);
};

describe("SignUpPage", () => {
it("should render the email input field", () => {
renderSignUpPage();

expect(screen.getByLabelText(/email/i)).toBeInTheDocument();
});

it("should render the password input field", () => {
renderSignUpPage();

expect(screen.getByLabelText(/^password$/i)).toBeInTheDocument();
});

it("should render the confirm password input field", () => {
renderSignUpPage();

expect(screen.getByLabelText(/confirm password/i)).toBeInTheDocument();
});

it("should allow typing in the email input", async () => {
renderSignUpPage();
const user = userEvent.setup();

const emailInput = screen.getByLabelText(/email/i);
await user.type(emailInput, "test@example.com");

expect(emailInput).toHaveValue("test@example.com");
});

it("should allow typing in the password input", async () => {
renderSignUpPage();
const user = userEvent.setup();

const passwordInput = screen.getByLabelText(/^password$/i);
await user.type(passwordInput, "password123");

expect(passwordInput).toHaveValue("password123");
});

it("should allow typing in the confirm password input", async () => {
renderSignUpPage();
const user = userEvent.setup();

const confirmPasswordInput = screen.getByLabelText(/confirm password/i);
await user.type(confirmPasswordInput, "password123");

expect(confirmPasswordInput).toHaveValue("password123");
});

it("should render the create account button", () => {
renderSignUpPage();

expect(
screen.getByRole("button", { name: /create account/i }),
).toBeInTheDocument();
});

it("should render the continue with google button", () => {
renderSignUpPage();

expect(
screen.getByRole("button", { name: /continue with google/i }),
).toBeInTheDocument();
});

it("should render the sign in link", () => {
renderSignUpPage();

expect(screen.getByRole("link", { name: /sign in/i })).toBeInTheDocument();
});
});
100 changes: 100 additions & 0 deletions src/features/auth/SignUpPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { useState } from "react";
import { Link } from "react-router-dom";
import { Button } from "../../components/button/Button";
import { Input } from "../../components/input/Input";
import { Card, CardBody } from "../../components/card/Card";
import { GoogleLogo } from "../../components/googlelogo/GoogleLogo";

export const SignUpPage = () => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");

const handleSubmit = (event: React.FormEvent) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: 🟠 Major

handleSubmit currently prevents default but never validates or triggers a sign-up flow; add at least a password/confirm match check and surface an error (and/or call into your auth API).

if (password !== confirmPassword) return setFormError("Passwords do not match");

event.preventDefault();
};

return (
<div className="min-h-screen bg-linear-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4">
<div className="w-full max-w-md">
<Card>
<CardBody className="space-y-6">
<div className="text-center">
<h1 className="text-2xl font-bold text-gray-900 mb-2">
Create Account
</h1>
<p className="text-gray-600">
Join us to save and organize your resources
</p>
</div>

<form onSubmit={handleSubmit} className="space-y-4">
<Input
label="Email"
type="email"
placeholder="Enter your email"
value={email}
onChange={(event) => setEmail(event.target.value)}
className="w-full"
required
autoComplete="off"
/>

<Input
label="Password"
type="password"
placeholder="Create a password"
value={password}
onChange={(event) => setPassword(event.target.value)}
className="w-full"
required
autoComplete="off"
/>

<Input
label="Confirm Password"
type="password"
placeholder="Confirm your password"
value={confirmPassword}
onChange={(event) => setConfirmPassword(event.target.value)}
className="w-full"
required
autoComplete="off"
/>

<Button type="submit" className="w-full">
Create Account
</Button>
</form>

<div className="relative">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-gray-200" />
</div>
<div className="relative flex justify-center text-sm">
<span className="px-2 bg-white text-gray-500">
Or sign up with
</span>
</div>
</div>

<Button variant="outline" className="w-full">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: 🟠 Major

The “Continue with Google” button has no action; wire it to a handler (or accept an onGoogleSignIn prop) and set type="button" to avoid accidental form submits if layout changes.

<Button type="button" onClick={handleGoogleSignIn} ...>

<GoogleLogo />
Continue with Google
</Button>

<p className="text-center text-gray-600 text-sm">
Already have an account?
<Link
to="/signin"
className="text-blue-600 hover:text-blue-700 font-medium"
>
Sign in
</Link>
</p>
</CardBody>
</Card>
</div>
</div>
);
};