diff --git a/resources/js/pages/auth/login.test.tsx b/resources/js/pages/auth/login.test.tsx new file mode 100644 index 00000000..6563d3ec --- /dev/null +++ b/resources/js/pages/auth/login.test.tsx @@ -0,0 +1,66 @@ +import { render, screen } from '@testing-library/react'; +import { type ReactNode } from 'react'; +import { describe, expect, it, vi } from 'vitest'; +import Login from './login'; + +globalThis.ResizeObserver ??= class { + observe() {} + unobserve() {} + disconnect() {} +}; + +const capturedFormProps: Record = {}; + +vi.mock('@inertiajs/react', () => ({ + Form: ({ + children, + ...props + }: { + children: (renderProps: { + processing: boolean; + errors: Record; + }) => ReactNode; + } & Record) => { + Object.assign(capturedFormProps, props); + + return
{children({ processing: false, errors: {} })}
; + }, + Head: () => null, + Link: ({ children }: { children: ReactNode }) => {children}, + usePage: () => ({ props: { demoCredentials: undefined } }), +})); + +vi.mock('@/layouts/auth-layout', () => ({ + default: ({ children }: { children: ReactNode }) =>
{children}
, +})); + +vi.mock('@/lib/key-storage', () => ({ + clearKey: vi.fn(), +})); + +vi.mock('@/utils/i18n', () => ({ + __: (key: string) => key, +})); + +vi.mock('@/routes', () => ({ + register: () => ({ url: '/register' }), +})); + +vi.mock('@/routes/login', () => ({ + store: { form: () => ({ action: '/login', method: 'post' }) }, +})); + +vi.mock('@/routes/password', () => ({ + request: () => ({ url: '/forgot-password' }), +})); + +describe('Login', () => { + it('does not reset the form on success', () => { + // The success redirect unmounts the form; resetting it afterwards makes + // Inertia construct a FormData from a stale ref and crash (PHP-LARAVEL-2Y). + render(); + + expect(screen.getByRole('button', { name: /log in/i })).toBeTruthy(); + expect(capturedFormProps.resetOnSuccess).toBeUndefined(); + }); +}); diff --git a/resources/js/pages/auth/login.tsx b/resources/js/pages/auth/login.tsx index fddd8aef..ac0f6ba1 100644 --- a/resources/js/pages/auth/login.tsx +++ b/resources/js/pages/auth/login.tsx @@ -54,7 +54,6 @@ export default function Login({