adrema/modules/Auth/Components/PasswordResetTest.php

51 lines
1.6 KiB
PHP

<?php
namespace Modules\Auth\Components;
use Modules\Auth\Mails\ResetPassword;
use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
uses(TestCase::class);
uses(DatabaseTransactions::class);
it('displays component', function () {
test()->get(route('password.request'))->assertSeeLivewire(PasswordReset::class)->assertDontSee('Dashboard');
});
it('shows intro', function () {
Livewire::test(PasswordReset::class)->assertSee('Hier kannst du dein Passwort zurücksetzen.');
});
it('it needs email address', function (string $email, string $error) {
Livewire::test(PasswordReset::class)
->set('email', $email)
->call('submit')
->assertHasErrors(['email' => $error]);
})
->with([
['', 'E-Mail Adresse ist erforderlich.'],
['aaa', 'E-Mail Adresse muss eine gültige E-Mail-Adresse sein.'],
]);
it('displays error when user doesnt exsst', function () {
Livewire::test(PasswordReset::class)
->set('email', 'nowhere@example.com')
->call('submit')
->assertHasErrors(['email' => 'Es konnte leider kein Nutzer mit dieser E-Mail-Adresse gefunden werden.']);
});
it('requests link', function () {
Notification::fake();
$user = User::factory()->loginData('admin@example.com', 'secret')->create();
Livewire::test(PasswordReset::class)
->set('email', 'admin@example.com')
->call('submit')
->assertDispatched('success', 'Du hast weitere Instruktionen per E-Mail erhalten.');
Notification::assertSentTo($user, ResetPassword::class);
});