diff --git a/frontend/src/pages/auth/Signup.jsx b/frontend/src/pages/auth/Signup.jsx index d39bafe..f8cf734 100644 --- a/frontend/src/pages/auth/Signup.jsx +++ b/frontend/src/pages/auth/Signup.jsx @@ -42,10 +42,9 @@ const Signup = ({ onAuthSuccess = () => {} }) => { [form.username] ); const nameValid = form.name.trim().length >= 2; - const dateOfBirthValid = useMemo( - () => isValidDateOfBirth(form.dateOfBirth), - [form.dateOfBirth], - ); + + const dateOfBirthValid = isValidDateOfBirth(form.dateOfBirth); + const genderValid = ['male', 'female', 'other', 'na'].includes(form.gender); const phoneValid = /^\+?[0-9]{10,15}$/.test(form.phone); const passwordValid = useMemo( @@ -231,7 +230,9 @@ const Signup = ({ onAuthSuccess = () => {} }) => { {touched.gender && !genderValid && ( -

{t('auth:errors.genderRequired', 'Please select a gender')}

+

+ {t('auth:errors.genderRequired', 'Please select a gender')} +

)} diff --git a/frontend/src/pages/auth/Signup.test.jsx b/frontend/src/pages/auth/Signup.test.jsx index 1ba03c4..05b9da7 100644 --- a/frontend/src/pages/auth/Signup.test.jsx +++ b/frontend/src/pages/auth/Signup.test.jsx @@ -79,11 +79,11 @@ describe('Signup', () => { }); it('requires a date of birth', async () => { - const user = userEvent.setup(); renderSignup(); + const dobInput = screen.getByLabelText(/date of birth/i); - screen.getByLabelText(/date of birth/i).focus(); - await user.tab(); + fireEvent.focus(dobInput); + fireEvent.blur(dobInput); expect(screen.getByText(/date of birth is required/i)).toBeInTheDocument(); }); @@ -211,14 +211,16 @@ describe('Signup', () => { await user.type(screen.getByLabelText(/full name/i), 'John Doe'); fireEvent.change(screen.getByLabelText(/date of birth/i), { target: { value: '2000-01-01' } }); await user.selectOptions(screen.getByRole('combobox'), 'male'); - - // Try to type letters - they should be stripped + const phoneInput = screen.getByPlaceholderText(/phone number/i); - await user.type(phoneInput, '123abc4567890'); - - await user.type(screen.getByLabelText(/^password$/i), 'Password123'); - await user.type(screen.getByLabelText(/confirm password/i), 'Password123'); - await user.click(screen.getByRole('button', { name: /sign up/i })); + await user.type(phoneInput, '123-456-7890'); + + await user.type(screen.getByLabelText(/^password$/i), 'Password123!'); + await user.type(screen.getByLabelText(/confirm password/i), 'Password123!'); + + const submitButton = screen.getByRole('button', { name: /sign up/i }); + expect(submitButton).toBeEnabled(); + await user.click(submitButton); await waitFor(() => { expect(mockSignup).toHaveBeenCalledWith( diff --git a/frontend/src/utils/validation.js b/frontend/src/utils/validation.js index febdc0d..5864e28 100644 --- a/frontend/src/utils/validation.js +++ b/frontend/src/utils/validation.js @@ -34,3 +34,19 @@ export const validatePassword = (value) => { return checks.hasUppercase && checks.hasNumber; }; +export const isValidDateOfBirth = (value) => { + if (!value) return false; + const dob = new Date(value); + if (Number.isNaN(dob.getTime())) return false; + const today = new Date(); + let age = today.getFullYear() - dob.getFullYear(); + const m = today.getMonth() - dob.getMonth(); + if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) { + age--; + } + return age >= 13 && age <= 120; +}; + +export const formatDateForInput = (date = new Date()) => { + return date.toISOString().split('T')[0]; +}; diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js index 699dd3a..20ce38c 100644 --- a/frontend/tailwind.config.js +++ b/frontend/tailwind.config.js @@ -8,15 +8,15 @@ export default { extend: { colors: { health: { - primary: '#0f766e', // (Teal) - secondary: '#059669', // (Emerald) - good: '#10b981', // Normal (Green) - warning: '#f59e0b', // Caution (Orange) - critical: '#ef4444', // Danger (Red) - surface: '#f0fdfa', // Background (Teal-50) + primary: '#0f766e', + secondary: '#059669', + good: '#10b981', + warning: '#f59e0b', + critical: '#ef4444', + surface: '#f0fdfa', } - } + }, }, }, plugins: [], -} +} \ No newline at end of file