set('form.email', $email) ->call('sendLink'); } function mockPasswordResetStatus(string $status, string $email = 'user@example.com'): void { Password::shouldReceive('sendResetLink') ->once() ->with(['form.email' => $email]) ->andReturn($status); } /* |-------------------------------------------------------------------------- | Component Rendering |-------------------------------------------------------------------------- */ it('renders forgot password component successfully', function () { Livewire::test(ForgotPassword::class) ->assertViewIs('livewire.auth.forgot-password') ->assertSet('form.email', ''); }); /* |-------------------------------------------------------------------------- | Validation Rules |-------------------------------------------------------------------------- */ it('validates email field is required', function () { Livewire::test(ForgotPassword::class) ->set('form.email', '') ->call('sendLink') ->assertHasErrors(['form.email' => 'required']); }); /* |-------------------------------------------------------------------------- | Send Reset Link |-------------------------------------------------------------------------- */ it('sends reset link successfully', function () { $email = 'user@example.com'; mockPasswordResetStatus(Password::ResetLinkSent, $email); attemptSendResetLink($email) ->assertHasNoErrors(); }); it('handles failure when sending reset link', function () { $email = 'user@example.com'; mockPasswordResetStatus('passwords.user', $email); attemptSendResetLink($email) ->assertHasNoErrors(); });