Skip to content
Merged
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
5 changes: 3 additions & 2 deletions client/src/Login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Login', () => {
fireEvent.click(screen.getByRole('button', { name: 'Sign In' }));

await waitFor(() => {
expect(mockSignIn).toHaveBeenCalledWith({ email: 'test@test.com', password: 'password123' });
expect(mockSignIn).toHaveBeenCalledWith({ email: 'test@test.com', password: 'password123'});
});
});

Expand Down Expand Up @@ -85,6 +85,7 @@ describe('Login', () => {
render(<Login />);
fireEvent.click(screen.getByText('Sign Up'));
fireEvent.change(screen.getByPlaceholderText('Enter email'), { target: { value: 'test@test.com' } });
fireEvent.change(screen.getByPlaceholderText('Enter username'), { target: { value: 'test_user' } });
fireEvent.change(screen.getByPlaceholderText('Enter password'), { target: { value: 'password123' } });
fireEvent.click(screen.getByRole('button', { name: 'Sign Up' }));

Expand All @@ -111,7 +112,7 @@ describe('Login', () => {
fireEvent.click(screen.getByRole('button', { name: 'Sign Up' }));

await waitFor(() => {
expect(screen.getByText('Password is too weak. Please use a strong password.')).toBeInTheDocument();
expect(screen.getByText('Password is too weak. Please use a password of at least 6 characters.')).toBeInTheDocument();
});
});

Expand Down
5 changes: 3 additions & 2 deletions client/src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Login = () => {
}
};

const handleSignUp = async (email: string, password: string, name?: string) => {
const handleSignUp = async (email: string, password: string, username: string) => {
setError(null);
setIsLoading(true);

Expand All @@ -53,6 +53,7 @@ const Login = () => {
email: email,
password: password,
options: {
data: {display_name: username},
emailRedirectTo: "http://localhost:5173/"
}
});
Expand All @@ -61,7 +62,7 @@ const Login = () => {
if (error.code === 'user_already_exists') {
setError('An account with this email already exists. Please sign in instead.');
} else if (error.code ===('weak_password')) {
setError('Password is too weak. Please use a strong password.');
setError('Password is too weak. Please use a password of at least 6 characters.');
} else {
setError(error.message);
}
Expand Down
6 changes: 5 additions & 1 deletion client/src/SignUpForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@ describe('SignUpForm', () => {
it('renders without crashing', () => {
render(<SignUpForm onSubmit={mockOnSubmit} />);
expect(screen.getByPlaceholderText('Enter email')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Enter username')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Enter password')).toBeInTheDocument();
});

it('updates email and password fields', () => {
render(<SignUpForm onSubmit={mockOnSubmit} />);
fireEvent.change(screen.getByPlaceholderText('Enter email'), { target: { value: 'test@test.com' } });
fireEvent.change(screen.getByPlaceholderText('Enter username'), { target: { value: 'test_user' } });
fireEvent.change(screen.getByPlaceholderText('Enter password'), { target: { value: 'admin1' } });
expect(screen.getByPlaceholderText('Enter email')).toHaveValue('test@test.com');
expect(screen.getByPlaceholderText('Enter username')).toHaveValue('test_user');
expect(screen.getByPlaceholderText('Enter password')).toHaveValue('admin1');
});

it('calls onSubmit with email and password when submitted', async () => {
render(<SignUpForm onSubmit={mockOnSubmit} />);
fireEvent.change(screen.getByPlaceholderText('Enter email'), { target: { value: 'test@test.com' } });
fireEvent.change(screen.getByPlaceholderText('Enter username'), { target: { value: 'test_user' } });
fireEvent.change(screen.getByPlaceholderText('Enter password'), { target: { value: 'admin1' } });
fireEvent.click(screen.getByText('Sign Up'));

await waitFor(() => {
expect(mockOnSubmit).toHaveBeenCalledWith('test@test.com', 'admin1');
expect(mockOnSubmit).toHaveBeenCalledWith('test@test.com', 'admin1', 'test_user');
});
});
});
13 changes: 11 additions & 2 deletions client/src/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { createClient } from './supabase.ts';
import { useState } from 'react';

interface SignUpProps {
onSubmit: (email: string, password: string) => Promise<void>;
onSubmit: (email: string, password: string, username: string) => Promise<void>;
isLoading?: boolean;
}
export default function SignUpForm({ onSubmit, isLoading = false }: SignUpProps) {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [username, setUsername] = useState('');
const [error, setError] = useState('');

const handleSubmit = async (e: React.SubmitEvent) => {
e.preventDefault();
await onSubmit(email, password);
await onSubmit(email, password, username);
};


Expand All @@ -26,6 +27,14 @@ export default function SignUpForm({ onSubmit, isLoading = false }: SignUpProps)
placeholder="Enter email"
/>
</div>
<div>
<input
type="username"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Enter username"
/>
</div>
<div>
<input
type="password"
Expand Down