Fix auth translations and admin PWA UI
This commit is contained in:
78
resources/js/pages/auth/__tests__/ForgotPassword.test.tsx
Normal file
78
resources/js/pages/auth/__tests__/ForgotPassword.test.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import React from 'react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
vi.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, fallback?: string | Record<string, unknown>) => {
|
||||
if (typeof fallback === 'string') {
|
||||
return fallback;
|
||||
}
|
||||
if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
|
||||
return fallback.defaultValue;
|
||||
}
|
||||
return key;
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@/layouts/auth-layout', () => ({
|
||||
default: ({ children, title, description }: { children: React.ReactNode; title: string; description: string }) => (
|
||||
<div>
|
||||
<h1>{title}</h1>
|
||||
<p>{description}</p>
|
||||
{children}
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('@/actions/App/Http/Controllers/Auth/PasswordResetLinkController', () => ({
|
||||
store: {
|
||||
form: () => ({}),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('@inertiajs/react', () => ({
|
||||
Form: ({ children }: { children: (props: { processing: boolean; errors: Record<string, string[]> }) => React.ReactNode }) => (
|
||||
<form>{children({ processing: false, errors: {} })}</form>
|
||||
),
|
||||
Head: () => null,
|
||||
}));
|
||||
|
||||
vi.mock('@/routes', () => ({
|
||||
login: () => '/login',
|
||||
}));
|
||||
|
||||
vi.mock('@/components/input-error', () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
vi.mock('@/components/text-link', () => ({
|
||||
default: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
|
||||
}));
|
||||
|
||||
vi.mock('@/components/ui/button', () => ({
|
||||
Button: ({ children }: { children: React.ReactNode }) => <button>{children}</button>,
|
||||
}));
|
||||
|
||||
vi.mock('@/components/ui/input', () => ({
|
||||
Input: (props: React.InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
|
||||
}));
|
||||
|
||||
vi.mock('@/components/ui/label', () => ({
|
||||
Label: ({ children }: { children: React.ReactNode }) => <label>{children}</label>,
|
||||
}));
|
||||
|
||||
import ForgotPassword from '../forgot-password';
|
||||
|
||||
describe('ForgotPassword', () => {
|
||||
it('renders the translated copy', () => {
|
||||
render(<ForgotPassword />);
|
||||
|
||||
expect(screen.getByText('Forgot password')).toBeInTheDocument();
|
||||
expect(screen.getByText('Enter your email to receive a password reset link')).toBeInTheDocument();
|
||||
expect(screen.getByText('Email password reset link')).toBeInTheDocument();
|
||||
expect(screen.getByText('Or, return to')).toBeInTheDocument();
|
||||
expect(screen.getByText('Login')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -15,8 +15,14 @@ import AuthLayout from '@/layouts/auth-layout';
|
||||
export default function ForgotPassword({ status }: { status?: string }) {
|
||||
const { t } = useTranslation('auth');
|
||||
return (
|
||||
<AuthLayout title={t('auth.forgot.title', 'Forgot password')} description={t('auth.forgot.description', 'Enter your email to receive a password reset link')}>
|
||||
<Head title={t('auth.forgot.title', 'Forgot password')} />
|
||||
<AuthLayout
|
||||
title={t('forgot.title', 'Forgot password')}
|
||||
description={t('forgot.description', 'Enter your email to receive a password reset link')}
|
||||
name={t('login.brand', 'Die Fotospiel App')}
|
||||
logoSrc="/logo-transparent-md.png"
|
||||
logoAlt={t('login.logo_alt', 'Logo Die Fotospiel App')}
|
||||
>
|
||||
<Head title={t('forgot.title', 'Forgot password')} />
|
||||
|
||||
{status && <div className="mb-4 text-center text-sm font-medium text-green-600">{status}</div>}
|
||||
|
||||
@@ -25,8 +31,15 @@ export default function ForgotPassword({ status }: { status?: string }) {
|
||||
{({ processing, errors }) => (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="email">Email address</Label>
|
||||
<Input id="email" type="email" name="email" autoComplete="off" autoFocus placeholder={t('auth.forgot.email_placeholder')} />
|
||||
<Label htmlFor="email">{t('forgot.email_label', 'Email address')}</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
name="email"
|
||||
autoComplete="off"
|
||||
autoFocus
|
||||
placeholder={t('forgot.email_placeholder', 'name@example.com')}
|
||||
/>
|
||||
|
||||
<InputError message={errors.email} />
|
||||
</div>
|
||||
@@ -34,7 +47,7 @@ export default function ForgotPassword({ status }: { status?: string }) {
|
||||
<div className="my-6 flex items-center justify-start">
|
||||
<Button className="w-full" disabled={processing}>
|
||||
{processing && <LoaderCircle className="h-4 w-4 animate-spin" />}
|
||||
Email password reset link
|
||||
{t('forgot.submit', 'Email password reset link')}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
@@ -42,8 +55,8 @@ export default function ForgotPassword({ status }: { status?: string }) {
|
||||
</Form>
|
||||
|
||||
<div className="space-x-1 text-center text-sm text-muted-foreground">
|
||||
<span>Or, return to</span>
|
||||
<TextLink href={login()}>{t('auth.forgot.back')}</TextLink>
|
||||
<span>{t('forgot.back_prefix', 'Or, return to')}</span>
|
||||
<TextLink href={login()}>{t('forgot.back', 'Login')}</TextLink>
|
||||
</div>
|
||||
</div>
|
||||
</AuthLayout>
|
||||
|
||||
Reference in New Issue
Block a user